hermes.store, hermes.knowledge, hermes.linking
Graph stores
Systems and the scorer only call query(sparql), which returns SPARQL 1.1 JSON results. The same system runs on local files or a remote endpoint.
KnowledgeGraph
from hermes import KnowledgeGraph
kg = KnowledgeGraph.from_files("prod-vocab.ttl", "prod-inst.ttl") # Oxigraph
kg = KnowledgeGraph.from_files("onto.ttl", engine="rdflib")
kg = KnowledgeGraph.from_endpoint("https://dbpedia.org/sparql",
prefixes=[("dbo", "http://dbpedia.org/ontology/")])
A knowledge graph pairs a store with the vocabulary used to prompt for it. schema names smaller files to read the vocabulary from. Loading is lazy, so nothing is parsed until the first query. kg.executions counts real executions. Source: knowledge.py.
Stores
| Store | Backend |
|---|---|
OxigraphStore | Local RDF files in Oxigraph. The default: it loads the 26.6k-triple corporate graph in a fraction of a second. |
LocalStore | Local RDF files in rdflib, in pure Python. |
EndpointStore | A SPARQL endpoint over HTTP POST, with retries on server errors, a 60-second timeout, and a User-Agent header. |
CachedStore | Wraps any store, memoizes results, and counts executions. |
A failed query raises QueryError; try_query returns empty results instead. Turtle, N-Triples, N-Quads, RDF/XML, and TriG are read by extension. Source: store.py.
Entity linking
LabelIndex reads rdfs:label, skos:prefLabel, skos:altLabel, and the local names of typed subjects once, and matches in memory, falling back to partial-word matches. ExactLabel sends capitalized n-grams of the question to the store as label literals in one VALUES query, for large endpoints such as DBpedia. linker_for(kg) picks the first for local stores and the second for endpoints. Source: linking.py.