Object Oriented Rules and Inheritance - PowerPoint PPT Presentation

About This Presentation
Title:

Object Oriented Rules and Inheritance

Description:

Inheritance Candidates: quaker[policy]-nixon. republican[policy]-nixon. Inheritance Conflict: ... Candidates. Remove. Candidates. Applies user rules, as in CHR ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 71
Provided by: ces44
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Rules and Inheritance


1
Object Oriented Rules and Inheritance
  • Fabrício Teles Marcos Aurélio, August 2006

2
Outline
  • Purely Relational Rule Languages x Purely Object
    Oriented Languages
  • Hybrid Object Oriented Rule Languages
  • Inheritance Taxonomy
  • Yangs Inheritance Postulates
  • CHORD Extending CHR? with High-Order Object
    Oriented Constraints
  • Case Study Triangram

3
Knowledge Representation and Rule Based Languages
  • Strong points
  • provides built-in FOL deduction with negation as
    failure
  • the most powerful and versatile inference
    mechanism
  • with formal semantics
  • provides bases for implementation of other
    mechanisms like abduction, induction, planning,
    non-monotonic reasoning
  • uses rules that
  • are intuitive and modular
  • preserve the truth (detachment)
  • can be acquired by machine learning
  • Weak points
  • non-intuitive codification of the terminological
    and procedural knowledge
  • poor facility to structure complex entities
  • limitations of the tools and methodologies of
    distributed development on a large scale
  • poor standardization
  • few non-AI computational services, libraries
    available for reuse
  • limited interoperability with other languages

4
Knowledge Representation and Rule Based Languages
  • Rules often represent expert knowledge in a
    natural way (If...Then)
  • Rules represent modular knowledge

X
Y (? ? X) ? Y ? Y (? ? X) ? Y X
5
Knowledge Representation and Object Oriented
Languages
  • Strong points
  • intuitive codification of the terminological and
    procedural knowledge
  • facilities to structure complex entities
  • tools and methodologies of distributed
    development on a large scale consolidated and
    very spread out
  • API for the most varied computational services
    and languages
  • emphasis in the standardization, interoperability
    and reuse
  • Weak points
  • no built-in general purpose inference machine
  • any mechanism of inference beyond inheritance
    must be implemented from scratch
  • codifies behaviors procedurally
  • no techniques to learn objects from data
  • neither complete nor standard declarative formal
    semantics

6
Hybrid Object OrientedRule Languages
  • OO Requirements
  • Object identity
  • Complex Objects
  • Classes
  • Encapsulation
  • Inheritance
  • Overriding and Overloading
  • Reasoning Requirements
  • Declarative Language
  • Predicates with logical variables
  • Automatic deduction
  • Formal semantics
  • Computational completeness

Hybrid Rules Objects
7
Rules and objects how integrate?
Object Oriented Systems
Rule Based Systems
8
Integrating rules with objectssyntactic
alternatives
  • Hybrid system object oriented system in which
  • procedural methods of the classes are substituted
    by encapsulated rules bases, or
  • Hybrid system rule based system in which
  • instances of logical terms in the facts base are
    substituted by
  • objects instances of a hierarchy of classes
  • logical terms in the premises and conclusions of
    the rules are substituted by
  • object patterns with logical variables in the
    place of
  • object names and attribute values
  • possibly also name of classes and attributes

9
Substitute procedural methodsby encapsulated
rule bases
Classes Hierarchy
Object Base
10
Substitutefact base byobject base
11
F-Logic
  • Frame Logic is a deductive object oriented
    database language
  • Syntactical integration between Object Oriented
    Paradigm and Rules
  • Combines rules expressivity and declarative
    semantics with object oriented concepts.
  • Implements Structural and Behavioral Inheritance
    with support for Single-source Multiple
    Inheritance
  • Flora is an implementation for F-logic over XSB
    Prolog

