outline logistics (project) & review first order predicate calculus relational algebra datalog...
TRANSCRIPT
![Page 1: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/1.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 2: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/2.jpg)
Softbot = Software Robot[Etzioni AI Mag93]
cgi invocationdb update
• Effectors• Planning-Based Control
– High-Level Goals…
– Increased Autonomy
httpfinger
• Sensors
![Page 3: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/3.jpg)
The Tuple Extraction Problem
• WWW Sources Formatted for People
• Softbot wants relational information
These movies now showing:
The Rock 7:20 Great! Vertigo 9:30 Classic!Star Trek 7:30 Beam me up
Bookmark Me Now!Thanks!
N
<The Rock, 7:20> <Vertigo, 9:30><Star Trek, 7:30>
?
[Kushmerick 97]
![Page 4: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/4.jpg)
HTML Source
<HTML><TITLE>Showtimes</TITLE><BODY><B>Now Showing:</B> <P><B>The Rock</B> <I>7:20</I>Great!<BR><B>Vertigo</B> <I>9:30</I>Classic<BR><B>Star Trek</B> <I>7:30</I>Beam me up<BR><HR> Bookmark me now! <BR><B>Thanks!</B></BODY></HTML>
![Page 5: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/5.jpg)
Note the Movie Names….
<HTML><TITLE>Showtimes</TITLE><BODY><B>Now Showing:</B> <P><B>The Rock</B> <I>7:20</I>Great!<BR><B>Vertigo</B> <I>9:30</I>Classic<BR><B>Star Trek</B> <I>7:30</I>Beam me up<BR><HR> Bookmark me now! <BR><B>Thanks!</B></BODY></HTML>
![Page 6: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/6.jpg)
Surrounded by <B> and </B>
<HTML><TITLE>Showtimes</TITLE><BODY><B>Now Showing:</B> <P><B>The Rock</B> <I>7:20</I>Great!<BR><B>Vertigo</B> <I>9:30</I>Classic<BR><B>Star Trek</B> <I>7:30</I>Beam me up<BR><HR> Bookmark me now! <BR><B>Thanks!</B></BODY></HTML>
![Page 7: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/7.jpg)
Similarly, Showtimes by <I>, </I>
<HTML><TITLE>Showtimes</TITLE><BODY><B>Now Showing:</B> <P><B>The Rock</B> <I>7:20</I>Great!<BR><B>Vertigo</B> <I>9:30</I>Classic<BR><B>Star Trek</B> <I>7:30</I>Beam me up<BR><HR> Bookmark me now! <BR><B>Thanks!</B></BODY></HTML>
![Page 8: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/8.jpg)
A Wrapper
ExtractMovieTimes Tuples := {} While P not empty do: Skip forward to <B> Title := ExtractTextUntilNext( </B> ) Skip forward to <I> Time := ExtractTextUntilNext( </I> ) Push (Title, Time) onto Tuples Return Tuples
![Page 9: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/9.jpg)
Project
• (5/7) Select Information Sources– Movie domain– We supply an ontology– You provide Datalog source descriptions
• (5/14) Write Wrappers (Class to share)– Each one subclasses Java wrapper class– Regular expression package
• (6/11) Complete Information Integration Softbot
![Page 10: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/10.jpg)
Course Topics by Week• Search & Constraint Satisfaction
• Knowledge Representation 1: Propositional Logic• Autonomous Spacecraft 1: Configuration Mgmt
• Autonomous Spacecraft 2: Reactive Planning• Information Integration 1: Knowledge Representation
• Information Integration 2: Planning & Execution• Supervised Learning & Datamining
• Reinforcement Learning
• Bayes Nets: Inference & Learning
• Review & Future Forecast
![Page 11: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/11.jpg)
Knowledge Representation
Propositional Logic
Relational Algebra
Datalog
First-Order Predicate Calculus
Bayes NetworksDescription
Logic(s)
![Page 12: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/12.jpg)
Reasoning Algorithms
• Tasks– Satisfiability– Entailment
• Approach– Systematic (e.g. DPLL)– Stochastic (e.g. GSAT)
• Properties– Soundness – Completeness– Complexity
![Page 13: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/13.jpg)
13
Summary: Propositional Logic• Syntax
– Prop variables: P, Q, …
– Connectives: and, or, not, =>, =
• Semantics– Truth Tables
• Inference
– Modus Ponens
– Resolution
• Complexity: – NPC
P Q, P
Q
P Q, P R
Q R
![Page 14: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/14.jpg)
14
Propositional. Logic vs First Order
Ontology
Syntax
Semantics
Inference
Facts: P, Q
Atomic sentencesConnectives
Truth Tables
NPC, but SAT algos work well
Objects (e.g. Dan)Properties (e.g. mother-of)Relations (e.g. female)Variables & quantificationSentences have structure: termsfemale(mother-of(X)))
Interpretations (Much more complicated)
Undecidable, but theorem proving works sometimesLook for tractable subsets
![Page 15: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/15.jpg)
15
Definitions• Constants: a,b, dog33.
– Name a specific object.
• Variables: X, Y. – Refer to an object without naming it.
• Functions: father-of– Mapping from objects to objects.
• Terms: father-of(father-of(dog33))– Refer to objects
• Atomic Sentences: in(father-of(dog33), food6)– Can be true or false
– Correspond to propositional symbols P, Q
![Page 16: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/16.jpg)
16
More Definitions• Logical connectives: and, or, not, =>• Quantifiers:
– For all – There exists
• Examples– Dumbo is grey
– Elephants are grey
– There is a grey elephant
![Page 17: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/17.jpg)
Interaction of quant + connective
x E(x) G(x)
x E(x) G(x)
x E(x) G(x)
x E(x) G(x)
E(x) == “x is an elephant”G(x) == “x has the color grey”
![Page 18: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/18.jpg)
Nested Quantifiers: Order matters!
• Examples– Every dog has a tail
– Someone is loved by everyone
x y P(x,y) yx P(x,y)
![Page 19: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/19.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 20: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/20.jpg)
Today’s KR Sequence
Propositional Logic
Relational Algebra = Datalog without recursion
Datalog
First-Order Predicate Calculus
1
2
3
4
![Page 21: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/21.jpg)
Terminology
Name Price Category Manufacturer
gizmo $19.99 gadgets GizmoWorks
Power gizmo $29.99 gadgets GizmoWorks
SingleTouch $149.99 photography Canon
MultiTouch $203.99 household Hitachi
Tuples
Attribute namesProduct
Product(name, price, category, manufacturer)
(Arity=4)
![Page 22: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/22.jpg)
More Terminology
Every attribute has an atomic type.
Relation Schema: relation name + attribute names + attribute types
Relation instance: a set of tuples. Only one copy of any tuple! (not)
Database Schema: a set of relation schemas.
Database instance: a relation instance for every relation in the schema.
![Page 23: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/23.jpg)
More on Tuples
Formally, a mapping from attribute names to (correctly typed) values:
name gizmo price $19.99 category gadgets manufacturer GizmoWorks
Sometimes we refer to a tuple by itself: (note order of attributes))
(gizmo, $19.99, gadgets, GizmoWorks) or
Product (gizmo, $19.99, gadgets, GizmoWorks).
![Page 24: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/24.jpg)
Integrity Constraints
An important functionality of a DBMS is to enable the specificationof integrity constraints and to enforce them.
Knowledge of integrity constraints is also useful for query planning and optimization.
Examples of constraints:
keys, superkeys foreign keys domain constraints, tuple constraints. Functional dependencies, multivalued dependencies.
![Page 25: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/25.jpg)
KeysA minimal set of attributes that uniquely identify the tuple (I.e., there is no pair of tuples with the same values for the key attributes):
Person: social security number name name + address name + address + age
Perfect keys are often hard to find, but organizations usuallyinvent something anyway.Superkey: a set of attributes that contains a key.A relation may have multiple keys, but only one primary key
employee number, social-security number
Movies?
![Page 26: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/26.jpg)
Foreign Key Constraints
Purchase:
buyer price product
Joe $20 gizmo Jack $20 E-gizmo
Product:
name manufacturer description
gizmo G-sym great stuffE-gizmo G-sym even better
An attribute of a relation R is must refer to a key of a relation S.
![Page 27: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/27.jpg)
Functional Dependencies
Definition:
If two tuples agree on the attributes
A , A , … A 1 2 n
then they must also agree on the attributes
B , B , … B 1 2 m
Formally:
A , A , … A 1 2 n
B , B , … B 1 2 m
Key of a relation: all the attributes are either on the left or right.
![Page 28: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/28.jpg)
Relational Algebra• Operators: tuple sets as input, new set as output • Basic Binary Set Operators
– Result is table (set) with same attributes• Sets must be compatible!
– R1(A1,A2,A3) R2(B1,B2,B3) Domain(Ai) = Domain(Bi)
– Union• All tuples in either R1 or in R2
– Intersection• All tuples in both R1 and R2
– Difference• All tuples in R1 but not in R2
– Complement - what’s the universe?• Selection, Projection, Cartesian Product, Join
![Page 29: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/29.jpg)
Selection
• Grab a subset of the tuples in a relation that satisfy a given condition– Use and, or, not, >, <… to build condition
• Unary operation… returns set with same attributes, but ‘selects’ rows
![Page 30: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/30.jpg)
EmployeeSSN Name DepartmentID Salary999999999 John 1 30,000777777777 Tony 1 32,000888888888 Alice 2 45,000
Selection Example
SSN Name DepartmentID Salary888888888 Alice 2 45,000
Select DepartmentID = 2
![Page 31: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/31.jpg)
Projection
• Unary operation, selects columns
• Returned schema is different, – so returned tuples are not subset of original set– Contrast with selection
• Eliminates duplicate tuples
![Page 32: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/32.jpg)
Example: Projection Onto SSN, Name
EmployeeSSN Name DepartmentID Salary999999999 John 1 30,000777777777 Tony 1 32,000888888888 Alice 2 45,000
SSN Name999999999 John777777777 Tony888888888 Alice
![Page 33: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/33.jpg)
Cartesian Product
• Binary Operation
• Result is set of tuples combining all elements of R1 with all elements of R2, for R1 R2
• Schema is union of Schema(R1) & Schema(R2)
• Notice we could do selection on result to get meaningful info!
![Page 34: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/34.jpg)
EmployeeName SSNJohn 999999999Tony 777777777DependentsEmployeeSSN Dname999999999 Emily777777777 Joe
Employee_DependentsName SSN EmployeeSSN DnameJohn 999999999 999999999 EmilyJohn 999999999 777777777 JoeTony 777777777 999999999 EmilyTony 777777777 777777777 Joe
Cartesian Product Example
![Page 35: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/35.jpg)
Join• Most often used…
• Combines 2 relations, selecting only related tuples
• Equivalent to a cross product followed by selection
• Resulting schema has all attributes of the two relations, but one copy of join condition attributes
![Page 36: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/36.jpg)
Join Example
EmployeeName SSNJohn 999999999Tony 777777777
DependentsEmployeeSSN Dname999999999 Emily777777777 Joe
Employee_DependentsName SSN DnameJohn 999999999 EmilyTony 777777777 Joe
![Page 37: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/37.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 38: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/38.jpg)
Logic Based Query Languages
• Datalog:– Subset of First Order Predicate Calculus
• Function Free• Restricted to Horn Clauses
• More Powerful than relational algebra– Enables expressing recursive queries– More convenient for analysis
• Without recursion (but with negation) it is – Equivalent in power to relational algebra
![Page 39: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/39.jpg)
Datalog Concepts
• Atoms• Datalog rules, datalog programs• EDB predicates, IDB predicates • Conjunctive queries• Recursion• Built-in predicates• Negated atoms, stratified programs.• Semantics: least fixpoint.
![Page 40: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/40.jpg)
Predicates and Atoms
- Relations are represented by predicates- Tuples are represented by atoms.
Purchase( “joe”, “bob”, “Nike Town”, “Nike Air”, 2/2/98)
- arithmetic: built-in relations:
X < 100, X+Y+5 > Z/2
- negated atoms:
NOT Product(“Brooklyn Bridge”, $100, “Microsoft”)
Just
like i
n
First-O
rder
Pre
dica
te Calc
ulus
![Page 41: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/41.jpg)
Datalog Rules and QueriesA pure datalog rule (e.g. first-order horn clause with a positive literal)has the following form:
head :- atom1, atom2, …., atom,… where all the atoms are non-negated and relational.
BritishProduct(X) :- Product(X,Y,P) & Company(P, “UK”, SP)
A datalog program is a set of datalog rules.A program with a single rule is a conjunctive query.
We distinguish EDB predicates and IDB predicates• EDB’s are stored in the database, appear only in the bodies• IDB’s are intensionally defined, appear in both bodies and heads.
![Page 42: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/42.jpg)
Correspondence: Datalog ~ Relational Algebra
EmployeeName SSNJohn 999999999Tony 777777777DependentsEmployeeSSN Dname999999999 Emily777777777 Joe
ED(Name, SSN, Dname) :- Employee(Name, SSN) & Dependents(SSN, Dname)
EDName SSN DnameJohn 999999999 EmilyTony 777777777 Joe
Given: EDBs
Define: IDB
![Page 43: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/43.jpg)
The Meaning of Datalog Rules
Repeat the following until you cannot derive any new facts:Consider every assignment from the variables in the bodyto the constants in the database.
If each of the atoms in the body is made true by the assignment,
then
add the tuple for the head into the relation of the head.
Start with the facts in the EDB and iteratively derive facts for IDBs.
![Page 44: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/44.jpg)
Transitive Closure
Suppose we are representing a graph by a relation Edge(X,Y):
Edge(a,b), Edge (a,c), Edge(b,d), Edge(c,d), Edge(d,e)
a
b
c
d e
I want to express the query:
Find all nodes reachable from a.
![Page 45: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/45.jpg)
Recursion in DatalogPath( X, Y ) :- Edge( X, Y )Path( X, Y ) :- Path( X, Z ), Path( Z, Y ).
Semantics: evaluate the rules until a fixedpoint:Iteration #0: Edge: {(a,b), (a,c), (b,d), (c,d), (d,e)}
Path: {}
Iteration #1: Path: {(a,b), (a,c), (b,d), (c,d), (d,e)}
Iteration #2: Path gets the new tuples: (a,d), (b,e), (c,e)
Iteration #3: Path gets the new tuple: (a,e)
Iteration #4: Nothing changes -> We stop.Note: number of iterations depends on the data. Cannot be anticipated by only looking at the query!
a
b
c
d e
![Page 46: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/46.jpg)
Built in PredicatesRules may include atoms with built-in predicates:
ExpensiveProduct(X) :- Product(X,Y,P) & P > $100
But: we need to restrict the use of built-in atoms in rules.
P(X) :- R(X) & X<Y
What does this mean?
Hence, we require that every variable that appears in a built-inatom also appears in a relational atom.
![Page 47: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/47.jpg)
Negated SubgoalsRules may include negated subgoals, but in restricted forms:
Ok:P(X,Y) :- Between(X,Y,Z) & NOT Direct(X,Z)
Bad: Q(X, Y) :- R(X) & NOT S(Y)
Bad but salvagable: T(X) :- R(X) & NOT S(X,Y)
We’ll rewrite as: S’(X) :- S(X,Y) T(X) :- R(X) & NOT S’(X)
![Page 48: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/48.jpg)
Stratified Negation is Ok
A predicate P depends on a predicate Q if: Q appears negated in a rule defining P.
If there is a cycle in the dependency graph, the datalog programis not stratified.
Example:
p(X) :- r(X) & NOT q(X)q(X) :- r(X) & NOT p(X)
Suppose r has the tuple {1}What is the fixed point?
![Page 49: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/49.jpg)
Subtleties with Stratified Rules
Example:
p(X) :- r(X) q(X) :- s(X) & NOT p(X).
Suppose: r = {1}, and s = {1,2}
One solution: p = {1} and q = {2}
Another solution: p={1,2} and q={}.
Perfect model semantics: apply the rules stratum after stratum.
q
p
![Page 50: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/50.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 51: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/51.jpg)
Motivation: Info Integration
• Want agent such that
• User says what she wants
• Softbot determines how & when to achieve it
• Example:– Show me all reviews of movies starring Marlon
Brando that are currently playing in Seattle
Ebert
IMDB Spot
ShowT
![Page 52: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/52.jpg)
User must know which sites have relevant info
User must go to each one in turnSlow: Sequential access takes time
Confusing: Each site has a different interface
User must manually integrate information
Problems
Before your softbot can solve these problems it must be able to perceive WWW content...
![Page 53: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/53.jpg)
Information Integration
Planner
Pruner
Executor
plan
stream
exec
graph
Query
Tuples
InfoSourceModels
sourcecapabilities
localcomplete
wrappers
InfoSource
InfoSource
InfoSource
Optimizer
![Page 54: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/54.jpg)
Representation I• World Ontology
– Defines predicates of relational schemata– E.g.,
• actor-in (Movie, Part, Name), • review-of (Movie, Part) • year-of (Movie, Year)• shows-in (Movie, City, Theatre)
– User uses this language to specify queries– You use language to specify content of info sites
![Page 55: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/55.jpg)
:- vs. vs.
Representation II: • Queries
Find-all (M, Review, brando, seattle)Such That actor-in(M, Part, brando) &
shows-in(M, seattle, T) &review-of(M, Review)
• Writen in Datalog:
query(M, R, Brando, Seattle) :- actor-in(M, Part, brando) &shows-in(M, seattle, T) &review-of(M, R)
![Page 56: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/56.jpg)
Representation II• Information Source Functionality
– Info Required? $ Binding Patterns
– Info Returned?
– Mapping to World Ontology
Source may be incomplete: (not )
IMDBActor($Actor, M) actor-in(M, Part, Actor)
Spot($M, Rev, Y) review-of(M, Rev) &year-of(M, Y)
Sidewalk($C, M, Th) shows-in(M, C, Th)
•For Example
[Rajaraman95]
![Page 57: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/57.jpg)
A Plan to Solve the Query
IMDBActor($Actor, M) actor-in(M, Part, Actor) Spot($M, Rev, Y) review-of(M, Rev) &
year-of(M, Y)Sidewalk($C, M, Th) shows-in(M, C, Th)
• How verify plan answers query?
• How find this solution?
query(M, R, Brando, Seattle) actor-in(M, Part, brando) &shows-in(M, seattle, T) &review-of(M, R)
plan(M, R, Brando, Seattle) IMDBActor(brando, M) & Sidewalk(seattle, M, Th) & Spot(M, Rev, Y)
![Page 58: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/58.jpg)
Two Questions
• How verify this plan answers query?1. Verify information content of plan
• Same as DB problem of rewriting queries using views
• Show expansion of plan equivalent to query
• Technique of query containment
2. Verifying binding pattern constraints
• How find a valid solution plans?– Search...– Search-free synthesis of maximal recursive plan
![Page 59: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/59.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 60: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/60.jpg)
Query Containment
• Containment– q1 q2 iff q1(D) q2(D) for every database
instance, D
• Equivalence– q1 q2 iff q1 q2 and q2 q1
• Satisfiability– q is satisfiable if D such that q(D)
Let q1, q2 be datalog rulesE.g. q1(X) :- p(X) & r(X)
![Page 61: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/61.jpg)
Motivation
• Removing redundant subgoals• Detecting independence of queries from update• Knowledge Base verification• Semantic caching• Reusing views (results of previous queries)
– Internet Information Integration Softbots
![Page 62: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/62.jpg)
Perspective from Logic
• Containment a special form of validity
Givenq1(A, D) :- p(A, B) & r(C, D)q2(A, D) :- p(A, B) & r(B, D)
q1 q2 is equivalent to saying the next sentence is valid:
A, D ( B p(A, B) r(B, D)) => ( B,C p(A, B) r(C, D))
![Page 63: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/63.jpg)
(p(A, B)) = p(E, G)
(r(C, D)) = r(G, F)
• q1 contains q2 iff : vars(q1) -> vars(q2) s.t. literals L body(q1), (L) body(q2) – (head(q1)) = head(q2)
• For example– Q1: q(A, D) :- p(A, B) & r(C, D)– Q2: q(E, F) :- p(E, G) & r(G, F) & s(E, F)– : A -> E D -> F B -> G
C -> G
Containment Mappings[Chandra & Merlin 77]
![Page 64: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/64.jpg)
Computing Containment
• To show q1 contains q2
• Search ...– Space of possible containment mappings
– Incrementally verify: literals L body(q1), • literal L’ body(q2) such that (L)=L’
• NP-complete for pure conjunctive queries
• “Works” for unions of conjunctive queries
![Page 65: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/65.jpg)
Reusing Materialized Viewsq (A, E) :- r(A, B) & r(B, C) & s(C, D) & s(D, E)
Suppose all we have are results of previous queries:v(F, G) :- r(F, H) & r(H, G) & s(G, I)
u(J, K) :- r(M, J) & s(J, N) & s(N, K)Can we still answer q?
Yes! q'(X, Y) :- v(X, Z) & u(Z, Y)
Let q” denote expansion of q’q”(X, Y) :- r(X, H) & r(H, Y) & s(Y, I) &
r(M, Z) & s(Z, N) & s(N, Y)Equivalence chain: q q” q’I.e. prove q q’ q” q
![Page 66: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/66.jpg)
I Y H
q q”q (A, E) :- r(A, B) & r(B, C) & s(C, D) & s(D, E)
q”(X, Y) :- r(X, H) & r(H, Y) & s(Y, I) & r(M, Z) & s(Z, N) & s(I, Y)
: A -> X B ->C ->D ->E -> Y
![Page 67: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/67.jpg)
Back to Information Integration
• How verify this plan answers query?1. Verify information content of plan
• Same as DB problem of rewriting queries using views• Show expansion of plan equivalent to query• Technique of query containment
2. Verifying binding pattern constraints
• How find a valid solution plans?– Search...– Search-free synthesis of maximal recursive plan
![Page 68: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/68.jpg)
A Plan to Solve the Query
IMDBActor($Actor, M) actor-in(M, Part, Actor) Spot($M, Rev, Y) review-of(M, Rev) &
year-of(M, Y)Sidewalk($C, M, Th) shows-in(M, C, Th)
query(M, R, b, s) actor-in(M, Part, b) &shows-in(M, s, T) &review-of(M, R)
plan(M, R, b, s) IMDBActor(b, M) &Sidewalk(s, M, Th) &Spot(M, R, Y)
plan'(M, R, b, s) actor-in(M, P, A) & review-of(M, R) & year-of(M, Y) & shows-in(M, C, T)
: M -> M Part -> Pb -> As -> CR -> R
![Page 69: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/69.jpg)
How verify this plan answers query?1. Verify information content of plan
2. Verifying binding pattern constraints
IMDBActor($Actor, M) actor-in(M, Part, Actor) Spot($M, Rev, Y) review-of(M, Rev) &
year-of(M, Y)Sidewalk($C, M, Th) shows-in(M, C, Th)
plan(M, R, brando, seattle) IMDBActor(b, M) &Sidewalk(s, M, Th) &Spot(M, R, Y)
![Page 70: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/70.jpg)
Outline
• Logistics (Project) & Review
• First Order Predicate Calculus
• Relational Algebra
• Datalog
• Information Integration Softbots
• Query Containment
• Rewriting Queries w/ Views
![Page 71: Outline Logistics (Project) & Review First Order Predicate Calculus Relational Algebra Datalog Information Integration Softbots Query Containment Rewriting](https://reader035.vdocument.in/reader035/viewer/2022062519/56649f495503460f94c6b9cb/html5/thumbnails/71.jpg)
Summary• How Represent Contents of Information Sources?
– Datalog
• How pose a query?– Datalog
• How verify a plan answers query?1. Verify information content of plan
• Check containment of query and plan expansion
2. Verifying binding pattern constraints
• How find a valid solution plans?– Search through the space of...– Search-free synthesis of maximal recursive plan
Paper 6.1