View Javadoc
1   package ubic.basecode.ontology.jena;
2   
3   import com.hp.hpl.jena.ontology.OntModel;
4   import com.hp.hpl.jena.rdf.model.Resource;
5   import com.hp.hpl.jena.util.iterator.ExtendedIterator;
6   import ubic.basecode.ontology.search.OntologySearchException;
7   
8   import java.util.List;
9   import java.util.stream.Stream;
10  
11  interface SearchIndex extends AutoCloseable {
12  
13      /**
14       * Find RDF nodes matching the given query string.
15       */
16      List<JenaSearchResult> search( OntModel model, String queryString, int maxResults ) throws OntologySearchException;
17  
18      /**
19       * Find classes that match the query string.
20       *
21       * @param model that goes with the index
22       * @return Collection of OntologyTerm objects
23       */
24      List<JenaSearchResult> searchClasses( OntModel model, String queryString, int maxResults ) throws OntologySearchException;
25  
26      /**
27       * Find individuals that match the query string
28       *
29       * @param model that goes with the index
30       * @return Collection of OntologyTerm objects
31       */
32      List<JenaSearchResult> searchIndividuals( OntModel model, String queryString, int maxResults ) throws OntologySearchException;
33  
34      class JenaSearchResult {
35  
36          public final Resource result;
37          public final double score;
38  
39          JenaSearchResult( Resource result, double score ) {
40              this.result = result;
41              this.score = score;
42          }
43  
44          @Override
45          public String toString() {
46              return String.format( "%s score=%f", result, score );
47          }
48      }
49  }