Course / Lectures / Lecture 17 / Lab Lab 17

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.

33 triples 28 entities 12 templates 1 fallback No install · runs in the browser

The question-to-query lab

Ready. The default question will parse and execute on load.
Question — Graph — Mentions —

Parse

Step 01 · sentence → query

Template —

Slots —

—

Execute

Step 02 · query → bindings
—
—

The 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.

The whole schema. Eight relations, no hidden facts.
RelationDomainRange
directedByFilmDirector
bornInDirectorCountry
hasGenreFilmGenre
releasedInFilmYear (literal)
wonAwardFilmAward
awardAtAwardFestival
starsFilmActor
producedByFilmStudio

How the pipeline works

  1. Normalize and match. The question is lowercased and matched against twelve hand-written templates. A match identifies the question shape, not just keywords.
  2. 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.
  3. Build a query. The template emits triple patterns with variables. The query is printed as SPARQL-like text; there is no hidden SQL.
  4. 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.

WHAT TO NOTICE

Three outcomes, three kinds of evidence.

OUTCOME 01 · PARSE

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.

OUTCOME 02 · EXECUTE

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.

OUTCOME 03 · FALLBACK

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.

What the lab is not

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.

Read semantic parsing again · Read the RAG limits · Slides