hermes.systems.training_free
Training-free
The training-free system writes one SPARQL query from the schema vocabulary in a single model call, plus one repair call if the draft does not parse.
Command
hermes generate \
--ontology GeoOutage.ttl \
--question "Which counties have the highest number of outages?" \
--context notes.txt \
--examples pairs.jsonl
| Flag | Meaning |
|---|---|
--ontology, --graph, or --endpoint | One is required: an RDF file, a graph name from data/graphs.yaml, or a SPARQL endpoint URL. |
--question | Required. |
--context | A text file of extra context. |
--examples | JSONL, one object per line with nl and sparql (nl_text and sparql_query are accepted). |
--system | Any registered system; the default is training-free. |
Source: cli.py.
From Python
from hermes import Context, Example, TrainingFree
system = TrainingFree() # or TrainingFree(llm=...)
result = system(
"Which counties have the highest number of outages?",
"GeoOutage.ttl",
Context(text="Counties are administrative regions.",
examples=[Example(nl="List outage records.",
sparql="SELECT ?rec WHERE { ?rec a geooutageonto:OutageRecord }")]),
)
print(result["sparql"])
The result has sparql, model, and provider. Source: training_free.py.
Prompt
build_prompt joins these sections with a blank line:
- Instructions: one query, only the prefixes and terms below, match labels in quotes, triples inside
WHERE,ORDER BYandLIMITafter it, noSELECTinsideFILTER, do not copy the shape example, return only the query. - A shape example with
ex:terms that are not from the ontology. - Prefixes, classes, and properties from the vocabulary.
- Context text and example pairs, when given.
- The question, last.
Errors
A reply without a query raises ValueError. A query that still fails to parse after one repair raises ValueError with the parser message. Model failures are LookupError; see Models.