Post on 18-Aug-2015
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
PSOA2Prolog: Object-RelationalRule Interoperation and Implementation by
Translation from PSOA RuleML to ISO PrologThe 9th International Web Rule Symposium, RuleML 2015
August 2-5, 2015
Gen Zou Harold Boley
Faculty of Computer Science,University of New Brunswick, Fredericton, Canada
1 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
2 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
3 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Introduction
Paradigms of modeling knowledge in the Semantic Weband AI
Relational: FOL, PrologObject-centered: RDF, N3Combined
Heterogenous: F-logic, RIFHomogeneous: PSOA RuleML
In order to create a major interoperation path for PSOARuleML, we developed the PSOA2Prolog translator fromPSOA RuleML to a subset of the relational ISO PrologPSOA2Prolog is combined with XSB Prolog into thePSOATransRun[PSOA2Prolog, XSBProlog]implementation of PSOA RuleML
4 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
PSOA RuleML
Integrates relational and object-centered modelingGeneralizes F-logic, RIF-BLD, and POSLUses positional-slotted object-applicative (psoa) terms,permitting a relation application to have an OID – typed bythe relation – and, orthogonally, its arguments to bepositional or slotted.General case (multi-tuple):o#f([t1,1 ... t1,n1] ... [tm,1 ... tm,nm] p1->v1 ... pk->vk)
Special cases (single-tuple brackets and zero-argumentparentheses optional):Combined: o#f([t1 ... tn] p1->v1 ... pk->vk)Positional: o#f([t1 ... tn])Slotted: o#f( p1->v1 ... pk->vk)Member-only: o#f()
5 / 31
Startup Example in Presentation Syntax (PS)
KB:
Document (Group (
Forall ?X ?Y ?Z ?EX ?EY (_startup(?X ?Y _employee->?Z) :-
And(_cofounders(?X ?Y) _hire(?X ?Z)_equity(?X ?EX) _equity(?Y ?EY)External(
pred:numeric-less-than-or-equal(External(func:numeric-add(?EX ?EY)) 100)))
)
_cofounders(_Ernie _Tony) _hire(_Ernie _Kate)_equity(_Ernie 50) _equity(_Tony 30)_startup##_company
))
Query: _company(?X ?Y)Answer: ?X=_Ernie ?Y=_Tony
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
ISO Prolog
International standard of the widely used logicprogramming language PrologWe focus on the Horn subset of ISO Prolog, whichexcludes procedural features like negation-as-failure
7 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
8 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Normalization
ObjectificationSkolemizationSlotribution and TupributionFlatteningRule Splitting
9 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Objectification
Introduce an OID for each OID-less atomic psoa formulap(...)
For a formula in the KB:Ground fact_i#p(...), _i is a new KB constant, i = 1,2, ...Non-ground fact or in rule conclusionExists ?j (?j#p(...))In rule premise?j#p(...), where ?j is a new variable in the universalscope of the enclosing rule
For a formula in the query: Exists ?j (?j#p(...))
10 / 31
Startup Example (After Objectification)
KB:
Document (Group (Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 (Exists ?1 (?1#_startup(?X ?Y _employee->?Z)) :-
And(?2#_cofounders(?X ?Y) ?3#_hire(?X ?Z)?4#_equity(?X ?EX) ?5#_equity(?Y ?EY)External(
pred:numeric-less-than-or-equal(External(func:numeric-add(?EX ?EY)) 100)))
)_1#_cofounders(_Ernie _Tony) _2#_hire(_Ernie _Kate)_3#_equity(_Ernie 50) _4#_equity(_Tony 30)_startup##_company
))
Objectified Query:
Exists ?1 (?1#_company(?X ?Y))
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Skolemization
Specialized FOL Skolemization is employed to eliminateexistentials in rule conclusions or facts, which are notallowed in PrologReplace each existential formula Exists ?X (σ) in arule conclusion or a fact withσ[?X/_skolemk(?v1 ...?vm)], where each occurrenceof ?X in σ becomes a Skolem function _skolemk appliedto all universally quantified variables ?v1 ... ?vm fromthe clause’s quantifier prefix
12 / 31
Startup Example (After Skolemization)
Skolemized KB:
Document (Group (Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 (_skolem1(?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5)
#_startup(?X ?Y _employee->?Z) :-And(?2#_cofounders(?X ?Y) ?3#_hire(?X ?Z)
?4#_equity(?X ?EX) ?5#_equity(?Y ?EY)External(
pred:numeric-less-than-or-equal(External(func:numeric-add(?EX ?EY)) 100)))
)_1#_cofounders(_Ernie _Tony) _2#_hire(_Ernie _Kate)_3#_equity(_Ernie 50) _4#_equity(_Tony 30)_startup##_company
))
Query:
Exists ?1 (?1#_company(?X ?Y))
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Slotribution and Tupribution
Rewrite each psoa formulao#f([t1,1 ... t1,n1] ... [tm,1 ... tm,nm] p1->v1 ... pk->vk)
into a conjunctionAnd(o#f
o#Top(t1,1 ... t1,n1) ... o#Top(tm,1 ... tm,nm)o#Top(p1->v1) ... o#Top(pk->vk))
14 / 31
Startup Example (After Slotribution and Tupribution)
Document(Group (Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 (
And(_skolem1(?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5)#_startup_skolem1(...)#Top(?X ?Y)_skolem1(...)#Top(_employee->?Z)) :-
And(?2#_cofounders ?2#Top(?X ?Y) ?3#_hire ?3#Top(?X ?Z)?4#_equity ?4#Top(?X ?EX) ?5#_equity ?5#Top(?Y ?EY)External(
pred:numeric-less-than-or-equal(External(func:numeric-add(?EX ?EY)) 100)))
)
_1#_cofounders _1#Top(_Ernie _Tony)_2#_hire _2#Top(_Ernie _Kate)_3#_equity _3#Top(_Ernie 50)_4#_equity _4#Top(_Tony 30)_startup##_company
))
Slotributed/Tupributed Query:
Exists ?1 (And(?1#_company ?1#Top(?X ?Y)))
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Flattening
Extract embedded interpreted function application asseparate equalityEach atomic formula ϕ (in a rule premise or a query) thatembeds an external function application ψ, which is not onthe top level of an equality, is replaced withAnd(?i=ψ ϕ[ψ/?i]), where ?i is the first variable in ?1,?2, ... that does not occur in the enclosing rule
16 / 31
Startup Example (After Flattening)KB:
Document(Group (Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 ?6 (
And(_skolem1(?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5)#_startup_skolem1(...)#Top(?X ?Y)_skolem1(...)#Top(_employee->?Z)) :-
And(?2#_cofounders ?2#Top(?X ?Y) ?3#_hire ?3#Top(?X ?Z)?4#_equity ?4#Top(?X ?EX) ?5#_equity ?5#Top(?Y ?EY)And(?6=External(func:numeric-add(?EX ?EY))
External(pred:numeric-less-than-or-equal(?6 100)))))
_1#_cofounders _1#Top(_Ernie _Tony)_2#_hire _2#Top(_Ernie _Kate)_3#_equity _3#Top(_Ernie 50)_4#_equity _4#Top(_Tony 30)_startup##_company
))
Query:
Exists ?1 (And(?1#_company ?1#Top(?X ?Y)))
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Rule Splitting
Remove conjunctions in rule conclusions, which are notsupported in PrologEach rule with a conjunction in the conclusionForall ?v1 ... ?vm (And(ϕ1 ... ϕn) :- ϕ′)
is split into n rulesForall ?v1 ... ?vm (ϕ1 :- ϕ′)
...
Forall ?v1 ... ?vm (ϕn :- ϕ′)
18 / 31
Startup Example (After Rule Splitting)
KB:
Document(Group (Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 ?6 (_skolem1(?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5)#_startup :-And(?2#_cofounders ?2#Top(?X ?Y) ?3#_hire ?3#Top(?X ?Z)
?4#_equity ?4#Top(?X ?EX) ?5#_equity ?5#Top(?Y ?EY)And(?6=External(func:numeric-add(?EX ?EY))
External(pred:numeric-less-than-or-equal(?6 100))))Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 ?6 (_skolem1(...)#Top(?X ?Y) :- And(...)
)Forall ?X ?Y ?Z ?EX ?EY ?2 ?3 ?4 ?5 ?6 (_skolem1(...)#Top(_employee->?Z) :- And(...)
)_1#_cofounders _1#Top(_Ernie _Tony)_2#_hire _2#Top(_Ernie _Kate)_3#_equity _3#Top(_Ernie 50)_4#_equity _4#Top(_Tony 30)_startup##_company
))
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
20 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Constants and Variables
(Mapping function denoted by ρpsoa)Constants
If c is a number, ρpsoa(c) is the corresponding ProlognumberIf c is an arithmetic built-in, ρpsoa(c) is the correspondingProlog built-inOtherwise, ρpsoa(c) is the single-quoted version of c
VariablesFor a ‘?’-prefixed variable v , ρpsoa(v) replaces ‘?’ with theupper-case letter ‘Q’ (Question mark)
21 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Central PSOA Constructs
Table : Mapping from PSOA/PS constructs to Prolog constructs
PSOA/PS Constructs Prolog Constructso#Top(t1...tk) tupterm(ρpsoa(o), ρpsoa(t1) ... ρpsoa(tk))o#Top(p->v) sloterm(ρpsoa(o), ρpsoa(p), ρpsoa(v))
o#c() memterm(ρpsoa(o), ρpsoa(c))f(t1...tk) ρpsoa(f)(ρpsoa(t1), ... ,ρpsoa(tk))
And(f1 ... fn) (ρpsoa(f1) , ... , ρpsoa(fn))Or(f1 ... fn) (ρpsoa(f1) ; ... ; ρpsoa(fn))
Exists ?v1 ... ?vm (ϕ) ρpsoa(ϕ)Forall ?v1 ... ?vm (ϕ) ρpsoa(ϕ)
ϕ :- ψ ρpsoa(ϕ) :- ρpsoa(ψ).?v=External(f(t1...tk)) is(ρpsoa(?v), ρpsoa(f)(ρpsoa(t1), ... , ρpsoa(tk)))
c1##c2 memterm(X,ρpsoa(c2)) :- memterm(X,ρpsoa(c1)).
22 / 31
Mapped Startup Example
Translated KB:memterm(’_skolem1’(QX,QY,QZ,QEX,QEY,Q2,Q3,Q4,Q5),’_startup’) :-(((memterm(Q2,’_cofounders’),tupterm(Q2,QX,QY)),(memterm(Q3,’_hire’),tupterm(Q3,QX,QZ)),(memterm(Q4,’_equity’),tupterm(Q4,QX,QEX)),(memterm(Q5,’_equity’),tupterm(Q5,QY,QEY)),(is(Q0,’+’(QEX,QEY)),’=<’(Q0,100)))).
tupterm(’_skolem1’(...),QX,QY) :- (...).sloterm(’_skolem1’(...),’_employee’,QX) :- (...).memterm(’_1’,’_cofounders’). tupterm(’_1’,’_Ernie’,’_Tony’).memterm(’_2’,’_hire’). tupterm(’_2’,’_Ernie’,’_Kate’).memterm(’_3’,’_equity’). tupterm(’_3’,’_Ernie’,50).memterm(’_4’,’_equity’). tupterm(’_4’,’_Tony’,30).memterm(X,’_company’) :- memterm(X,’_startup’).
Translated Query:(memterm(Q1,’_company’),tupterm(Q1,QX,QY)).
Query Answer in Prolog:Q1=’_skolem1’(...), QX=’_Ernie’, QY=’_Tony’
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
24 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Realization
We implement PSOA2Prolog in Java based on ANTLR v3PSOA2Prolog is composed of a lexer, a parser, andmultiple tree walkers generated from ANTLR grammarsPSOA2Prolog and XSB Prolog are composed into theinstantiation PSOATransRun[PSOA2Prolog, XSBProlog] ofour PSOATransRun framework
25 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Evaluation
Compare with previous TPTP instantiationPSOATransRun[PSOA2TPTP,VampirePrime]First evaluation: a test suite of 30 test cases and 90queries, covering all PSOA features that we haveimplementedEach test case consists of one KB, multiple queries andone user-provided answer to each queryProlog instantiation passed all 30 test cases, while theTPTP instantiation failed on 10 test cases which containfeatures that it currently does not support: externalfunctions, subclass formulas, and IRI constants
26 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Evaluation
Second evaluation: size-parameterized test caseschain(k) for performance testingEach call of chain(k) generates a KB consisting of onefact _r0(_a1 _a2 _a3) and k rules of the formForall ?X ?Y ?Z (
_ri(?X ?Y ?Z) :- _ri ′(?X ?Y ?Z)), i = 1, . . . , k , i ′ = i − 1The query is _rk(?X ?Y ?Z), which has one answer?X=_a1 ?Y=_a2 ?Z=_a3
We measured the average query execution time of the twoinstantiations on ten test cases, starting with k = 20 andincreasing in steps of 20 rules until reaching k = 200
27 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Evaluation
Figure : Performance of PSOATransRun instantiations on chain(k)test cases
28 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Outline
1 Introduction and Background
2 Normalization of PSOA Source in Five Steps
3 Mapping the Normalized PSOA Source to Prolog
4 Realization and Evaluation
5 Summary and Future Work
29 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Summary
We realized PSOA2Prolog translator, which is composedof a five-step source-to-source normalizer followed by amapper to a pure (Horn) subset of ISO PrologPSOATransRun[PSOA2Prolog, XSBProlog] compositionprovides efficient query answering for PSOA RuleMLPSOATransRun[PSOA2Prolog, XSBProlog] outperformsour earlier PSOATransRun instantiation targeting TPTP onlarge test cases
30 / 31
Introduction and BackgroundNormalization of PSOA Source in Five Steps
Mapping the Normalized PSOA Source to PrologRealization and EvaluationSummary and Future Work
Future Work
Versions of PSOA2Prolog that implement equality foruser-defined functions and translate to an expanded set ofbuilt-insDetailed comparisons regarding the functionality andperformance of comparable subsets of PSOA RuleML and(1) ‘native’ ISO Prolog and (2) F-logicExploring further relational translation targets besidesTPTP and PrologRealizing translations between PSOA RuleML andobject-centered languages such as N3Studying subsets with interesting properties, e.g.function-free PSOA RuleML, and its connection toDatalog±
31 / 31