330 likes | 465 Views
Semantic Web in Depth. Rules. Dr Nicholas Gibbins - nmg @ecs.soton.ac.uk 2013-2014. The Role of Rules. The Semantic Web concentrates on declarative forms of knowledge representation OWL, RDF Schema
E N D
Semantic Web in Depth Rules Dr Nicholas Gibbins - nmg@ecs.soton.ac.uk2013-2014
The Role of Rules The Semantic Web concentrates on declarative forms of knowledge representation • OWL, RDF Schema Rules are a common form of procedural knowledge representation elsewhere in Knowledge Engineering • Expert Systems • CLIPS, JESS, OPS, Prolog…
The Role of Rules The KR formalisms of the Semantic Web have expressive limitations which can be overcome by rule-based knowledge For example, we cannot express the fact that a person’s parent’s brother is the person’s uncle in either RDFS or OWL (including OWL Full) • No role composition in OWL 1.0
The Role of Rules Trivial to express in a language like Prolog: hasUncle(X,Y) :- hasParent(X,Z),hasBrother(Z,Y).hasBrother(X,Y) :- isMale(Y),hasParent(X,Z),hasParent(Y,Z).
Signature Encryption The Semantic Web layer cake User Interface and Applications Attribution Trust Proof Explanation OWL Rules SPARQL(queries) Ontologies +Inference RDF Schema Metadata RDF XML + Namespaces Standard syntax Identity URI Unicode
SPARQL CONSTRUCT PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>CONSTRUCT { ?x vcard:FN ?name . ?xvcard:EMAIL ?mail . }WHERE { ?xfoaf:name ?name . ?xfoaf:mbox ?mail . }
SPARQL CONSTRUCT is not a rule language From the Data Access Working Group Charter: “While it is hoped that the product of the RDF Data Access Working Group will be useful in later development of a rules language, development of such a rules language is out of scope for this working group. However, any serializations of a query language must not preclude extension to, or inclusion in, a rules language. The group should expend minimal effort assuring that such an extension be intuitive and and consistent with any query language produced by the group.”
Rules and the Semantic Web Several proposed rule languages for use with the SW: • RuleML • N3 Rules • Jena Rules • Semantic Web Rule Language (SWRL) • Rule Interchange Format (RIF)
Rule Format The majority of rules in rule-based systems are of the form:A ⇐ B1 ∧ B2 ∧ … ∧ Bn • A is known as the consequent or head of the rule • B1…Bn are known as the antecedents or body of the rule • Also known as Horn Clauses (disjunction with at most one positive literal)
Description Logics and Rules Some work on designing DLs which include trigger rules of the form:C ⇒D (if an individual is a member of C, then it must be a member of D
Description Logics and Rules C ⇒D is not the same as saying C ⊑ D (every instance of C is an instance of D) • C ⊑ D is equivalent to saying ¬D ⊑ ¬C (contrapositive) • The trigger rule C ⇒D is not equivalent to ¬D ⇒ ¬C DLs with rules include an epistemic (modal) operator K: • KC can be read as “the class of things which are known to be of class C” • C ⇒D is equivalent to KC ⊑ D • Used as a foundation for SWRL, etc
N3 Rules Defines log: namespace for logical operators • Some triples are “special” – interpreted as components of rules • log: namespace puts ontology into OWL Full Relies on N3 syntax for graphs: {} (not in Turtle, etc) Not widely implemented • cwm (TimBL’s pet reasoner) • +?
N3 Rules General form: { antecedent graph } log:implies { consequent graph }. Example: {?x ont:parent ?y. ?y ont:brother ?z. } log:implies {?x ont:uncle ?z. }.
Jena Rules Jena RDF/OWL library contains support for forward- and backward-chaining rules • Only implemented in Jena Syntax: [rule name: antecedents -> consequent ] Antecedents expressed as triple patterns (unfortunately not in a SPARQL-like syntax)
Jena Rule Example # Example rule file@prefix ont: <http://example.org/ontology#>.@include <RDFS>.[rule1: (?x ont:parent?t) (?t ont:brother?z) -> (?x ont:uncle?z)] can include other rulebases – these are the entailment rules for RDFS
SWRL Submitted to W3C in 2004 • Based on RuleML subset and OWL • XML and RDF-based serialisations(also, human-readable abstract syntax) • Obeys constraints put on OWL re: disjointness of instances and datatype values Two types of variable in expressions • I-variable – matches class instances • D-variable – matches datatype values
SWRL Rule Example hasParent(?x1,?x2) ∧ hasBrother(?x2,?x3) ⇒ hasUncle(?x1,?x3) In abstract syntax: Implies(Antecedent(hasParent(I-variable(x1) I-variable(x2))hasBrother(I-variable(x2) I-variable(x3)))Consequent(hasUncle(I-variable(x1) I-variable(x3))))
SWRL Rule Example Artist(?x) ∧ artistStyle(?x,?y) ∧ Style(?y) ∧ creator(?z,?x) ⇒ style/period(?z,?y) Implies(Antecedent(Artist(I-variable(x)) artistStyle(I-variable(x) I-variable(y))Style(I-variable(y))creator(I-variable(z) I-variable(x)))Consequent(style/period(I-variable(z) I-variable(y))))
SWRL Rule Example Artist(?x) ∧ (≤1 artistStyle)(?x) ∧ creator(?z,?x) ⇒ (≤1 style/period)(?z) Implies(Antecedent(Artist(I-variable(x))(restriction(artistStyle maxCardinality(1)))(I-variable(x))Style(I-variable(y))creator(I-variable(z) I-variable(x)))Consequent((restriction(style/period maxCardinality(1)) (I-variable(z))))
SWRL XML Syntax <ruleml:imp> <ruleml:_rlabruleml:href="#example1"/> <ruleml:_body> <swrlx:individualPropertyAtomswrlx:property="hasParent"> <ruleml:var>x1</ruleml:var> <ruleml:var>x2</ruleml:var> </swrlx:individualPropertyAtom> <swrlx:individualPropertyAtomswrlx:property="hasBrother"> <ruleml:var>x2</ruleml:var> <ruleml:var>x3</ruleml:var> </swrlx:individualPropertyAtom> </ruleml:_body> <ruleml:_head> <swrlx:individualPropertyAtomswrlx:property="hasUncle"> <ruleml:var>x1</ruleml:var> <ruleml:var>x3</ruleml:var> </swrlx:individualPropertyAtom> </ruleml:_head> </ruleml:imp>
SWRL RDF Syntax <swrl:Variablerdf:ID="x1"/><swrl:Variablerdf:ID="x2"/><swrl:Variablerdf:ID="x3"/><ruleml:Imp> <ruleml:bodyrdf:parseType="Collection”> <swrl:IndividualPropertyAtom> <swrl:propertyPredicaterdf:resource="⪚hasParent"/> <swrl:argument1 rdf:resource="#x1" /> <swrl:argument2 rdf:resource="#x2" /> </swrl:IndividualPropertyAtom> <swrl:IndividualPropertyAtom> <swrl:propertyPredicaterdf:resource="⪚hasSibling"/> <swrl:argument1 rdf:resource="#x2" /> <swrl:argument2 rdf:resource="#x3" /> </swrl:IndividualPropertyAtom> </ruleml:body> …
Rule Interchange Format • W3C Working Group chartered in late 2005 • More expressive language than SWRL • Common core with extensions • Reached Recommendation in June 2010
Rule Interchange Format • Defines XML syntax and non-XML presentation syntax (c.f. OWL) • Latest version from:http://www.w3.org/2005/rules/wiki/RIF_Working_Group
RIF Dialects Two dialects (building on a common core): • RIF Basic Logic Dialect • Monotonic condition and conclusion • Statements are either true or false • The values of predicates cannot be changed, you can only add new staements • RIF Production Rule Dialect • Non-monotonic condition and conclusion • Values of predicates can be changed
RIF Basic Logic Dialect • Definite Horn rules • Disjunction with exactly one positive literalA :- B and C and D • N-ary predicates (sugared syntax)
RIF Structure Rules occur in Groups: Group( (Forall ?x Q(?x) :- P(?x)) (Forall ?x Q(?x) :- R(?x))) Groups occur in Documents: Document( Group( (Forall ?x Q(?x) :- P(?x)) (Forall ?x Q(?x) :- R(?x)) ) Group( (Forall ?y R(?y) :- S(?y)) ))
RIF Example Document(Prefix(cpt http://example.com/concepts#)Prefix(ppl http://example.com/people#)Prefix(bks http://example.com/books#)Group (Forall ?Buyer ?Item ?Seller (cpt:buy(?Buyer ?Item ?Seller) :- cpt:sell(?Seller ?Item ?Buyer) )cpt:sell(ppl:Johnbks:LeRifppl:Mary)) )
RIF Example Document( Prefix(dbp http://dbpedia.org/property/) Prefix(my http://mydata.org/resource#) Prefix(rdfs http://www.w3.org/2000/01/rdf-schema#) Group ( Forall ?mname ?aname ?movie ?actor my:actorIn(?aname ?mname) :- And( dbp:starring(?movie ?actor) rdfs:label(?movie ?mname) rdfs:label(?actor ?aname) ) ))
RIF Example Document( Prefix(dbp http://dbpedia.org/property/) Prefix(my http://mydata.org/resource#) Prefix(rdfs http://www.w3.org/2000/01/rdf-schema#) Group ( Forall ?mname ?aname ?movie ?actor my:actorIn(?aname ?mname) :- And( ?movie[dbp:starring -> ?actor rdfs:label-> ?mname] ?actor[rdfs:label ?aname] ) ))