33
Semantic Web in Depth Rules Dr Nicholas Gibbins - [email protected] 2013-2014

Semantic Web in Depth

  • Upload
    elam

  • View
    46

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Semantic Web  in Depth

Semantic Web in DepthRules

Dr Nicholas Gibbins - [email protected]

Page 2: Semantic Web  in Depth

The Role of RulesThe 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…

Page 3: Semantic Web  in Depth

The Role of RulesThe 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

Page 4: Semantic Web  in Depth

The Role of RulesTrivial 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).

Page 5: Semantic Web  in Depth

Rules

XML + Namespaces

URI Unicode

Sign

atur

e

Encr

yptio

n

RDF

RDF Schema

OWL

Identity

Standard syntax

Metadata

Ontologies +Inference

Explanation

Attribution

SPARQL(queries)

Proof

Trust

User Interface and Applications

The Semantic Web layer cake

Page 6: Semantic Web  in Depth

SPARQL CONSTRUCTPREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>CONSTRUCT {

?x vcard:FN ?name .?x vcard:EMAIL ?mail .

}WHERE {

?x foaf:name ?name .?x foaf:mbox ?mail .

}

Page 7: Semantic Web  in Depth

SPARQL CONSTRUCT is not a rule languageFrom 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.”

Page 8: Semantic Web  in Depth

Rules and the Semantic WebSeveral proposed rule languages for use with the SW:

– RuleML– N3 Rules– Jena Rules– Semantic Web Rule Language (SWRL)– Rule Interchange Format (RIF)

Page 9: Semantic Web  in Depth

Rule FormatThe 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)

Page 10: Semantic Web  in Depth

Description Logics and RulesSome 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

Page 11: Semantic Web  in Depth

Description Logics and RulesC ⇒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

Page 12: Semantic Web  in Depth

N3 Rules

Page 13: Semantic Web  in Depth

N3 RulesDefines 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)– +?

Page 14: Semantic Web  in Depth

N3 RulesGeneral form:

{ antecedent graph } log:implies { consequent graph }.

Example:

{?x ont:parent ?y. ?y ont:brother ?z. } log:implies {?x ont:uncle ?z. }.

Page 15: Semantic Web  in Depth

Jena Rules

Page 16: Semantic Web  in Depth

Jena RulesJena 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)

Page 17: Semantic Web  in Depth

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

Page 18: Semantic Web  in Depth

Semantic Web Rule Language

Page 19: Semantic Web  in Depth

SWRLSubmitted 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

Page 20: Semantic Web  in Depth

SWRL Rule ExamplehasParent(?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))))

Page 21: Semantic Web  in Depth

SWRL Rule ExampleArtist(?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))))

Page 22: Semantic Web  in Depth

SWRL Rule ExampleArtist(?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))))

Page 23: Semantic Web  in Depth

SWRL XML Syntax<ruleml:imp>

<ruleml:_rlab ruleml:href="#example1"/><ruleml:_body>

<swrlx:individualPropertyAtom swrlx:property="hasParent"> <ruleml:var>x1</ruleml:var><ruleml:var>x2</ruleml:var>

</swrlx:individualPropertyAtom><swrlx:individualPropertyAtom swrlx:property="hasBrother">

<ruleml:var>x2</ruleml:var><ruleml:var>x3</ruleml:var>

</swrlx:individualPropertyAtom> </ruleml:_body> <ruleml:_head>

<swrlx:individualPropertyAtom swrlx:property="hasUncle"> <ruleml:var>x1</ruleml:var><ruleml:var>x3</ruleml:var>

</swrlx:individualPropertyAtom> </ruleml:_head>

</ruleml:imp>

Page 24: Semantic Web  in Depth

SWRL RDF Syntax<swrl:Variable rdf:ID="x1"/><swrl:Variable rdf:ID="x2"/><swrl:Variable rdf:ID="x3"/><ruleml:Imp>

<ruleml:body rdf:parseType="Collection”><swrl:IndividualPropertyAtom>

<swrl:propertyPredicate rdf:resource="&eg;hasParent"/>

<swrl:argument1 rdf:resource="#x1" /><swrl:argument2 rdf:resource="#x2" />

</swrl:IndividualPropertyAtom><swrl:IndividualPropertyAtom>

<swrl:propertyPredicate rdf:resource="&eg;hasSibling"/>

<swrl:argument1 rdf:resource="#x2" /><swrl:argument2 rdf:resource="#x3" />

</swrl:IndividualPropertyAtom></ruleml:body>…

Page 25: Semantic Web  in Depth

Rule Interchange

Format

Page 26: Semantic Web  in Depth

Rule Interchange Format•W3C Working Group chartered in late 2005

•More expressive language than SWRL– Common core with extensions

•Reached Recommendation in June 2010

Page 27: Semantic Web  in Depth

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

Page 28: Semantic Web  in Depth

RIF DialectsTwo 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

Page 29: Semantic Web  in Depth

RIF Basic Logic Dialect•Definite Horn rules

– Disjunction with exactly one positive literal

A :- B and C and D

•N-ary predicates (sugared syntax)

Page 30: Semantic Web  in Depth

RIF StructureRules 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)) )

)

Page 31: Semantic Web  in Depth

RIF ExampleDocument(

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:John bks:LeRif ppl:Mary)

))

Page 32: Semantic Web  in Depth

RIF ExampleDocument(

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) )

))

Page 33: Semantic Web  in Depth

RIF ExampleDocument(

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] )

))