Class QueryService
All lookups run against the inference dataset, so results include both approved assertions and
statements derived from them by the reasoner. Provenance, which lives in the provenance graph of the assertions dataset and is excluded from
inference, is looked up there.
-
Constructor Summary
ConstructorsConstructorDescriptionQueryService(org.apache.jena.query.Dataset inferences, org.apache.jena.query.Dataset assertions, org.apache.jena.ontapi.model.OntModel ontModel, UsageService usageService) Creates the service. -
Method Summary
Modifier and TypeMethodDescriptionList<ai.chatur.cortex.ProvenancedStatement> Returns everything known about a resource, with the creation timestamp of each statement where provenance was recorded.List<ai.chatur.cortex.Term> getInstances(String type) Returns the known instances of an ontology class.Runs a SPARQL query against the knowledge graph.Finds resources by fuzzy full-text search over their labels.List<ai.chatur.cortex.SearchResult> searchSubjects(String text) Searches the full-text index and returns the matching subjects.
-
Constructor Details
-
QueryService
public QueryService(org.apache.jena.query.Dataset inferences, org.apache.jena.query.Dataset assertions, org.apache.jena.ontapi.model.OntModel ontModel, UsageService usageService) Creates the service.- Parameters:
inferences- the dataset holding the assertions enriched by inferenceassertions- the dataset holding the approved assertions and their provenanceontModel- the ontology model, used to resolve classes and shorten URIsusageService- view counts, which weight the ranking of search results
-
-
Method Details
-
getInstances
Returns the known instances of an ontology class.- Parameters:
type- the local name of the ontology class- Returns:
- the instance identifiers sorted alphabetically, empty if the class is unknown
-
describe
Returns everything known about a resource, with the creation timestamp of each statement where provenance was recorded.The statements come from the inference dataset; their creation timestamps come from the
provenance graphof the assertions dataset. Each statement is returned once: statements carrying several provenance records — for example because they were asserted by more than one ingestion — report their earliest creation timestamp.- Parameters:
id- the identifier of the resource within the Cortex namespace, or a full URI- Returns:
- the statements about the resource, sorted by predicate
-
query
Runs a SPARQL query against the knowledge graph.- Parameters:
sparql- a SPARQLSELECT,ASK, orDESCRIBEquery- Returns:
SELECTandASKresults formatted as text,DESCRIBEresults serialized in Turtle syntax, ornullfor other query types
-
search
Finds resources by fuzzy full-text search over their labels.Each term of the input is matched approximately, so small typos and spelling variations still find their target.
- Parameters:
text- the text to search for- Returns:
- the matches with their relevance scores, formatted as text and ranked best first
-
searchSubjects
Searches the full-text index and returns the matching subjects.Longer terms are matched approximately, so small typos and spelling variations still find their target. Every term must occur in the same indexed literal, so adding a word narrows the results.
The index holds one document per literal, so a resource matching on both its label and its comment produces several hits; each resource is reported once, keeping its best-scoring match.
- Parameters:
text- the text to search for- Returns:
- the matching subjects ranked best first, empty if nothing matches
-