A few general statements about categories and relations, and the facts that follow from them.
schema-inference.py · output · proof · check · try it in the playground
Data on the web often comes with a schema: general statements about what the data means. “Every cat is a mammal.” “If someone is a parent of someone, they are related.” “Only people can be parents.”
Given a schema and a couple of plain facts — Koko is a cat; Alice is Bob’s parent —
what else can we safely conclude? And can each conclusion be traced back to the statements it came from?
parent_of
implies related_to.parent_of is a person.These are the core ideas of the web’s RDF Schema, written here as ordinary rules.
fact(subclass('cat', 'mammal'))
fact(subclass('mammal', 'animal'))
fact(subproperty('parent_of', 'related_to'))
fact(domain('parent_of', 'person'))
fact(codomain('parent_of', 'person'))
fact(type('koko', 'cat'))
fact(triple('alice', 'parent_of', 'bob'))
implies(subclass(A, B) & subclass(B, C), subclass(A, C))
implies(type(X, A) & subclass(A, B), type(X, B))
implies(triple(S, P, O) & subproperty(P, Q), triple(S, Q, O))
implies(triple(S, P, _) & domain(P, Class), type(S, Class))
implies(triple(_, P, O) & codomain(P, Class), type(O, Class))
implies means “keep applying this until nothing new follows”. No question is
asked, so peye reports everything new.
subclass('cat', 'animal')
type('koko', 'animal')
type('koko', 'mammal')
triple('alice', 'related_to', 'bob')
type('alice', 'person')
type('bob', 'person')
Six new facts, none of them typed in:
Each conclusion cites the rule and facts behind it:
parent_of implies related_to, so Alice
is related to Bob — rule 10.Step 2 builds on step 1: one conclusion feeds the next.
A separate checker read all 13 proof steps against the program and confirmed that:
Verdict: checked. Nothing taken on trust.
python -m peye examples/schema-inference.py # the new facts
python -m peye --proof examples/schema-inference.py # with their proof
Or open it in the playground.
Add fact(triple('bob', 'parent_of', 'carol')) and run again: Bob becomes related to
Carol, and Carol is concluded to be a person.
A schema says a lot in a few lines. peye spells out what it implies, and every implied fact comes with the exact statements that support it — so a surprising conclusion can be traced to the schema line that caused it.