12
Flora Metamodel
Sequential Transaction Frame Logic Programming
Frame Logic Programming
Sequential Transaction Logic Programming
General Logic Programming
Hilog Logic Programming
Definite Logic Programming
13
HiLog Metamodel
closure(R)(X,Y) - R(X,Y). closure(R)(X,Y) -
R(X,Z), closure(R)(Z,Y).
14
F-Logic Metamodel
john person, johnage -gt 31, johnchildren -gtgt
bob,mary
john personage -gt 31, children -gtgt bob,mary
15
F-Logic Metamodel
john.age 31, john..children bob,
john..children mary
16
F-Logic Metamodel
17
F-Logic Metamodel
18
F-Logic Metamodel
19
F-Logic Metamodel
20
F-Logic Metamodel
21
F-Logic Metamodel
22
F-Logic OO Concepts
23
F-Logic Program Example with Rules
Triangram Rules - Poligon Regularity
XirregularPolygon - Xtriangleside-gtgtS1,S2
and tnot(S1 S2) and S1.length \
S2.length. Xhypotenuse-gtHypotenuse -
Xtriangle and X..triangleSideposition-gtb
ase, side-gtBase and X..triangleSideposit
ion-gtleft, side-gtLeft and
X..triangleSideposition-gtright, side-gtRight
and if (Base.length gt Left.length and
Base.length gt Right.length) then
Hypotenuse Base else if Left.length
gt Right.length then Hypotenuse
Left else Hypotenuse
Right.
Triangram Rule Segment Adjacency
Sadjacent-gtgtX - XsegmentLine, Xadjacent-gtgtS.
24
Inheritance Taxonomy (1/4)
Inheritance
Structural
Behavioral
engineersalary(2009)?5000 ? johnengineer ? joh
nsalary(2009)?5000
flowerpetalColor?color ? mary
flower ? marypetalColor?color
code engineersalary(X)?V-VX2 ?
johnengineer ? johnsalary(X)?V-VX2
Values
Code
Signatures
Non-monotonic reasoning in FLORA-2, Kifer, 2005
25
Code Inheritance Example
  • Rules

R1 _at_ softDeptbonus()-gtB -
softDepttotal-gtT, B T 100. R2 _at_ code
softDeptbonus1()-gtB - softDepttotal-gtT, B
T 100.
?- johnbonus()-gtB.B 1000.
?- johnbonus1()-gtB.B 3000.
26
Inheritance Taxonomy (2/4)
class1att1?color ? class2att1?tree
? class2class1 ? objclass2att1?value ? value
color ? value tree
Inheritance
class1att1?color ? class2att1?integer
? class2class1 ? objclass2 ? objatt1?integer
Monotonic
Non-monotonic
27
Inheritance Taxonomy (3/4)
Inheritance
  • humanlegs?2 ? policehasGun?true ?
    shaftpolice ? shafthuman
  • ?
  • shaftlegs?2 ? shafthasGun?true

flowerpetalColor?color ? mary
flower ? marypetalColor?color
Simple
Multiple
quakerpolicy?pacifist ? republicanpolicy?paci
fist ? nixon quaker ? nixon republican
? nixonpolicy-gtpacifist
quakerpolicy?pacifist ? republicanpolicy?hawk
? nixon quaker ? nixon republican
? nixon.policy unknown
Single Source
Multiple Source
Source Based
Value Based
28
Inheritance Taxonomy (4/4)
Inheritance
elephantcolor?gray ? royalElephantcolor?whit
e ? royalElephant elephant ? clyde
royalElephant ? clydecolor?white
elephantcolor?gray ? royalElephantcolor?white
? royalElephant elephant ? clyde
royalElephant ? clydecolor?white ?
clydecolor?gray ? white gray
elephantcolor?gray ? royalElephantcolor?white
? royalElephant elephant ? clyde
royalElephant ? false
w/ Overriding
wo/ Overriding
29
Source x Value Based Multiple Inheritance
c1
  • Source-based c2..m and c3..m cancel each other
    regardless of the set of values
  • Value-based c2..m and c3..m do not cancel each
    other when they return the same set of values
    (since there is no real conflict)

30
Inheritance and Negation
  • Non-Monotonic Inheritance (NMI) is a form of
    default reasoning,
  • Thus, in order to provide semantics and implement
    inheritance we can reuse another form of default
    reasoning Negation As Failure (NAF)
  • F-Logic programs inheritance semantics reuses
    General Logic Programs' Well-Founded Semantics
    for NAF
  • Flora implements F-logic inheritance by reusing
    SLG resolution of XSB Prolog

