The Java Deductive Reasoning Engine for the Web
The Java Deductive Reasoning Engine for the Web 0 CS 6795 Semantic Web Techniques 22 -Sep-06
Train people to build the Rule-based web services l Courses on systems employing rule engines and Internet applications – – l Meier and Warren’s book: Programming in Logic, 1988 – – 1 Writing deduction engines in Java/C/C++ Interfacing with Internet API Old techniques (Prolog 30 years ago) New techniques from CADE System Competition Updated in Java? Specific to Prolog at low level CS 6795 Semantic Web Techniques 22 -Sep-06
Will such a course work? l No – – Guts of Prolog, Internet API’s, how to program in logic At least three courses here l Yes – – Students understand recursion How to build a tree how to search a space l – 2 Propositional theorem prover how to interface to Internet CS 6795 Semantic Web Techniques 22 -Sep-06
This talk l Architecture – – first order easily configured l – – – 3 forward or backward embedded supports calls to and from rest of system l Tour – for building deduction systems of internals backward & forward engines tree/proof terms bindings discrimination tree l Prototypes CS 6795 Semantic Web Techniques 22 -Sep-06
Choose the right abstractions l l Goal, Unifier, Proof. Tree use Java iterators: pay as you go – l Make every Goal responsible for its list of matching clauses – – l has. Next. Matching. Clause() attach. Next. Matching. Clause() Place Goals in stack of backtrack points – 4 for finding the next proof popped in reverse chronological order CS 6795 Semantic Web Techniques 22 -Sep-06
Propositional Prover initially proof. Tree has an open Goal loop if(proof. Tree. has. No. Open. Goal()) halt('success'); else Goal g = proof. Tree. select. Open. Goal(); g. create. Matching. Clause. List(); if(g. has. More. Matching. Clauses()) Definite. Clause c = g. next. Clause(); g. attach. Clause(c); choice. Points. push(g); else chronological. Backtrack(); 7 chronological. Backtrack while(choice. Points. non. Empty()) Goal g = choice. Points. pop(); g. remove. Attached. Clause(); if(g. has. More. Clauses()) return; halt('failure') Remove bindings Create bindings Java Iterator CS 6999 SWT Semantic Web Techniques
Tree with initial goal p(Z) p(X) : - q(X), r(X). q(g(X)). q(k). r(g(h)) ? : -p(Z) a p(Y 1) : - q(Y 1), r(Y 1) c b b’ q(g(Y 2)) r(g(h)) q(k) Choice. Points c b b’ Y 1/k Y 1/g(Y 2) a 8 CS 6795 Semantic Web Techniques Y 2/h Z/Y 1 22 -Sep-06
Moving to First Order Logic l Students struggle with variables – – – l Can we hide the hard stuff? – 9 Unification Composition of substitutions Unbinding on backtracking Powerful abstraction CS 6795 Semantic Web Techniques 22 -Sep-06
Shallow or deep variables? l Deep – – – variable binding is a list of replacements traverse list for each lookup undoing: remove most recent replacements {X f(Y)} {Y a} l Shallow – – 11 an array of (all) variables and their current values [X f(a) Y a …] undoing: pop stack of previous values (trail) CS 6795 Semantic Web Techniques 22 -Sep-06
Goal Tree and flatterms N p l l Each node has head and body atoms Body atoms form goals – l l 13 attach children resolved p 1 from d p 1, …, pm against q from q q 1, …, qn resolved pm against r . p 1 C pm D q q 1 CS 6795 Semantic Web Techniques r qn 22 -Sep-06
Flatterms to represent atoms l j-DREW uses flatterms – Array of pairs: l l – l l 14 symbol table ref length of subterm Not structure sharing Flatterms save theorem provers time and space (de Nivelle, 1999) Data transfer between deduction engine and rest of application CS 6795 Semantic Web Techniques 22 -Sep-06
Variables are clause-specific Variables use negative indexes l Bindings are references to flatterm & position l l 15 Unifier X g 2 Y f(g 2) W h(g 2) Z f(g 2) CS 6795 Semantic Web Techniques 22 -Sep-06
Composing and undoing Bindings l Local shallow bindings currently do not allow composition – – l Backtracking is integrated with unbinding – 16 bindings must be done to a flatterm new binding on a new flatterm for quick unbinding, we use a stack of flatterms for each goal. CS 6795 Semantic Web Techniques 22 -Sep-06
Discrimination trees l l Given a goal we want to access matching clauses quickly Every-argument addressing – l Useful for RDF triples – – 18 unlike Prolog’s first argument addressing a pattern may have variable in first argument rdf(X, ownedby, ‘Ora Lassila’) CS 6795 Semantic Web Techniques 22 -Sep-06
Discrimination trees l l l Given a goal, want to access input clauses with matching heads quickly Index into clauses via a structure built from heads Replace vars by * – l merge prefixes as much as possible • We added – 19 imperfect discrimination a tree arises p r f g 1 h h * g 2 h g 1 * p(f(g 1 ), h(g 2 ), g 1 ) p(f(h( X )), h(Y ), f(Z, Z)) CS 6795 Semantic Web Techniques q f * * 22 -Sep-06
Finding heads for goal p(X, h(g 2), Y) l replace vars in goal by * – l p * in goal, skip subtree • Find generalizations of goal –* in tree, skip term in goal g 1 h h * g 2 h g 1 * f • Find unifiable –combination of both 20 r f p(*, h(g 2), *) Find instances of goal – q * p(f(g 1 ), h(g 2 ), g 1 ) p(f(h( X )), h(Y ), f(Z, Z)) CS 6795 Semantic Web Techniques 22 -Sep-06
Iterator for matching clauses l l We use Java idioms where possible Java’s iterators give access to sequence – – l Used for access to sequence of matching clauses – 21 next() has. Next() used in discrimination tree for access to roots leaves of skipped tree (Mc. Cune’s term: jump-list) CS 6795 Semantic Web Techniques 22 -Sep-06
22 CS 6795 Semantic Web Techniques 22 -Sep-06
• Smoked. Salmon is the intersection of Smoked and Salmon Smoked Salmon 23 CS 6795 Semantic Web Techniques 22 -Sep-06
• Smoked. Salmon is the intersection of Smoked and Salmon Smoked Salmon • Gravalax is the intersection of Cured and Salmon, but not Smoked Gravalax 24 CS 6795 Semantic Web Techniques 22 -Sep-06
• Smoked. Salmon is the intersection of Smoked and Salmon Smoked Salmon • Gravalax is the intersection of Cured and Salmon, but not Smoked Lox • Lox is Smoked, Cured Salmon 25 Gravalax CS 6795 Semantic Web Techniques 22 -Sep-06
26 l A search for keywords Salmon and Cured should return pages that mention Gravalax, even if they don’t mention Salmon and Cured l A search for Salmon and Smoked will return pages with smoked salmon, should also return pages with Lox, but not Gravalax Smoked Salmon Lox Gravalax The Semantic Web vision is to make information on the web “understood” by computers, for searching, categorizing, … CS 6795 Semantic Web Techniques 22 -Sep-06
Smoked Salmon Lox Gravalax 27 CS 6795 Semantic Web Techniques 22 -Sep-06
One possible encoding Search criteria: retrieve(P) : about(P, cured), about(P, salmon). Ontology: about(P, cured) : about(P, gravalax). about(P, salmon) : about(P, gravalax). 28 A search for keywords Salmon and Cured should return pages that mention Gravalax, even if they don’t mention Salmon and Cured. about(p 1, gravalax). retrieve(p 1) succeeds CS 6795 Semantic Web Techniques 22 -Sep-06
retrieve(P) : about(P, smoked), about(P, salmon). 29 about(P, cured) : about(P, lox). about(P, salmon) : about(P, lox). about(P, smoked) : about(P, lox). about(P, cured) : about(P, gravalax). about(P, salmon) : about(P, gravalax). A search for Salmon and Smoked will return pages with smoked salmon, should also return pages with Lox, but not Gravalax. about(p 1, gravalax). about(p 2, lox). retrieve(p 1) fails retrieve(p 2) succeeds CS 6795 Semantic Web Techniques 22 -Sep-06
Working Prototypes: l Basic Prolog Engine – – Accepts Rule. ML, or Prolog, or mixture Iterator for instances of the top goal Main loop is same code as propositional theorem prover (shown earlier) Builds, displays deduction tree l – 30 available to rest of system Negation as failure CS 6795 Semantic Web Techniques 22 -Sep-06
More working prototypes: Variants of Top-Down Engine l User directed – – User selects goals User chooses clauses l – – iteratively increase bound every resolution in search space will eventually be tried a fair selection strategy Original variable names supplied – 31 Good teaching tool Bounded search – l keeps track of clauses still left to try particularly important for Rule. ML CS 6795 Semantic Web Techniques 22 -Sep-06
Bottom-Up / Forward Chaining l l l Set of support prover for definite clauses Facts are supports Theorem: Completeness preserved when definite clause resolutions are only between first negative literal and fact. – l l 35 Proof: completeness of lock resolution (Boyer’s Ph. D) Use standard search procedure to reduce redundant checking (next) Unlike OPS/Rete, returns proofs and uses first order syntax for atoms CS 6795 Semantic Web Techniques 22 -Sep-06
Theorem Prover’s Search Procedure l Priority – queue new facts l Discrimination trees: – – 36 used facts rules, indexed on first goal main loop select new fact for each matching rule resolve process new result add to old facts process new result(C) if C is rule for each old fact matching first goal resolve process new result add C to rules else add C to new facts CS 6795 Semantic Web Techniques 22 -Sep-06
Event – Condition - Action l Suppose theorem prover saturates – – may need datalog, subsumption Then a new fact is added from l l – adding a fact restarts saturation l l 37 push process Java event listener could generate new Java events ECA interaction with Java 1. 1 events CS 6795 Semantic Web Techniques 22 -Sep-06
j-DREW sound and complete l l Sound unification Search complete variant – – l Sound negation – – 38 fair search procedure rather than depth-first uses increasing bounds delay negation-as-failure subgoals until ground or until only NAF goals remain CS 6795 Semantic Web Techniques 22 -Sep-06
Related Work l j-DREW compared to Prolog – – j-DREW not compiled More flexible l l l – Performance requirements different l 39 Dynamic additions Web-ized Programmer’s API j-DREW unlikely to yield megalips CS 6795 Semantic Web Techniques 22 -Sep-06
Summary l Architecture – forward & backward l Backward: – – for Java-based reasoning engines variable binding/unbinding automatic tied with choicepoints configurable l Integrated with other Java APIs l Small footprint – Depolyed as thread, on server, on client, mobile l Dynamic – Integration of Rule. ML and Prolog rules in same proofs l Proofs 41 additions to rules available CS 6795 Semantic Web Techniques 22 -Sep-06
- Slides: 33