Logics for Data and Knowledge Representation

Slides:



Advertisements
Similar presentations
LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified.
Advertisements

The Relational Calculus
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Chapter 3 : Relational Model
Relational Schemas and Predicate Logic: Notation.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
LDK R Logics for Data and Knowledge Representation Modal Logic Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia,
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Calculus 198:541 Rutgers University.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
Logics for Data and Knowledge Representation Exercises: Modeling Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
LDK R Logics for Data and Knowledge Representation Propositional Logic: Reasoning First version by Alessandro Agostini and Fausto Giunchiglia Second version.
LDK R Logics for Data and Knowledge Representation Query languages Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia,
IST 210 The Relational Language Todd S. Bacastow January 2004.
LDK R Logics for Data and Knowledge Representation First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
Web Science & Technologies University of Koblenz ▪ Landau, Germany Relational Data Model.
Copyright © Curt Hill The Relational Calculus Another way to do queries.
IST 210 The Relational Language Todd S. Bacastow January 2005.
LDK R Logics for Data and Knowledge Representation Propositional Logic Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia,
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
CPSC 603 Database Systems Lecturer: Laurie Webster II, Ph.D., P.E.
Logics for Data and Knowledge Representation
A First Course in Database Systems
COMP3017 Advanced Databases
Module 2: Intro to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Relational Model
Relational Algebra - Part 1
Relational Calculus Chapter 4, Part B
Exercises: First Order Logics (FOL)
Relational Algebra.
Chapter 6: Formal Relational Query Languages
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Logics for Data and Knowledge Representation
LECTURE 3: Relational Algebra
Relational Calculus.
Relational Calculus and QBE
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Logics for Data and Knowledge Representation
Chapter 2: Intro to Relational Model
Relational Calculus and QBE
Chapter 6: Formal Relational Query Languages
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Logics for Data and Knowledge Representation
Relational Algebra & Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
CSE544 Wednesday, March 29, 2006.
Lecture 2 Relational Database
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
CS 405G: Introduction to Database Systems
Presentation transcript:

Logics for Data and Knowledge Representation Query languages Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese

Outline Relational and Algebraic Structures Answer set Relational schemas and Databases Query languages Domain Relational Calculus Tuple Relational Calculus SQL Changed 2

<N, ≤> is a relational structure STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A relational structure is a mathematical structure of the form S = <D, R1, …, Rn> where: - D is a non-empty domain (a set of objects) - Ri with 1≤ i ≤ n is a relation over D of any arity <N, ≤> is a relational structure

<N, +> is an algebraic structure STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A mathematical structure S is an algebraic structure if S = <D, f1, …, fn> where each fi with 1≤ i ≤ n is a function. The term structure is therefore used to denote either a relational structure or an algebraic structure. If D is finite, we say that the structure S is finite <N, +> is an algebraic structure 4

Answer Set FOL can be used as query language on structures STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES FOL can be used as query language on structures Let be γ = γ(x1, …, xn) a FOL-formula, M a structure, a an assignment then γ is a query over M. Qγ = {(a1, …, an)  Dn | M ⊨ γ [a1, …, an]} Qγ is called the answer set (or retrieval set) of γ. Since model checking takes polynomial time, also the problem of finding the answer set takes polynomial time. NOTE: A database is a relational structure. [Codd, 1970] Tables in databases are finite relations.

Example (I) STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES ATTEND STUDENT COURSE PROFESSOR Enzo LDKR Fausto Max Mary ML Alex DB = <D, Attend> D = {Enzo, Max, Mary, LDKR, ML, Fausto, Alex} Attend = {(Enzo, LDKR, Fausto), (Max, LDKR, Fausto), (Mary, ML, Alex), (Mary, LDKR, Fausto)} γ = Attend(Enzo, LDKR, x) Qγ = {(Fausto)} γ = Attend(Mary, x, Alex) Qγ = {(ML)} γ = Attend(x, LDKR, Fausto) Qγ = {(Enzo), (Max), (Mary)}

Example (II) STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES ATTEND STUDENT COURSE PROFESSOR Enzo LDKR Fausto Max Mary ML Alex DB = <D, Attend> D = {Enzo, Max, Mary, LDKR, ML, Fausto, Alex} Attend = {(Enzo, LDKR, Fausto), (Max, LDKR, Fausto), (Mary, ML, Alex), (Mary, LDKR, Fausto)} γ = ∃z Attend(Mary, x, z) Qγ = {(ML), (LDKR)} Qγ is such that DB ⊨ ∃z Attend(Mary, x, z) [a(x) = ML] or DB ⊨ ∃z Attend(Mary, x, z) [a(x) = LDKR]

