001package org.dllearner.algorithms.isle.index.semantic; 002 003import java.util.HashMap; 004import java.util.HashSet; 005import java.util.Set; 006 007import org.dllearner.algorithms.isle.index.AnnotatedDocument; 008import org.dllearner.algorithms.isle.index.Index; 009import org.semanticweb.owlapi.model.OWLEntity; 010 011/** 012 * Interface for an index which is able to resolve a given entity's URI to the set of documents containing 013 * this entity, i.e., documents which contain words disambiguated to the given entity. 014 * 015 * @author Lorenz Buehmann 016 * @author Daniel Fleischhacker 017 */ 018public class SemanticIndex extends HashMap<OWLEntity, Set<AnnotatedDocument>> implements Index{ 019 020 private int nrOfDocuments; 021 022 /** 023 * Returns the set of annotated documents which reference the given entity using one of its surface forms. 024 * 025 * @param entity entity to retrieve documents 026 * @return documents referencing given entity 027 */ 028 @Override 029 public Set<AnnotatedDocument> getDocuments(OWLEntity entity) { 030 Set<AnnotatedDocument> annotatedDocuments = get(entity); 031 if (annotatedDocuments == null) { 032 annotatedDocuments = new HashSet<>(); 033 } 034 return annotatedDocuments; 035 } 036 037 /** 038 * Returns the number of documents for the given entity. 039 * 040 * @param entity entity to return number of referencing documents for 041 * @return number of documents for the given entity in this index 042 */ 043 public int getNrOfDocumentsFor(OWLEntity entity) { 044 return get(entity).size(); 045 } 046 047 /** 048 * @param nrOfDocuments the nrOfDocuments to set 049 */ 050 public void setTotalNrOfDocuments(int nrOfDocuments) { 051 this.nrOfDocuments = nrOfDocuments; 052 } 053 054 /* (non-Javadoc) 055 * @see org.dllearner.algorithms.isle.index.Index#getTotalNumberOfDocuments() 056 */ 057 @Override 058 public long getTotalNumberOfDocuments() { 059 return nrOfDocuments; 060 } 061 062 /* (non-Javadoc) 063 * @see org.dllearner.algorithms.isle.index.Index#getNumberOfDocumentsFor(org.dllearner.core.owl.Entity) 064 */ 065 @Override 066 public long getNumberOfDocumentsFor(OWLEntity entity) { 067 return getDocuments(entity).size(); 068 } 069 070 /* (non-Javadoc) 071 * @see org.dllearner.algorithms.isle.index.Index#getNumberOfDocumentsFor(org.dllearner.core.owl.Entity[]) 072 */ 073 @Override 074 public long getNumberOfDocumentsFor(OWLEntity... entities) { 075 076 Set<AnnotatedDocument> documents = getDocuments(entities[0]); 077 for (int i = 1; i < entities.length; i++) { 078 documents.retainAll(getDocuments(entities[i])); 079 } 080 return 0; 081 } 082 083}