Title: Using answer set programming to answer complex queries
1Using answer set programming to answer complex
queries
- Chitta Baral
- (joint work with Michael Gelfond, Texas Tech U
and Richard Scherl, Monmouth U) - Arizona State University
- Tempe, AZ 85287
- chitta_at_asu.edu
- http//www.public.asu.edu/cbaral
2QUERIES
- Prediction, explanation, planning, cause,
counterfactual, etc.
3Queries and Answers
- Answering queries with respect to databases
various query languages - Relational databases SQL3
- Object-Oriented Databases OQL
- Web databases, XML Databases XML-QL
- Prolog queries
- Natural language queries
- Often translated to one of the above
- Complex Queries!
- Need knowledge beyond that is present in the
given data (or text) to answer. - Many can not be expressed in classical logics and
standard database query languages
4Complex Query example predictive query
- Text/Data John is at home in Boston and has not
bought a ticket to Paris yet. - Query
- What happens if John tries to fly to Paris?
- What happens if John buys a ticket to Paris and
then tries to fly to Paris? - Missing knowledge
- When can one fly? What is the result of flying?
5Complex Query example explanation query
- Text/Data On Dec 10th John is at home in Boston
and has not bought a ticket to Paris yet. On Dec
11th he is in Paris. - Query
- Explain what might have happened in between.
- Bought a ticket gone to the airport taken a
flight to Paris.
6Complex Query Example planning query
- Text/Data On Dec 10th John is at home in Boston
and has not bought a ticket to Paris yet. - Query What does John need to do to be in Paris
on Dec 11th. - He needs to buy the ticket get to the airport
fly to Paris.
7Complex Query ExampleCounterfactual Query
- Text/Data On Dec 10th John is at home in Boston.
He made a plan to get to Paris by Dec 11th. He
then bought a ticket. But on his way to the
airport he got stuck in the traffic. He did not
make it to the flight. - Query What if John had not gotten stuck in the
traffic?
8Complex Query Example query about narratives
- Text/Data John, who always carries his laptop
with him, took a flight from Boston to Paris on
the morning of Dec 11th. - Queries
- Where is John on the evening of Dec 11th?
- In which city is Johns laptop that evening?
9Complex Query Example Causal queries
- Text/Data On Dec 10th John is at home in Boston.
He made a plan to get to Paris by Dec 11th. He
then bought a ticket. But on his way to the
airport he got stuck in the traffic. He reached
the airport late and his flight had left. - Queries
- What are the causes of John missing the flight?
10Our approach to answer such queries
- Develop various knowledge modules in an
appropriate knowledge representation and
reasoning language. - Travel module (includes flying, driving)
- Geography Module
- Time module
- Reasoning about actions module
- Planning module
- Explanation module
- Counterfactual module
- Cause finding module
11Knowledge Representation and Reasoning
12What properties should an appropriate KR R
language have
- Should be non-monotonic. So that the system can
revise its earlier conclusion in light of new
information. - Should have the ability to represent normative
statements, exceptions, and default statements,
and should be able to reason with them. - Should be expressive enough to express and answer
problem solving queries such as planning queries,
counterfactual queries, explanation queries and
diagnostic queries. - Should have a simple and intuitive syntax so that
domain experts (who may be non-computer
scientists) can express knowledge using it. - Should have enough existing research (or building
block results) about this language so that one
does not have to start from scratch. - Should have interpreters or implementation of the
language so that one can indeed represent and
reason in this language. (I.e., it should not be
just a theoretical language.) - Should have existing applications that have been
built on this language so as to demonstrate the
feasibility that applications can be indeed built
using this language.
13AnsProlog a suitable knowledge representation
and reasoning language
- AnsProlog Programming in logic with answer sets
- Syntax Set of statements of the form
- A0 or or Ak ? B1, , Bm, not C1,
not Cn. - Intuitive meaning of the above statement
- If B1, , Bm is known to be true and C1, , Cn
can be assumed to be false then at least one of
A0 ,, Ak must be true. - Semantics
- A set of atoms A is an answer set of a program P
if A is the minimal model of the program PA
obtained by using A to remove all literals of the
form not C. - If C is in A then remove that rule and if C is
not in A then remove not C from that rules body - a ? not b b ? not a a a ?
14AnsProlog Program example illustrating
non-monotonicity
- T1 fly(X) ? bird(X), not ab(X).
- T2 bird(X) ? penguin(X).
- T3 ab(X) ? penguin(X).
- T4 bird(tweety).
- T1, T2, T3, T4 fly(tweety).
- T1, T2,T3, T4, penguin(tweety)
- fly(tweety).
15Transitive Closure in AnsProlog
- ancestor(X,Y) ? ancestor(X,Z), parent(Z,Y).
- ancestor(X,Y) ? parent(X,Y).
- parent(a,b).
- parent(b,c).
- parent(c,d).
- parent(e,f).
16Planning using AnsProlog
- initially f. initially g. b causes f
if g. a causes g. finally f. - ab is a plan that achieves the goal.
- Planning All answer sets encode a plan.
- Describing the initial state. holds(f,
1). holds(g, 1). - Describing effect of actions.
- holds(f,T1) ?occurs(b,T), holds(g,T).
- holds(g,T1) ?occurs(a,T).
- Describing what does not change.
- holds(f,T1) ?holds(f,T), not
holds(f,T1). - holds(f,T1) ?holds(f,T), not
holds(f,T1). - Enumerating possible plans.
- other-occurs(A,T) ?occurs(B,T), A \ B.
- occurs(A,T) ? not other-occurs(A,T).
- Eliminating answer sets which do not encode a
plan.
17AnsProlog vs Prolog
- Differences
- Prolog is sensitive to ordering of rules and
ordering of literals in the body of rules. - Inappropriate ordering leads to infinite loops.
(Thus Prolog is not declarative hence not a
knowledge representation language) - Prolog stumbles with recursion through negation
- No disjunction in the head (less power)
- Similarities For certain subclasses of AnsProlog
Prolog can be thought of as a top-down engine.
18AnsProlog vs other KR R languages
- AnsProlog has a simple syntax and semantics
- Syntax has structure that allows defining
sub-classes - More expressive than propositional and
first-order logic propositional AnsProlog is as
expressive as default logic. Yet much simpler. - It has the largest body of support structure
(theoretical results as well as implementations)
among the various knowledge representation
languages - Description logic comes close. But its focus is
very narrow, namely representing and reasoning
about ontologies. -
19Building blocks for AnsProlog
- Syntactic subclasses
- Definite, normal, extended, disjunctive.
- Acyclic, signed, stratified, call-consistent,
order-consistent. - Properties
- Existence of consistent answer sets.
- Existence of unique answer sets.
- Complexity of entailment.
- Expressibility of the entailment relation.
- Relation between the literals in an answer set
and the program
20Building blocks for AnsProlog- cont.
- Transforming programs.
- Equivalence of programs.
- Formal relation with other languages. (classical
logic, default logic, etc.) - Splitting programs modular analysis, and
computation of answer sets. - Systematic building of programs from components
program composition. - Compilation to propositional logic
-
21Examples of specific properties
- Expressibility
- Function-free AnsProlog without disjunctions P1P
(Co-NP) - Function-free AnsProlog P2 P.
- AnsProlog P11
- Relation between literals in an answer set and
the program. - If f is in an answer set A of a program P,
then there must be a rule in P such that - If an answer set A of a program P satisfies the
body of a rule r of P then, the head of that
rule
22Some existing AnsProlog applications
- Reasoning
- Reasoning with incomplete information, default
reasoning. - Reasoning with preferences and priorities,
inheritance hierarchies. - Declarative problem solving
- Planning, job-shop scheduling, tournament
scheduling. - Abductive reasoning, explanation generations,
diagnosis. - Combinatorial graph problems.
- Combinatorial optimizations, combinatorial
auctions. - Product configuration.
- Software Engineering Specification is the
program. (rapid prototyping)
23Illustration of Complex Query Answering
- John flying to Baghdad to meet Bob example.
24The extracted text and the queries
- Extracted Text
- John spent Dec 10 in Paris and took a plane to
Baghdad the next morning. He was planning to meet
Bob who was waiting for him there. - Queries
- Q1 Was John in the Middle East in mid-December?
- Q2 If so, did he meet Bob in the Middle East in
mid-December?
25Required background and common-sense knowledge
- Knowledge about geographical objects and their
hierarchy. (M1) - Baghdad is a city in Iraq. Iraq is a country in
the middle east region. - A city in a country in a region is a city in that
region. - Knowledge about travel events. (M2)
- If someone is in a city then she is in the
country where the city is in and so on. - Executability conditions and effect of travel
events - Inertia
- Duration of flying
- Knowledge about time units. (M3)
- Relation between various time granularities
- Knowledge about planned events, meeting events.
(M4) - People normally follow through their plans
- Executability condition of meeting events
26M1 The geography Module
- List of places
- is(baghdad,city).
- is(iraq,country).
- ...
- Relation between places
- in(baghdad, iraq).
- in(iraq,middle_east).
- in(paris,france).
- in(france,western_europe).
- in(western_europe,europe).
- ...
- Transitive closure
- in(P1,P3) ? in(P1,P2), in(P2,P3).
- Completeness assumption about in
- -in(P1,P2) ? not in(P1,P2)
27M2 The traveling module
- Based on theory of dynamic systems
- Views world as a transition diagram
- States are labeled by fluents
- Arcs labeled by actions
- Various types of traveling events
- instance_of(fly,travel).
- instance_of(drive,travel).
- Generic description of John flying to Baghdad
- event(a1).
- type(a1,fly).
- actor(a1,john).
- destination(a1,baghdad).
- Actual event is recorded as
- occurs(a1,i)
28M2 The traveling module (cont.)
- Representation of transition Diagram
- State Constraints
- loc(P2,X,T) ? loc(P1,X,T), in(P2,P1).
- disjoint(P1,P2) ? -in(P1,P2), -in(P2,P1),
neq(P1,P2). - -loc(P2,X,T) ? loc(P1,X,T),disjoint(P1,P2).
- Causal Laws
- loc(P,X,T1) ? occurs(E,T),
type(E,travel), actor(E,X),
destination(E,P), -interference(E,T). - -interference(E,T) ? not interference(E,T).
- Executability Conditions
- -occurs(E,T) ? cond(T).
- Inertia Rules (frame axioms)
- loc(P,X,T1) ? loc(P,X,T), not -loc(P,X,T1).
- -loc(P,X,T1) ? -loc(P,X,T), not loc(P,X,T1).
29Reasoning with M1 and M2
- Given
- loc(paris,john,0).
- loc(baghdad,bob,0).
- occurs(a1,0).
- And with M1 and M2 AnsProlog can conclude
- loc(baghdad,john,1), loc(baghdad,bob,1),
- loc(middle_east,john,1), -loc(paris,john,1)
30M3 Time and durations
- Duration of actions (additional ones needed for
month etc.) - time(T1,day,D) ? occurs(E,T), type(E,fly),
- time(T,day,D), not -time(T1,day,D).
- Basic measuring units
- day(1..31). month(1..12). part(start). part(end).
part(middle). - Rules translating between one granularity to
another - time(T,part,middle) ? time(T,d,D), 10 lt
D lt 20. - time(T,season,summer) ? time(T,month,M), 5 lt M
lt 9. - Missing elements from the module
- next(date(10,12,03),date(11,12,03)).
- next(date(31,12,03),date(1,1,04)).
31Reasoning with M1, M2 and M3
- Given information about Johns flight
- loc(paris,john,0).
- loc(baghdad,bob,0).
- occurs(a1,0).
- time(0,day,11).
- time(0,month,12).
- The query Q1
- ? loc(middle_east,john,T), time(T,month,12),
time(T,part,middle). - AnsProlog gives the correct answer yes with T
1.
32M4 planning to meet and meeting
- Describing the event meet
- event(a2). type(a2,meet).
- actor(a2,john). actor(a2,bob).
- place(a2,baghdad).
- Executability conditions of the meeting event
- -occurs(E,T) ? type(E,meet), actor(E,X),
place(E,P), -loc(P,X,T). - Planned meeting planned(a2,1).
- Planned actions and their occurrence People
normally follow their plans - occurs(E,T) ? planned(E,T), not -occurs(E).
- People persist with their plans until it happens
- planned(E,T1) ? planned(E,T), -occurs(E,T).
- Second query
- ? occurs(E,T), type(E,meet), actor(E,john),
actor(E,bob), loc(middle_east,john,T),
time(T,month,12), time(T,part,middle). - Answer Yes.
33Conclusion
- Answering complex queries need a lot of knowledge
and reasoning rules that are not present in the
text or data. - These reasoning rules and knowledge need to be
encoded as modules in an appropriate knowledge
representation and reasoning language.
34Ongoing and Future Work
- Further development of Modules (examples)
- Travel duration
- Time period representation issues (eg. time
zones) - Dealing with the case when a planned event fails
- Further development of the AnsProlog language
- Not good when dealing with time or similar
features that result in large instantiations. - Taking advantage of Prolog execution engine when
necessary - Necessity of set notations, aggregates etc.
35Acknowledgements
- Steve Maiorano, Jean-Michel Pomarede
- Ryan Weddle, Jicheng Zhao, Saadat Anwar, Luis
Tari (all from ASU), Greg Gelfond (from Texas
Tech University)