A question is a query.
A 33-triple film graph, twelve question templates, and a join executor. Pick a question, watch the parse resolve names to entities, then execute the query and inspect the derivation. When no template fits, the retrieval fallback shows what a ranked list can and cannot replace.
The question-to-query lab
Parse
Step 01 · sentence → queryExecute
Step 02 · query → bindingsFallback
No parse · lexical retrievalThe knowledge graph
A hand-built film graph with 28 entities and 33 triples. The entities and titles are fictional; the mechanics are the point. Every answer printed on this page is computed from these triples, not looked up in a table.
| Relation | Domain | Range |
|---|---|---|
| directedBy | Film | Director |
| bornIn | Director | Country |
| hasGenre | Film | Genre |
| releasedIn | Film | Year (literal) |
| wonAward | Film | Award |
| awardAt | Award | Festival |
| stars | Film | Actor |
| producedBy | Film | Studio |
How the pipeline works
- Normalize and match. The question is lowercased and matched against twelve hand-written templates. A match identifies the question shape, not just keywords.
- Resolve the slots. Names in the question are resolved to entity IDs with a type check. “Sweden” must be a Country; “Crystal Palm” must be an Award.
- Build a query. The template emits triple patterns with variables. The query is printed as SPARQL-like text; there is no hidden SQL.
- Join and derive. A naive nested-loop join evaluates each pattern against the triple list, carrying bindings forward. The trace shows rows in, matches, and rows out. Each answer carries the triples that produced it.
What to try
- Ask the default three-pattern question and expand Derivation. Three triples, one film.
- Ask Which films were released in 2016? The literal in the query is matched against the literal in the graph; there is no string parsing at execution time.
- Press Try an unmatched question. The parser fails; the fallback ranks triples by lexical overlap. No query, no join, no computed answer.
- Ask Which films are dramas? and then Which drama films were produced by Lumen Studio?. The first is one pattern; the second is an intersection of two.
What this shows
A semantic parser is a translation into an executable object. The query, not the answer, is the artefact you can inspect; the derivation, not the score, is the evidence. The join order is visible because the graph is small. At scale, that order becomes a query-planning problem.
What this does not
It is not a SPARQL engine, a neural parser, an embedding model, or a RAG system. The templates are fixed, the graph is fictional, and the executor is a naive join over 33 triples. It isolates one mechanism — question to query to bindings to derivation — and leaves the hard parts of scale, ambiguity, and coverage to the guide.
Three outcomes, three kinds of evidence.
The template is a hypothesis about the question shape
“Which films did X direct?” and “Who directed Y?” share words but not structure. The parser chooses a template, resolves the slot to a typed entity, and emits a query with a direction. A wrong template is not a syntax error; it is a wrong hypothesis.
The derivation is the answer’s audit trail
Every binding comes from a triple, and every triple is displayed. If the answer is wrong, the trace says whether the query matched the wrong entity, the wrong relation, or no relation at all. A zero-row result is shown as unknown, not as false.
Retrieval ranks evidence; it does not compute a join
When parsing fails, the fallback scores each triple by lexical overlap and returns the top three. The result can be useful for a human reader, but it is not an answer to the question’s logical form. There is no variable binding and no composition.
This is a deterministic teaching toy, not a benchmark. The graph is fictional and the parser is a template matcher, so a low score here would mean the question is outside the grammar, not that a model is weak. The lab does not test generalization, ambiguity resolution, or scale; those are the subjects of the guide’s failure section.