Sandro Hawke
(sandro@w3.org)
@sandhawke
SemTech 2010, 24 June 2010
http://www.w3.org/2010/Talks/0624-rif-sandro
"Rule Interchange Format", not "Semantic Web Rule Language"
<!DOCTYPE Document [ <!ENTITY ppl "http://example.com/people#"> <!ENTITY cpt "http://example.com/concepts#"> <!ENTITY dc "http://purl.org/dc/terms/"> <!ENTITY rif "http://www.w3.org/2007/rif#"> <!ENTITY func "http://www.w3.org/2007/rif-builtin-function#"> <!ENTITY pred "http://www.w3.org/2007/rif-builtin-predicate#"> <!ENTITY xs "http://www.w3.org/2001/XMLSchema#"> ]> <Document xmlns="http://www.w3.org/2007/rif#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema#"> <payload> <Group> <id> <Const type="&rif;iri">http://sample.org</Const> </id> <meta> <Frame> <object> <Const type="&rif;local">pd</Const> </object> <slot ordered="yes"> <Const type="&rif;iri">&dc;publisher</Const> <Const type="&rif;iri">http://www.w3.org/</Const> </slot> <slot ordered="yes"> <Const type="&rif;iri">&dc;date</Const> <Const type="&xs;date">2008-04-04</Const> </slot> </Frame> </meta> <sentence> <Forall> <declare><Var>item</Var></declare> <declare><Var>deliverydate</Var></declare> <declare><Var>scheduledate</Var></declare> <declare><Var>diffduration</Var></declare> <declare><Var>diffdays</Var></declare> <formula> <Implies> <if> <And> <formula> <Atom> <op><Const type="&rif;iri">&cpt;perishable</Const></op> <args ordered="yes"><Var>item</Var></args> </Atom> </formula> <formula> <Atom> <op><Const type="&rif;iri">&cpt;delivered</Const></op> <args ordered="yes"> <Var>item</Var> <Var>deliverydate</Var> <Const type="&rif;iri">&ppl;John</Const> </args> </Atom> </formula> <formula> <Atom> <op><Const type="&rif;iri">&cpt;scheduled</Const></op> <args ordered="yes"> <Var>item</Var> <Var>scheduledate</Var> </args> </Atom> </formula> <formula> <Equal> <left><Var>diffduration</Var></left> <right> <External> <content> <Expr> <op><Const type="&rif;iri">&func;subtract-dateTimes</Const></op> <args ordered="yes"> <Var>deliverydate</Var> <Var>scheduledate</Var> </args> </Expr> </content> </External> </right> </Equal> </formula> <formula> <Equal> <left><Var>diffdays</Var></left> <right> <External> <content> <Expr> <op><Const type="&rif;iri">&func;days-from-duration</Const></op> <args ordered="yes"> <Var>diffduration</Var> </args> </Expr> </content> </External> </right> </Equal> </formula> <formula> <External> <content> <Atom> <op><Const type="&rif;iri">&pred;numeric-greater-than</Const></op> <args ordered="yes"> <Var>diffdays</Var> <Const type="&xs;integer">10</Const> </args> </Atom> </content> </External> </formula> </And> </if> <then> <Atom> <op><Const type="&rif;iri">&cpt;reject</Const></op> <args ordered="yes"> <Const type="&rif;iri">&ppl;John</Const> <Var>item</Var> </args> </Atom> </then> </Implies> </formula> </Forall> </sentence> <sentence> <Forall> <declare><Var>item</Var></declare> <formula> <Implies> <if> <Atom> <op><Const type="&rif;iri">&cpt;unsolicited</Const></op> <args ordered="yes"><Var>item</Var></args> </Atom> </if> <then> <Atom> <op><Const type="&rif;iri">&cpt;reject</Const></op> <args ordered="yes"> <Const type="&rif;iri">&ppl;Fred</Const> <Var>item</Var> </args> </Atom> </then> </Implies> </formula> </Forall> </sentence> </Group> </payload> </Document>
Document( Prefix(ppl <http://example.com/people#>) Prefix(cpt <http://example.com/concepts#>) Prefix(dc <http://purl.org/dc/terms/>) Prefix(rif <http://www.w3.org/2007/rif#>) Prefix(func <http://www.w3.org/2007/rif-builtin-function#>) Prefix(pred <http://www.w3.org/2007/rif-builtin-predicate#>) Prefix(xs <http://www.w3.org/2001/XMLSchema#>) (* "http://sample.org"^^rif:iri _:pd[dc:publisher -> "http://www.w3.org/"^^rif:iri dc:date -> "2008-04-04"^^xs:date] *) Group ( Forall ?item ?deliverydate ?scheduledate ?diffduration ?diffdays ( cpt:reject(ppl:John ?item) :- And(cpt:perishable(?item) cpt:delivered(?item ?deliverydate ppl:John) cpt:scheduled(?item ?scheduledate) ?diffduration = External(func:subtract-dateTimes(?deliverydate ?scheduledate)) ?diffdays = External(func:days-from-duration(?diffduration)) External(pred:numeric-greater-than(?diffdays 10))) ) Forall ?item ( cpt:reject(ppl:Fred ?item) :- cpt:unsolicited(?item) ) ) )
Nothing standard... room for experimentation
Prefix ppl <http://example.com/people#> Prefix cpt <http://example.com/concepts#> Prefix dc <http://purl.org/dc/terms/> Prefix rif <http://www.w3.org/2007/rif#> Prefix func <http://www.w3.org/2007/rif-builtin-function#> Prefix pred <http://www.w3.org/2007/rif-builtin-predicate#> Prefix xs <http://www.w3.org/2001/XMLSchema#> (* <http://sample.org> { _:pd dc:publisher lt;http://www.w3.org/>; dc:date "2008-04-04"^^xs:date] } *) if cpt:perishable(?item) and cpt:delivered(?item ?deliverydate ppl:John) and cpt:scheduled(?item ?scheduledate) and func:days-from-duration(?deliverydate - ?scheduledate) > 10 then cpt:reject(ppl:John ?item). if cpt:unsolicited(?item) then cpt:reject(ppl:Fred ?item).
Slippery slope to "real" rule languages.
Not all engines implement the same features
Some features (retract and negation) are incompatible
Forward chaining, Backward chaining
Core: common subset
BLD: (basic logic dialect) common subset of Prolog-style languages
PRD: (production rule dialect) common subset of Production Rule languages
Double-check the specs
Check mailing list, Wiki
Check the Framework for Logic Dialects
Okay to define your own dialects
When adding an extension, consider:
What should non-implementing systems do?
(controlling this is "extensibility")
If non-implementers should... | Your extension should... |
---|---|
ignore it | use RIF annotations (metadata) |
stop | define new XML elements |
rewrite | [not yet supported] |
Add XML Elements, in your own namespace
Non-implementing systems will reject document
Document it, share on public-rif-dev@w3.org
Ideally, non-implementing systems could look up extension
Syntactic sugar -> perfect rewrites
Other rewrites have some "impact"
Proposed as XTAN, but not adopted in RIF
Useful, yes. But "necessary"?
if { ?p rdfs:range ?c. ?x ?p ?y } then { ?y rdf:type ?c }
See OWL 2 RL in RIF
In the January 2010 version, FOAF changed foaf:family_name to foaf:familyName. How many apps did this break?
Let's use this rule:
if { ?person foaf:family_name ?fam } then { ?person foaf:familyName ?fam }
(Yes, you could also do this with owl:equivalentProperty.)
FOAF has both firstName + lastName and (combined) name. Many data sources do not provide both. (Vocabulary Mapping)
if { ?person foaf:firstName ?first; foaf:lastName ?last } then { ?person foaf:name func:string-join(?first " " ?last) } # Works for Hillary Rodham Clinton, not Sarah Jessica Parker if { ?person foaf:name ?name } and pred:contains(?name, " ") then { ?x foaf:firstName func:string-before(?name, " "); foaf:lastName func:string-after(?name, " ") }
Facebook's Open Graph Protocol uses a simple-to-use (page-style) RDF vocabulary:
og:type - The type of your object, e.g., "movie". Depending on the type you specify, other properties may also be required.
That is:
<http://www.imdb.com/title/tt0117500/> og:type "movie".
Is an IMDB web page a movie??
Convert to standard RDF modeling:
if { ?page og:type "movie"; foaf:primaryTopic ?resource } then { ?resource rdf:type dbpedia-owl:Film }
RIF for Linked Data Allows:
RIF is stable, widely reviewed
Many implementation (not many products yet)
Use for Linked Data is experimental, but critical.
Test Suite:
The Future: