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 TypeMethodDescriptionCounts the instances of every class over the inference dataset, so a resource typed only by a subclass still counts towards the superclasses the reasoner derives for it.List<ai.chatur.cortex.ProvenancedStatement> Returns everything known about a resource, with theoriginof each statement and the creation timestamp of those 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 full-text search over their labels, comments, and SKOS annotations.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
-
countInstances
Counts the instances of every class over the inference dataset, so a resource typed only by a subclass still counts towards the superclasses the reasoner derives for it.- Returns:
- the number of distinct instances keyed by class URI; classes with no instances are absent
-
describe
Returns everything known about a resource, with theoriginof each statement and the creation timestamp of those 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.The inference dataset holds more than the reasoner's conclusions: the reasoner is bound to the ontology as its schema, so the ontology's own axioms are materialized alongside them. Those have no provenance either, so absence of a timestamp alone does not make a statement inferred — the origin distinguishes them by looking the statement up in the ontology.
- 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 full-text search over their labels, comments, and SKOS annotations.Every term of the input is required and matched exactly after analysis, so recall comes from the analyzer's stemming (
reportsfindsreport) rather than edit-distance fuzz.- 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.Every term is required and must occur in the same indexed literal, so adding a word narrows the results. Terms are matched exactly after analysis; the analyzer's stemming is what lets spelling variations of the same word still find their target.
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
-