A SPARQL 1.2 query finds the Rust developers available for a project, with their manager when recorded and their team.
staffing-rq.rq · data/staffing-rq.ttl · output · proof · check · playground
The question
A project needs Rust developers. Five team members have recorded languages and levels; some have a manager on record, and one is on leave. Which members know Rust at level 2 or more and are available, who manages them where that is known, and which team would each join: the platform team from level 3, the tools team below it?
What we tell eyemind
data/staffing-rq.ttl holds the team:
:ada :knows :rust, :python ; :level 3 ; :reportsTo :grace .
:linus :knows :rust ; :level 2 .
:alan :knows :rust ; :level 4 ; :onLeave true .
staffing-rq.rq is an ordinary SPARQL 1.2 query:
SELECT ?person ?level ?manager ?team WHERE {
?person :knows :rust ; :level ?level .
FILTER(?level >= 2)
OPTIONAL { ?person :reportsTo ?manager }
MINUS { ?person :onLeave true }
BIND(IF(?level >= 3, :platform, :tools) AS ?team)
}
What eyemind concludes
The command writes SPARQL JSON results; as TSV, with --to tsv:
?person ?level ?manager ?team
<https://example.org/staff#ada> 3 <https://example.org/staff#grace> <https://example.org/staff#platform>
<https://example.org/staff#linus> 2 <https://example.org/staff#tools>
Ken is below level 2, Barbara does not know Rust, and Alan is on leave.
Linus has no manager on record, so ?manager is unbound for him.
The check report records the answer as one JavaScript expression, the
variables and the rows, with 'undef' for an unbound variable:
// Checked answers: these follow from the input program and are every answer of its questions.
sparql_select(['person', 'level', 'manager', 'team'], [[iri('https://example.org/staff#ada'), 3, iri('https://example.org/staff#grace'), iri('https://example.org/staff#platform')], [iri('https://example.org/staff#linus'), 2, 'undef', iri('https://example.org/staff#tools')]])
How the query becomes a program
eyemind compiles the query to Logic Script over the dataset’s quads,
rdf(S, P, O, G). The rows are one findall_sorted over the pattern,
so SPARQL’s duplicate solutions would be kept. OPTIONAL is a choice: the managers the
pattern finds, or 'undef' when a helper, sparql_1(Person, Level), has no
solution. MINUS is a negation of another helper, sparql_2(Person), which
looks for the member’s leave. FILTER and BIND become goals over the same
function library as SPARQL 1.2 RL; --program prints the whole program.
What the proof establishes
The saved report ends with verdict('checked'). The proof holds the
collection’s listing and a call table for each helper the search consulted:
an empty table for Ada’s leave, and one answer for Alan’s:
called(sparql_2(iri('https://example.org/staff#ada')), [])
The checker expands each table one level against the compiled program, so an empty table must agree with the data, and replays the collection, so the rows must be every solution of the pattern. The verdict establishes that the answer follows from the query and the data and that no row is missing.
Try it
From the repository root:
node bin/eyemind.js examples/staffing-rq.rq examples/data/staffing-rq.ttl
node bin/eyemind.js --proof examples/staffing-rq.rq examples/data/staffing-rq.ttl
node bin/eyemind.js --check-proof examples/proof/staffing-rq.js examples/staffing-rq.rq examples/data/staffing-rq.ttl
Add --to tsv, --to csv or --to sparql-xml for the other result formats.
