Download presentation
Presentation is loading. Please wait.
1
Semantic Web in Depth Rules
Professor Steffen Staab Many slides courtesy by Dr. Nick Gibbins
2
The Semantic Web layer cake
Proof Trust User Interface and Applications XML + Namespaces URI Unicode Signature Encryption RDF RDF Schema OWL Identity Standard syntax Metadata Ontologies + Inference Explanation Attribution SPARQL (queries) Rules
3
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 assert a new fact in OWL by checking three other relations, like: triangle(?x,?y,?z) :- knows(?x,?y),knows(?y,?z),knows(?z,?x). “Three nodes are called a triangle if all three nodes know each other.” OWL does not allow for stating constraints: Inconsistent :- hasChild(?x,?y), hasAge(?x,?n), hasAge(?y,?m), ?n < ?m. “A parent cannot be younger than his/her child.”
4
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)
5
Rule Format 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 Rule systems differ in what kind of heads and antecedents they allow Propositional: P, Q, … Relational: Pk(?X1,…,?Xn) (nested) Function Symbols: Pk(f(?X1),…,g(?Xn-1, f(?X1),?Xn)) Negation (for the antecedent): not Pk (?X1,…,?Xn)
6
Rules – One Word for Two Things
Declarative, but rather procedural knowledge Traditional Expert Systems CLIPS, JESS, OPS,… Database triggers, ECA rules (Event-Condition-Action), Production rules Rules are active in time The order of processing is key to the effect of rules Declarative, (truely) logical knowledge Datalog (part of many DBs) Answer set programming: DLV, Potassco F-Logic: Florid, Ontobroker, Flora-2 / Ergo Suite … Rules describe logical constraints. Either used to derive data views (F-Logic) XOR logical consistency (ASP)
7
Rules – One Word for Two Things
Declarative, but rather procedural knowledge Traditional Expert Systems CLIPS, JESS, OPS,… Database triggers, ECA rules (Event-Condition-Action), Production rules Rules are active in time The order of processing is key to the effect of rules Declarative, (truely) logical knowledge Datalog (part of many DBs) Answer set programming: DLV, Potassco F-Logic: Florid, Ontobroker, Flora-2 / Ergo Suite … Rules describe logical constraints. Either used to derive data views (F-Logic) XOR logical consistency (ASP) Some important languages sit in the middle: Prolog, RIF,...
8
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) SPIN
9
ECA-like Rules: Given Empty default graph PREFIX dc: my: < Rule my:hasCreated(?X,?Y) :- dc:creator(?Y,?X). Sequence of Actions INSERT DATA { < dc:creator "A.N.Other" . } DELETE DATA { < dc:creator "A.N.Other" . } What is now returned in Step 3? CREATE ?X ?P ?Z. WHERE {?X ?P ?Z.} "A.N.Other“ my:hasCreated < An event happened here that added a statement which was never retracted by another rule.
10
Declarative Logical Rules:
Given Empty default graph PREFIX dc: my: < Rule my:hasCreated(?X,?Y) :- dc:creator(?Y,?X). Sequence of Actions INSERT DATA { < dc:creator "A.N.Other" . } DELETE DATA { < dc:creator "A.N.Other" . } What is now returned in Step 3? CREATE ?X ?P ?Z. WHERE {?X ?P ?Z.} {} Here, data and logical rules are questioned to determine what holds at time of querying.
11
Issues with Semantics of Logical Rules
Recursion Infinite structures Undecidability Multiple semantics Negation Function symbols Negation-as-failure Non-monotonicity
12
Non-monotonicity Given: Person(nicola). Man(?X) :- Person(?X), not Woman(?X). Infers: Man(nicola). But add another fact: Woman(nicola) Then the inference Man(nicola) needs to be retracted. OWL and 1st order predicate logics are monotonous: More facts always lead to more inferences, never to less.
13
Multiple Semantics Given: Person(nicola). Man(?X) :- Person(?X), not Woman(?X). Woman(?X) :- Person(?X), not Man(?X). What should be inferred? Possibility 1: Nothing (e.g. well-founded semantics) Possibility 2: Two competing solutions that are never true at the same time (e.g. answer-set semantics) a. Man(nicola) b. Woman(nicola)
14
Infinite Structures Number(0). Number(succ(?X)) :- Number(?X). Number holds for 0, succ(0), succ(succ(0)),... Even(0). Even(0) Even(succ(succ(?X))) :- Even(?X). Even(2),Even(4),... Odd(succ(?X)) :- Even(?X). Odd(1),Odd(3),.. Magic :- EXISTS ?X Number(?X) and not Even(?X) and not Odd(?X). Magic requires to check all infinitely many numbers
15
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
16
Description Logics and Rules
C ⇒D is (often) 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 procedural 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
17
SPIN
18
SPARQL CONSTRUCT PREFIX foaf: < PREFIX vcard: < CONSTRUCT { ?x vcard:FN ?name . ?x vcard: ?mail . } WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mail . } CONSTRUCT matches graph patterns and returns a new graph We could implement a simple rule-based system using CONSTRUCT queries to represent rules
19
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.” Spin goes this way.
20
Constraints # must be at least 18 years old ASK WHERE { ?this ex:age ?age . FILTER (?age < 18) . } Put this boolean condition on a class.
21
Class constraint in SPIN
ex:Parent a rdfs:Class ; rdfs:label "Parent"^^xsd:string ; rdfs:subClassOf ex:Person ; spin:constraint [ a sp:Ask ; rdfs:comment "must be at least 18 years old"^^xsd:string ; sp:where ([ sp:object sp:_age ; variable ?age sp:predicate ex:age ; property ex:age sp:subject spin:_this variable ?this ] [ a sp:Filter ; sp:expression [ a sp:lt ; sp:arg1 sp:_age ; sp:arg2 18 ] ]) ]. Spin encodes the syntax tree of SPARQL queries using blank nodes.
22
Spin encodes the syntax tree of SPARQL queries using blank nodes.
Unreadable Unless it is made readable by a tool Constraint/rule can be stored together with data and executed to indicate consistency or inferred data
23
SPARQL Construct Query
CONSTRUCT { ?this ex:grandParent ?grandParent . } WHERE { ?parent ex:child ?this . ?grandParent ex:child ?parent .
24
SPARQL Construct Query Turned into SPIN Rule
ex:Person a rdfs:Class ; rdfs:label "Person"^^xsd:string ; rdfs:subClassOf owl:Thing ; spin:rule [ a sp:Construct ; sp:templates ([ sp:object sp:_grandParent ; sp:predicate ex:grandParent ; sp:subject spin:_this ]) ; sp:where ([ sp:object spin:_this ; sp:predicate ex:child ; sp:subject sp:_parent ] [ sp:object sp:_parent ; sp:subject sp:_grandParent ]) ] .
25
Jena Rules
26
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)
27
Jena Rule Example # Example rule file @prefix ont: < @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
28
Semantic Web Rule Language
29
SWRL Member Submission 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
30
SWRL Rule Example In abstract syntax:
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))))
31
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)))) Class membership
32
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)))) Use of restrictions and other OWL features
33
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> Based on OWL XML Presentation Syntax (with RuleML)
34
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="⪚hasParent"/> <swrl:argument1 rdf:resource="#x1" /> <swrl:argument2 rdf:resource="#x2" /> </swrl:IndividualPropertyAtom> <swrl:IndividualPropertyAtom> <swrl:propertyPredicate rdf:resource="⪚hasSibling"/> <swrl:argument1 rdf:resource="#x2" /> <swrl:argument2 rdf:resource="#x3" /> </swrl:IndividualPropertyAtom> </ruleml:body> …
35
Rule Interchange Format
36
Rule Interchange Format
W3C Working Group chartered in late 2005 More expressive language than SWRL Common core with extensions Reached Recommendation in June 2010
37
Rule Interchange Format
Defines XML syntax and non-XML presentation syntax (c.f. OWL) Latest version from:
38
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 statements RIF Production Rule Dialect Non-monotonic condition and conclusion Values of predicates can be changed
39
RIF Basic Logic Dialect
Definite Horn rules Disjunction with exactly one positive literal A :- B and C and D N-ary predicates (sugared syntax)
40
RIF Structure Rules occur in Groups: Groups occur in Documents:
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)) ) )
41
RIF Example Document( Prefix(cpt Prefix(ppl Prefix(bks Group ( Forall ?Buyer ?Item ?Seller ( cpt:buy(?Buyer ?Item ?Seller) : cpt:sell(?Seller ?Item ?Buyer) ) cpt:sell(ppl:John bks:LeRif ppl:Mary) ) )
42
RIF Example Document( Prefix(dbp Prefix(my Prefix(rdfs Group ( Forall ?mname ?aname ?movie ?actor my:actorIn(?aname ?mname) : And( dbp:starring(?movie ?actor) rdfs:label(?movie ?mname) rdfs:label(?actor ?aname) ) ) )
43
RIF Example Document( Prefix(dbp Prefix(my Prefix(rdfs Group ( Forall ?mname ?aname ?movie ?actor my:actorIn(?aname ?mname) :- And( ?movie[dbp:starring -> ?actor rdfs:label -> ?mname] ?actor[rdfs:label ?aname] ) ) )
44
Reflection
45
Reflection on Rules Current subjective assessment of rules
Much used in Knowledge representation and Databases More used than Description Logics Rules are not exchanged much on the Web Suggested solution for the time being: Define your rules locally Use whatever rule mechanism and syntax you like Apply with data from the Web
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.