Terms

Web data, quoted statements and invented names, without any new syntax.

terms.js · output · proof · check · try it in the playground


The question

Data on the web (the Semantic Web, with its data model RDF) is made of small statements called triples: subject, predicate, object, such as “this page, has title, hello”. Names are web addresses (IRIs), and text can carry a language tag (“hello”, in English).

Sometimes you also want to talk about a group of statements without claiming they are true: a quoted graph, like quoting someone’s words.

Can a small rule language handle all this without special features, and what does it conclude about the quoted graph?


Historical background

RDF’s graph model standardized the use of triples for Web data. Notation3’s early extension added formulas that can be used as terms, allowing one statement to quote a graph. The example gives those ideas a representation made out of ordinary Logic Script terms. Original RDF Model and Syntax · W3C Team Submission, Notation3


What we tell eyemind: the data

Everything is written as ordinary nested terms, names with parts in brackets:

fact(
  quoted(
    graph(
      [
        triple(
          iri('https://example.org/s'),
          iri('https://example.org/p'),
          literal('hello', lang('en')),
        ),
      ],
    ),
  ),
)

Read from the inside out:


What we tell eyemind: the rules

// List membership, and a triple's membership of a graph.
fact(member_of(X, [X, ..._]))
implied_by(member_of(X, [_, ...Xs]), member_of(X, Xs))
implied_by(includes(graph(Triples), Triple), member_of(Triple, Triples))
implies([quoted(G), includes(G, T)], found(T))
// W occurs only in the head: one fresh Skolem term per quoted graph.
implies(quoted(X), witness(X, W))

Rules match these terms by unification: lining two terms up part by part and filling in variables so they become equal. That works for web data as for any other data; eyemind has no special support for it.


What eyemind concludes

// Conclusions: the facts the program derives, in the order derived.
found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))
witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])]))

The program has no query, so eyemind lists every fact it derived.


Naming what a rule says exists

The witness rule says: for every quoted graph X, there is some W. It never says which. To write a conclusion down, eyemind needs a name for that something, so it makes one up: a Skolem term (named after the logician Thoralf Skolem).

skolem(6, 'W', [the graph]) is built from three parts:

So it reads “the W that rule 6 says exists for this graph”. The same rule used for the same graph always gives the same name, and a different graph would give a different one. That is why a checker can recompute it.


The proof, line by line

eyemind --proof writes down how it reached each conclusion. This is the complete proof:

// Conclusions: the facts the program derives, in the order derived.
found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))
witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])]))

// Steps: each derived fact and what it rests on: the clause or control that
// justifies it, the bindings and the goals it uses.
step(found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))), clause(5), {G: graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), T: triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))}, [quoted(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])), includes(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))])
step(witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])])), clause(6), {X: graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), W: skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])])}, [quoted(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]))])

// Certificate: the derived facts and every answer of each call the questions make.
derived(found(A), [found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))])
derived(witness(A, B), [witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])]))])
called(found(A), [found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))])
called(includes(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), B), [includes(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))])
called(member_of(C, [triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), [member_of(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))), [triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])])
called(member_of(D, []), [])
called(witness(E, F), [witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])]))])

The lines are long because the whole triple is written out each time. It has three parts:

Write the graph for the quoted graph and the triple for the “hello” triple, and the lines read:

  1. The triple is found — by rule 5, with G = the graph and T = the triple, because the graph is quoted and includes the triple.
  2. There is a witness for the graph, named skolem(6, 'W', [the graph]) — by rule 6, with X = the graph and W = that invented name, because the graph is quoted.
  3. The graph includes exactly one triple, the triple — the table for includes(the graph, B), answered by rule 4 from the table below it.
  4. The triple is the only member of the graph’s list — the first item matches line 2 of the program, and line 3 looks in the rest of the list, [], which has no members: its table is empty.

Checked: what the report says

A proof is only worth something if someone else can check it. eyemind -c generates the proof and checks it against the program; --check-proof checks a saved proof. The checker never reasons by itself: it reads the clauses from the program and confirms the proof against them in one procedure:

This is the complete report:

// Checked answers: these follow from the input program and are every answer of its questions.
found(triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en'))))
witness(graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))]), skolem(6, 'W', [graph([triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hello', lang('en')))])]))

verdict('checked')

The verdict is checked: both conclusions follow from the program, and they are every answer of the original questions.


Try it

eyemind examples/terms.js            # the answers
eyemind --proof examples/terms.js    # answers with their proof

Or open it in the playground. Add a second triple to the list, for example triple(iri('https://example.org/s'), iri('https://example.org/p'), literal('hallo', lang('nl'))), and run again: two found lines appear, one for “hello” in English and one for “hallo” in Dutch. There is still one witness, because there is still one quoted graph, but its Skolem term now holds the larger graph.


Takeaway

Web addresses, language-tagged text, statements and quotations all fit into plain terms, so the same simple, checkable reasoning works on them.