Relational schema and database schema STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A relational schema consists of a name and an arity A relational schema is a FOL-formula. A database schema is a collection of relational schemas plus a domain Attend(x, y, z) has name “Attend” and arity 3. D + Attend(x, y, z) + Student(x, y) + Course(x, y)

Relational instance and database instance STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A n-ary relational instance is an n-ary relation R  Dn A database instance is a collection of relational instances over a domain NOTE: a database instance is a relational structure Attend(Enzo, LDKR, Fausto) DB + the collection of rows in the tables

Relational database STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A relational database is a finite relational structure DB = <D, R1, …, Rn> In particular a DB is said to be in first normal form if: - the objects in D are atomic (i.e. are not sets) - the relations R1, …, Rn are defined over D - the order of the tuples in each Ri does not matter (is a set)

Domain Relational Calculus (DRC) STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES EMPLOYEE NAME POSITION MANAGER Enzo PhD Fausto Professor Bassi Feroz “List name, position and manager of the employees” γ = Employee(x, y, z) Qγ = All the tuples in the Relation “List managers of the employees named Enzo” γ = ∃y Employee(Enzo, y, z) Qγ = {(Fausto)}

SELECT STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES EMPLOYEE NAME POSITION MANAGER Enzo PhD Fausto Professor Bassi Feroz “List name and position of the employees having a manager” γ = ∃z Employee(x, y, z) Qγ = {(Enzo, PhD), (Fausto, Professor), (Feroz, PhD)} NOTE: The ∀ quantifier is used to state a condition that must be true for all the tuples in the database, i.e. no missing values.

FILTER STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES EMPLOYEE NAME POSITION MANAGER AGE Enzo PhD Fausto 35 Professor Bassi 40 Feroz 20 “List name and position of the employees with Fausto as manager” γ = ∃z Employee(x, y, Fausto, z) Qγ = {(Enzo, PhD)} “List name and position of the employees with age > 28” γ = ∃w ∃z (Employee(x, y, z, w) ∧ (w > 28)) Qγ = {(Enzo, PhD), (Fausto, Professor)}

JOIN FACULTY DEPT “List name of faculty members and their department” STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES FACULTY DEPT NAME POSITION MANAGER Enzo PhD Fausto Professor Bassi Feroz NAME DEPT Enzo DISI Fausto Feroz MATH “List name of faculty members and their department” γ = ∃y ∃z ( Faculty(x, y, z) ∧ Dept(x, w) ) Qγ = {(Enzo, DISI), (Fausto, DISI), (Feroz, MATH)} “List name of faculty members who belong to all departments” γ = ∀w (∃x Dept(x, w) → ∃y ∃z (Faculty(x, y, z) ∧ Dept(x, w)))

Problems with DRC STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES Atomic objects in the domain cannot be distinguished by column Faculty(Phd, 28, Enzo, Fausto) is a valid (but unwanted) query The order of the columns is important. The DB must be queried by remembering the order of the columns To overcome these problems we use the Tuple Relational Calculus (see next slide)

Tuple Relational Calculus (TRC) STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES We define a set of types {t1, …, tn}. The set of objects D is then partitioned as follows: D = Dt1 ∪ … ∪ Dtn where Dti is the set of objects of type ti We introduce a set of attributes, i.e. pairs of the form (name, type). Each pair is a typed attribute and the name is the attribute (that correspond to the name of the columns). A relational schema is a relation name with a tuple of typed attributes. Employee(Name String, Position String, Manager String, Age Int)

Queries in Tuple Relational Calculus STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES “List all employees who have an age of exactly 35” γ = Employee(t) ∧ (t.age = 35) “List name and position of the employees who have age 35” γ = ∃ t : {name, position} (Employee(t) ∧ t.age = 35) We write t.age to extract from the tuple t the content of the attribute called “age” t is called a tuple variable In TRC variables range over tuples and not over the domain D

Structured Query Language (SQL) STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES A friendly face over the Tuple Relational Calculus SELECT {T1.attrib, …, T2.attrib} FROM {relation} T1, {relation} T2, … WHERE {predicates} 18

Queries in Structured Query Language STRUCTURES :: ANSWER SET :: RELATIONAL SCHEMAS AND DATABASES :: QUERY LANGUAGES EMPLOYEE EMPLOYEE POSITION MANAGER Enzo PhD Fausto Professor Bassi Feroz “List name and position of the employees with Fausto as manager” SELECT name, position FROM employee WHERE manager = ‘Fausto’