31
Yangs Postulates
  • Embodies the common intuition behind
    non-monotonic multiple inheritance
  • An object model for some F-logic program is an
    interpretation for every F-atom under a
    three-valued semantics

32
Main Concepts
  • Inheritance Contexts
  • cm is an inheritance context for o if o is a
    member of class cand m?v is locally defined at c
    for some value v
  • Local context
  • sm is a local context if is a fact or if it is
    derived through some rule
  • Overriding
  • the inheritance context sm overrides cm for o
    if c?s and sc
  • Inheritance Candidates
  • cm is an inheritance candidate for o if it is
    an inheritance context which is not overriden by
    any other inheritance context
  • Inheritance Conflict
  • An inheritance conflict occurs when there is more
    than one inheritance candidate for inheriting
    some field m to o

33
Main Concepts
  • Each concept previously defined can be
  • Strong
  • Some concept is strong if all of its
    preconditions are true.
  • Weak
  • Some concept is weak if some of its
    preconditions is undefined.

34
Example
  • quakerpolicy?pacifist ? republicanpolicy?hawk
    ?
  • partypolicy-gtpacifist
  • quaker party ? republican party
  • nixon quaker ? nixon republican
  • __________________________________________________
    ______

35
Translation Schema
  • Transforms every FLP F into a GLP G such that
  • WFS(G) ? OptimisticObjectModel (F)
  • Two parts
  • Transformation rules, each one rewriting an FLP
    fragment into a corresponding GLP fragment
  • Trailer GLP rules, concatenated at the end of the
    transformation result

36
Translation Schema
37
Translation Schema Trailer Rules
38
XirregularPolygon - Xtriangleside-gtgtS1
length-gtL1, side-gtgtS2length-gtL12,
S1\S2, L1 \ L2.
isa(X,irregularPolygon) - isa(X,triangle),
mvd(X,side,S1), mvd(X,side,S2), fd(S1,length,
L1), fd(S2, length, L2), S1\S2, L1\L2.
39
CHORDExtending CHR? with High-Order Object
Oriented Constraints
40
CHORD Metamodel
41
Reusing Yangs Approach on CHORD
  • Translate the initial set of CHORD rules into a
    set of CHR rules, transforming each F-atom in
    some special CHR predicate
  • Attach some trailer rules implementing OO
    semantics

42
Current Implementation
  • Current implementation supports only
  • F-Atoms and conjunctive F-molecules
  • F-Atoms are only allowed as rule defined
    constraints

43
Trailer Rules
  • Alter normal CHR execution
  • insert inheritance steps between constraint
    simplification steps

Normal CHR
Constraint Simplification!
44
CHORD Runtime State Machine
Process Overriding
Constraint Simplification
Remove Candidates
Block Multiple-source Inheritance
Propagate Class Structure
Inherit Candidates
Propagate Inheritance Candidates
45
Example
  • GOAL
  • quakerpolicy?pacifist, republicanpolicy?
    hawk, count?7,
  • partypolicy-gtpacifist,
  • quaker party, republican party, nixon
    quaker, nixon republican

