logic and rules n.
Skip this Video
Loading SlideShow in 5 Seconds..
Logic and Rules PowerPoint Presentation
Download Presentation
Logic and Rules

Logic and Rules

135 Vues Download Presentation
Télécharger la présentation

Logic and Rules

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Logic and Rules Most material was taken from the following source: Grigoris Antoniou, Frank van Harmelen, A Semantic Web Primer, 2nd Edition, MIT Press, 2008, ISBN 978-0-262-01242-3.

  2. Lecture Outline • Introduction • Rules: Example • Rules: Syntax & Semantics • RuleML & RIF: XML Representation for Rules • Rules & Ontologies: OWL 2 RL & SWRL Logic and Rules

  3. Knowledge Representation • The subjects presented so far were related to the representation of knowledge • Knowledge Representation was studied long before the emergence of WWW in AI • Logic is still the foundation of KR, particularly in the form of predicate logic (first-order logic) Logic and Rules

  4. The Importance of Logic • High-level language for expressing knowledge • High expressive power • Well-understood formal semantics • Precise notion of logical consequence • Proof systems that can automatically derive statements syntactically from a set of premises Logic and Rules

  5. The Importance of Logic (2) • There exist proof systems for which semantic logical consequence coincides with syntactic derivation within the proof system • Soundness & completeness Logic and Rules

  6. The Importance of Logic (3) • Predicate logic is unique in the sense that sound and complete proof systems do exist. • Not for more expressive logics (higher-order logics) • Logic can trace the proof that leads to a logical consequence. • Logic can provide explanations for answers • By tracing a proof Logic and Rules

  7. Specializations of Predicate Logic:RDF and OWL • RDF/S and OWL (Lite and DL) are specializations of predicate logic • correspond roughly to a description logic • They define reasonable subsets of logic • Trade-off between the expressive power and the computational complexity: • The more expressive the language, the less efficient the corresponding proof systems Logic and Rules

  8. Specializations of Predicate Logic:Horn Logic • A rule has the form: A1, . . ., An  B • Ai and B are atomic formulas • There are 2 ways of reading such a rule: • Deductive rules: If A1,..., An are known to be true, then B is also true • Reactive rules: If the conditions A1,..., An are true, then carry out the action B Logic and Rules

  9. Description Logics vs. Horn Logic • Neither of them is a subset of the other • It is impossible to assert that persons who study and live in the same city are “home students” in OWL • This can be done easily using rules: studies(X,Y), lives(X,Z), loc(Y,U), loc(Z,U)  homeStudent(X) • Rules cannot assert the information that a person is either a man or a woman • This information is easily expressed in OWL using disjoint union Logic and Rules

  10. Exchange of Rules • Exchange of rules across different applications • E.g., an online store advertises its pricing, refund, and privacy policies, expressed using rules • The Semantic Web approach is to express the knowledge in a machine-accessible way using one of the Web languages we have already discussed • We show how rules can be expressed in XML-like languages (“rule markup languages”) Logic and Rules

  11. Lecture Outline • Introduction • Rules: Example • Rules: Syntax & Semantics • RuleML & RIF: XML Representation for Rules • Rules & Ontologies: OWL 2 RL & SWRL Logic and Rules

  12. Family Relations • Facts in a database about relations: • mother(X,Y), X is the mother of Y • father(X,Y), X is the father of Y • male(X), X is male • female(X), X is female • Inferred relation parent: A parent is either a father or a mother mother(X,Y)  parent(X,Y) father(X,Y)  parent(X,Y) Logic and Rules

  13. Inferred Relations • male(X), parent(P,X), parent(P,Y), notSame(X,Y)  brother(X,Y) • female(X), parent(P,X), parent(P,Y), notSame(X,Y) sister(X,Y) • brother(X,P), parent(P,Y)  uncle(X,Y) • mother(X,P), parent(P,Y)  grandmother(X,Y) • parent(X,Y)  ancestor(X,Y) • ancestor(X,P), parent(P,Y)  ancestor(X,Y) Logic and Rules

  14. A More Complex Rule ExampleBrokered Trade • Brokered trades take place via an independent third party, the broker • The broker matches the buyer’s requirements and the sellers’ capabilities, and proposes a transaction when both parties can be satisfied by the trade • The application is apartment renting an activity that is common and often tedious and time-consuming Logic and Rules

  15. The Potential Buyer’s Requirements • At least 45 m2 with at least 2 bedrooms • Elevator if on 3rd floor or higher • Pet animals must be allowed • Carlos is willing to pay: • 300 € for a centrally located 45 m2 apartment • 250 € for a similar flat in the suburbs • An extra 5 € per m2 for a larger apartment • An extra 2 € per m2 for a garden • He is unable to pay more than 400 € in total Logic and Rules

  16. The Potential Buyer’s Requirements (2) • If given the choice, he would go for the cheapest option • His second priority is the presence of a garden • His lowest priority is additional space Logic and Rules

  17. Formalization of Carlos’s Requirements – Predicates Used • apartment(x), x is an apartment • size(x,y), y is the size of apartment x (in m2) • bedrooms(x,y), x has y bedrooms • price(x,y), y is the price for x • floor(x,y), x is on the y-th floor • gardenSize(x,y), x has a garden of size y Logic and Rules

  18. Formalization of Carlos’s Requirements – Predicates Used (2) • lift(x), there is an elevator in the house of x • pets(x), pets are allowed in x • central(x), x is centrally located • acceptable(x), flat x satisfies Carlos’s requirements • offer(x,y), Carlos is willing to pay y € for flat x Logic and Rules

  19. Formalization of Carlos’s Requirements – Rules acceptable(X):- apartment(X), not(incompatible(X)). incompatible(X):- bedrooms(X,Y), Y < 2. incompatible(X):- size(X,Y), Y < 45. incompatible(X):- not(pets(X)). incompatible(X):- floor(X,Y), Y > 2, not(lift(X)). incompatible(X):- price(X,Y), Y > 400 . Logic and Rules

  20. Formalization of Carlos’s Requirements – Rules (2) offer(X,O) :- size(X,Y), Y ≥ 45, garden(X,Z), central(X), O = 300 + 2*Z+5*(Y-45). offer(X,O) :- size(X,Y), Y ≥ 45, garden(X,Z), not(central(X)), O = 250+ 2*Z+5*(Y-45). incompatible(X):- offer(X,Y), price(X,Z), Y < Z. Logic and Rules

  21. Selecting an ApartmentAuxiliary predicates cheapest(X) :- acceptable(X), price(X,P1), not( (acceptable(Y), price(Y,P2), P2 < P1) ). largestGarden(X):- acceptable(X), gardenSize(X,G1), not( (acceptable(Y), gardenSize(Y,G2), G2 > G1) ). largest(X):- acceptable(X), size(X,S1), not( (acceptable(Y), size(Y,S2), S1<S2) ). Logic and Rules

  22. Selecting an Apartment cll(X):- cheapest(X), largestGarden(X), largest(X). cl(X) :- cheapest(X), largestGarden(X). c(X) :- cheapest(X). rent(X):- cll(X). rent(X):- cl(X), not(cll(Y)). rent(X):- c(X), not(cl(Y)). Logic and Rules

  23. Representation of Available Apartments pets(a1) garden(a1,0) price(a1,300) apartment(a1) bedrooms(a1,1) size(a1,50) central(a1) floor(a1,1) Logic and Rules

  24. Representation of Available Apartments (2) Logic and Rules

  25. Lecture Outline • Introduction • Rules: Example • Rules: Syntax & Semantics • RuleML & RIF: XML Representation for Rules Logic and Rules

  26. Rules – Syntax loyalCustomer(X), age(X) > 60  discount(X) • We distinguish some ingredients of rules: • variables which are placeholders for values: X • constants denote fixed values: 60 • Predicatesrelate objects: loyalCustomer, > • Function symbols which return a value for certain arguments: age Logic and Rules

  27. Rules B1, . . . , Bn  A • A, B1, ... , Bn are atomic formulas • A is the head of the rule • B1, ... , Bn are the premises (body of the rule) • The commas in the rule body are read conjunctively • Variables may occur in A, B1, ... , Bn • loyalCustomer(X), age(X) > 60  discount(X) • Implicitly universally quantified Logic and Rules

  28. Facts and Logic Programs • A fact is an atomic formula • E.g. loyalCustomer(a345678) • The variables of a fact are implicitly universally quantified. • A logic program P is a finite set of facts and rules. Logic and Rules

  29. Goals • A goal denotes a query G asked to a logic program • The form: • B1, . . . , Bn OR • ?- B1, . . . , Bn. (as in Prolog) Logic and Rules

  30. Proof Procedure • We use a proof technique from mathematics called proof by contradiction: • Prove that A follows from B by assuming that A is false and deriving a contradiction, when combined with B • In logic programming we prove that a goal can be answered positively by negating the goal and proving that we get a contradiction using the logic program • E.g., given the following logic program we get a logical contradiction Logic and Rules

  31. An Example p(a) ¬X p(X) • The 2nd formula says that no element has the property p • The 1st formula says that the value of a does have the property p • Thus X p(X) follows from p(a) contradiction Logic and Rules

  32. First-Order Interpretation of Goals p(a) p(X)  q(X) q(X)  • q(a) follows from the logical program • X q(X) follows from the logical program • Thus, “logical program”{¬Xq(X)} is unsatisfiable, and we give a positive answer Logic and Rules

  33. First-Order Interpretation of Goals (2) p(a) p(X)  q(X) q(b)  • We must give a negative answer because q(b) does not follow fromthe logical program Logic and Rules

  34. Carlo ExampleDetermining Acceptable Apartments • If we match Carlos’s requirements and the available apartments, we see that • flat a1 is not acceptable because it has one bedroom only • flats a4 and a6 are unacceptable because pets are not allowed • for a2, Carlos is willing to pay $ 300, but the price is higher • flats a3, a5, and a7 are acceptable Logic and Rules

  35. Inference for room a1 apartment(a1). bedrooms(a1,1). acceptable(X):- apartment(X), not(incompatible(X)). incompatible(X):- bedrooms(X,Y), Y < 2. ?- acceptable(a1). FALSE  apartment(a1), not(incompatible(a1))FALSE bedrooms(a1,1), 1 < 2 TRUE  Logic and Rules

  36. Inference for room a3 apartment(a3). bedrooms(a3,2). size(a3,65). floor(a3,2). pets(a3). garden(a3,0). price(a3,350). acceptable(X):- apartment(X), not(incompatible(X)). ?- acceptable(a3).  apartment(a3), not(incompatible(a3)) In order for «not» to becometrue, all alternative ways to proveincompatibility must beproven false Logic and Rules

  37. Formalization of Carlos’s Requirements – Rules incompatible(a3):- bedrooms(a3,2), 2 < 2.FALSE incompatible(a3):- size(a3,65), 65 < 45. FALSE incompatible(a3):- not(pets(a3)). FALSE incompatible(a3):- floor(a3,2), 2 > 2, not(lift(a3)). FALSE incompatible(a3):- price(a3,350), 350 > 400. FALSE incompatible(a3):- offer(a3,350), price(a3,350), 350 < 350. FALSE offer(a3,350) :- size(a3,65), 65 ≥ 45, garden(a3,0), not(central(a3)), 350 = 250+ 2*0+5*(65-45). Logic and Rules

  38. Selecting the “best” apartment • ?- rent(a3). • No • ?- rent(a5). • Yes • ?- rent(a7). • No • Among the acceptable (compatible) apartments a3, a5, a7, apartments a3 and a5 are cheapest. • Of these, a5 has the largest garden. • Thus a5 is suggested for renting. Logic and Rules

  39. Lecture Outline • Introduction • Rules: Example • Rules: Syntax & Semantics • RuleML & RIF: XML Representation for Rules • Rules & Ontologies: OWL 2 RL & SWRL Logic and Rules

  40. Rule Markup Language (RuleML) • RuleML: effort to develop markup of rules on the web • A familyof rule languages, corresponding to different kinds of rule languages: • derivation rules, integrity constraints, reaction rules, … • The kernel of the RuleML family is Datalog • function-free Horn logic • RuleML is experimental • studies various features of rule languages that are far from being standardized (e.g. nonmonotonic rules) • These efforts may feed into future standards • RuleML results were important in the development of RIF Logic and Rules

  41. The discount for a customer buying a product is 7.5% if the customer is premium and the product is luxury <Implies> <then> <Atom> <Rel>discount</Rel> <Var>customer</Var> <Var>product</Var> <Ind>7.5 percent</Ind> </Atom> </then> <if> <And> <Atom> <Rel>premium</Rel> <Var>customer</Var> </Atom> <Atom> <Rel>luxury</Rel> <Var>product</Var> </Atom> </And> </if> </Implies> Logic and Rules

  42. Atomic Formulas • p(X, a, f(b, Y)) <Atom> <Rel>p</Rel> <Var>X</Var> <Ind>a</Ind> <Expr> <Fun>f</Fun> <Ind>b</Ind> <Var>Y</Var> </Expr> </Atom> Logic and Rules

  43. Facts p(a). <Fact> <Atom> <Rel>p</Rel> <Ind>a</Ind> </Atom> </Fact> Logic and Rules

  44. Rules p(X,a), q(Y,b)  r(X,Y) <If> <And> <Atom><Rel>p</Rel> <Var>X</Var> <Ind>a</Ind> </Atom> <Atom><Rel>q</Rel> <Var>Y</Var> <Ind>b</Ind> </Atom> </And> </If> </Implies> <Implies> <Then> <Atom> <Rel>r</Rel> <Var>X</Var> <Var>Y</Var> </Atom> </Then> Logic and Rules

  45. RuleML: RuleMarkupLanguageDTD (one of the many variations) <!ELEMENT rulebase((Implies|Fact)*)> <!ELEMENT Fact (Atom)> <!ELEMENT Implies ((If,Then)|(Then,If))> <!ELEMENT If (Atom)> <!ELEMENT Then (Atom|Naf|And|Or)> <!ELEMENT Atom (Rel,(Ind|Var|Expr)*)> <!ELEMENT Naf (Atom)+)> <!ELEMENT And (Atom)+)> <!ELEMENT Or (Atom)+)> <!ELEMENT Rel (#PCDATA)> <!ELEMENT Var (#PCDATA)> <!ELEMENT Ind (#PCDATA)> <!ELEMENT Expr (Fun, (Ind|Var|Expr)*)> <!ELEMENT Fun (#PCDATA)> Logic and Rules

  46. Carlo – RuleML equivalent incompatible(X):- not(pets(X)). Negation As Failure <Implies> <Then> <Atom> <Rel>incompatible</Rel> <Var>x</Var> </Atom> </Then> <If> <Naf> <Atom> <Rel>pets</Rel> <var>x</var> </Atom> </Naf> </If> </Implies> Logic and Rules

  47. Rule Interchange Format: RIF • Rule technology exhibits a broad variety • e.g. action rules, first order rules, logic programming • The aim of the W3C RIF Working Group • not to develop a new rule language that would fit all purposes, • focus on the interchange among the various Web rules • A family of languages, called dialects (2 kinds) • Logic-based dialects. Based on some form of logic • e.g. first-order logic, and various logic programming approaches • RIF Core, essentially corresponding to function-free Horn logic • RIF Basic Logic Dialect (BLD), Horn logic withequality. • Rules with actions (Production systems and reactive rules) • Production RuleDialect (RIF-PRD). Logic and Rules

  48. RIF-BLD • Corresponds to Horn logic with equality plus • Data types and built ins, and • Frames. • Data Types • integer, boolean, string, date, • “Built-in” Predicates • numeric-greater-than, startswith, date-less-than • Functions • numeric-subtract, replace, hours-fromtime Logic and Rules

  49. An actor is a movie star if he has starred in more than 3 successful movies, produced in a span of at least 5 years. A film is considered successful if it has received critical acclaim (e.g. rating >8) or was financially successful (produced >$100M in ticket sales). These rules should be evaluated against the DBpedia data set. Logic and Rules

  50. RIF – use of frames • The use of frames has a long tradition in OO languages and knowledge representation, • Has also been prominent in rule languages (e.g. FLogic). • The basic idea is to represent objects as frames, and their properties as slots. • E.g., a class professor with slots name, office, phone, department etc. oid[slot1 -> value1 … slotn -> valuen] Logic and Rules