46
CHORD Runtime State Machine
CONSTRAINT STORE
quakerpolicy?pacifist, republicanpolicy?ha
wk, republicancount?7,
partypolicy-gtpacifist, quaker party,
republican party, nixon quaker, nixon
republican
Process Overriding
Constraint Simplification
Remove Candidates
Applies user rules, as in CHR? There are no rules
to fire
Block Multiple-source Inheritance
Propagate Class Structure
Inherit Candidates
Propagate Inheritance Candidates
47
CHORD Runtime State Machine
CONSTRAINT STORE quakerpolicy?paci
fist, republicanpolicy?hawk,
republicancount?7, partypolicy-gtpacifist,
quaker party, republican party,
nixon quaker, nixon republican nixon
party
Process Overriding
Constraint Simplification
Remove Candidates
Block Multiple-source Inheritance
Propagate Class Structure
Propagates class structures, i.e. ab, bc ?
ac
Inherit Candidates
Propagate Inheritance Candidates
48
CHORD Runtime State Machine
CONSTRAINT STORE quakerpolicy?paci
fist, republicanpolicy?hawk,
republicancount?7, partypolicy-gtpacifist,
quaker party, republican party,
nixon quaker, nixon republican nixon
party candidate_ifd(nixon,republican,count)
candidate_ifd(nixon,quaker,policy)
candidate_ifd(nixon,republican,policy)
candidate_ifd(nixon,party,policy)
candidate_ifd(republican,party,policy)
candidate_ifd(quaker,party,policy)
Process Overriding
Constraint Simplification
Remove Candidates
Block Multiple-source Inheritance
Propagate Class Structure
Calculate exhaustive list of inheritance
candidates, without taking overriding into
consideration
Inherit Candidates
Propagate Inheritance Candidates
49
CHORD Runtime State Machine
Removes overriden inheritance candidates
Process Overriding
Constraint Simplification
Remove Candidates
CONSTRAINT STORE quakerpolicy?pacifi
st, republicanpolicy?hawk,
republicancount?7, partypolicy-gtpacifist,
quaker party, republican party, nixon
quaker, nixon republican nixon
party candidate_ifd(nixon,republican,count) candid
ate_ifd(nixon,quaker,policy) candidate_ifd(nixon,r
epublican,policy) candidate_ifd(nixon,party,policy
) candidate_ifd(republican,party,policy) candidate
_ifd(quaker,party,policy)
Block Multiple-source Inheritance
Propagate Class Structure
Inherit Candidates
Propagate Inheritance Candidates
50
CHORD Runtime State Machine
Process Overriding
Constraint Simplification
Remove Candidates
CONSTRAINT STORE quakerpolicy?pacifist
, republicanpolicy?hawk, republicancount?7
, partypolicy-gtpacifist, quaker party,
republican party, nixon quaker, nixon
republican nixon party candidate_ifd(nixon,repu
blican,count) candidate_ifd(nixon,quaker,policy) c
andidate_ifd(nixon,republican,policy)
Block Multiple-source Inheritance
Propagate Class Structure
Removes inheritance Candidates causing multiple
inheritance conflicts
Inherit Candidates
Propagate Inheritance Candidates
51
CHORD Runtime State Machine
Process Overriding
Constraint Simplification
Remove Candidates
Block Multiple-source Inheritance
CONSTRAINT STORE quakerpolicy?pacifist,
republicanpolicy?hawk, republicancount?7,
partypolicy-gtpacifist, quaker party,
republican party, nixon quaker, nixon
republican nixon party nixoncount?7
Propagate Class Structure
Define remaining candidates as local Definitions
Inherit Candidates
Propagate Inheritance Candidates
52
CHORD Runtime State Machine
CONSTRAINT STORE quakerpolicy?pacifist,
republicanpolicy?hawk, republicancount?7,
partypolicy-gtpacifist, quaker party,
republican party, nixon quaker, nixon
republican nixon party nixoncount?7
Process Overriding
Constraint Simplification
Remove Candidates
Block Multiple-source Inheritance
Remove remaining intermediate helper constraints
Propagate Class Structure
Inherit Candidates
Propagate Inheritance Candidates
53
CHORD Runtime State Machine
  • Each state is associated to a sub-rule base
    associated with a part of the trailer
  • Constraint Simplification state is associated to
    user rules and goal
  • Since we can not control the order of the
    execution of the rules, we need some special
    strategy in order to implement state machines in
    CHR

54
Implementing State Machines in CHRD
  1. Associate each state to an unique constraint name

55
Implementing State Machines in CHRD
  • 2) Attach to each rule head of each state rule
    base the constraint associated to the state

Propagate Class Structure
XZ, ZY gt X ? Y XY. SC, OS gt
OC. OC, CMgtR gt OMgtR.
XZ, ZY, class_structure() gt X ? Y
XY. SC, OS, class_structure() gt
OC. OC, CMgtR, class_structure() gt
OMgtR.
56
Implementing State Machines in CHRD
  • 3) For each state rule base, add an
    simplification rule to simulate state
    transitions(this rule should be the last one in
    state rule base)

class_structure() ltgt propagate_candidates().
57
Implementing State Machines in CHRD
XZ, ZY, class_structure() gt X ? Y
XY. SC, OS, class_structure() gt
OC. OC, CMgtR, class_structure() gt
OMgtR. class_structure() ltgt
propagate_candidates().
58
Case Study Triangram
59
Case Study - Triangram
  • Simplification of the known Chinese game, the
    Tangram
  • Tangram
  • form complex figures using only 7 geometric 2D
    figures, without having overlapping between them
  • It considers only the following types of
    different parts
  • 5 isosceles triangles (2 small ones, 1 medium and
    2 great ones)
  • 1 square
  • 1 parallelogram

60
Case Study - Triangram
  • Exemplo Tangram

61
Case Study - Triangram
  • Triangram
  • Basic parts are only of a type triangles
  • Uses three types of triangles

62
Case Study - Triangram
  • Triangram
  • The objective is to form geometric figures from
    the basic types of triangles
  • It's only allowed to form a restricted number of
    types of figures the straight hexagons,
    pentagons and the quadrilaterals

63
Case Study - Triangram
  • UML/OCL
  • Representation of the world convex polygons

64
Case Study - Triangram
  • UML/OCL
  • Representation of the world triangle

65
Case Study - Triangram
  • Implementation
  • 28 CHORD rules
  • The largest one has 19 contraints on its head
  • About 125 constraints on goal
  • Average instances of the problem last about 1h to
    run

66
Case Study - Triangram
  • Implementation
  • Goal
  • Scenary being tested
  • Class hierarchy
  • Classes signatures
  • Rules
  • Invariants
  • Methods
  • Query ? propagation rules with the F-Atom of the
    method in the body of the rule and pre-conditions
    in the head
  • Transactional ? simpagation rules with
    pre-conditions in the head, removals in
    simplificateHead and pos-conditions in the body

67
Case Study - Triangram
CHORD Implementation - Goal
main() ltgt true ...
Class Hierarchy
scaleneTriangletriangle, isoscelesTriangletr
iangle, equilateralTriangleisoscelesTriangle,
...
Scenary being tested
tri1 equilateralTriangle side -gtgt s11
adjacent -gtgt s12, adjacent -gtgt s13,
length -gt 3 , ... , ...
Class signatures
triangleside gtgt segmentLine,
triangleSide gtgt triangleSide,
hypotenuse gt segmentLine, ...
68
Case Study - Triangram
Invariants
... XsegmentLineadjacent-gtgtS gt true
SsegmentLineadjacent-gtgtX. Xtriangle,
Xside-gtgtS1, Xside-gtgtS2, S1length-gtL1,
S2length-gtL2 gt ne(S1,S2), L1 L2
XregularPolygon. ...
69
Case Study - Triangram
Query Methods
... Pol1 rectangle side -gtgt SidePol1 length
-gt L, adjacent -gtgt A1 length -gt LA1
, parts -gtgt P1, parts -gtgt P2 , Pol2
isoscelesTriangle triangleSide -gtgt
TS1 side -gt SidePol2 length
-gt L, adjacent -gtgt A2
length -gt LA1 , position -gt base
gt ne(P1,Pol2), ne(P2,Pol2)
Pol1isCompatible(Pol2, SidePol1,
SidePol2)-gtvoid. ...
70
Case Study - Triangram
Transactional Methods
... Pol11triangleisCompatible(Pol2, SidePol1,
SidePol2)-gtvoid, Pol2 triangle,
... \ A11adjacent -gtgt SidePol1, A12adjacent
-gtgt SidePol1, A21adjacent -gtgt SidePol2,
A22adjacent -gtgt SidePol2 gt A11 ! A12, A21
! A22 A11adjacent -gtgt A22, A12adjacent -gtgt
A21, A21adjacent -gtgt A12, A22adjacent -gtgt
A11, Pol3 rectangleside -gtgt
A11,A12,A21,A22, parts -gtgt
Pol1,Pol2, ...
Write a Comment
User Comments (0)
About PowerShow.com