Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

See DATALOG EXAMPLES BELOW: Question 4 Work In network records information about users being connected to each other as well as about the companies they

image text in transcribed

See DATALOG EXAMPLES BELOW:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Question 4 Work In network records information about users being "connected" to each other as well as about the companies they work for and the countries they live in. Banana distribution company Conchita uses WorkIn to start a re- ferral campaign: when a campaign participant convinces one of their di- rect or indirect Workin connections to "like" Conchita Work In page, this person becomes a campaign participant and gets a deduction on the ba- nana price. All employees of Conchita automatically participate in the cam- paign. Note, that we do not restrict the number of "steps" in the "path" connecting two persons. Assume that directly connected(user, user), works_for(user, company) and lives_in(user, country) are given to rep- resent the WorkIn data. Write a Datalog query to list countries that Con- chita can reach with this campaign. Example Queries Example: define a view relation P700 containing account numbers and balances for accounts at the Perryridge branch with a balance of over 700. P700 (A, B) :- account (A, "Perryridge, B), B > 700 Retrieve the balance of account number "A-217" in the view relation P700. ? P700("A-217, B) To find account number and balance of all accounts in P700 that have a balance greater than 800 ? P700 (A,B), B > 800 B1050 1871 OR N Valovato Example Queries Each rule defines a set of tuples that a view relation must contain. .e.g., P700 (A, B) :- account (A, Perryridge, B), B > 700 is read as - for all A, B if (A, "Perryridge", B) E account and B > 700 then (A, B) E P700 The set of tuples in a view relation is then defined as the union of all the sets of tuples defined by all the rules for the view relation. Example: interest_rate (A, 5) :- account (A, N, B), B = 10000 JBI050 18/19 6B N. Yakovets Negation in Datalog Define a view relation c that contains the names of all customers who have a deposit but no loan at the bank: C(N) :- depositor (N, A), not is_borrower (N) is_borrower (N) :- borrower (NL) NOTE: using 'not borrower (N, L)'in the first rule would result in a different meaning, namely there exists an N, L combination (N being a depositor) that is not in borrower In general, to prevent such confusion, we require all variables in negated predicates to also appear in a non-negated predicate somewhere in the rule JBI050 18/19 6B N. Yakovets A More General View Create a view relation empl that contains every tuple (X, Y) such that X is directly or indirectly managed by Y. empl (X, Y):- manager (X, Y) empl (X, Y):- manager (X, Z), empl (Z, Y) Find the direct and indirect employees of Jones. ?empl (X, Jones"). Can define the view empl in another way too: empl (X, Y):- manager (X, Y) empl (X, Y):- empl (X, Z), manager (Z, Y) Recursion in Datalog Suppose we are given a relation manager (X, Y) containing pairs of names X, Y such that Y is a manager of X (or equivalently, X is a direct employee of Y). Each manager may have direct employees, as well as indirect employees Indirect employees of a manager, say Jones, are employees of people who are direct employees of Jones, or recursively, employees of people who are indirect employees of Jones Suppose we wish to "find all (direct and indirect) employees of Jones". We can write a recursive Datalog program. empl_jones (X) :- manager (X, Jones) empl_jones (X) :- manager (X, Y), empl_jones (Y) JBI050 19/20 1B N. Yakovets Question 4 Work In network records information about users being "connected" to each other as well as about the companies they work for and the countries they live in. Banana distribution company Conchita uses WorkIn to start a re- ferral campaign: when a campaign participant convinces one of their di- rect or indirect Workin connections to "like" Conchita Work In page, this person becomes a campaign participant and gets a deduction on the ba- nana price. All employees of Conchita automatically participate in the cam- paign. Note, that we do not restrict the number of "steps" in the "path" connecting two persons. Assume that directly connected(user, user), works_for(user, company) and lives_in(user, country) are given to rep- resent the WorkIn data. Write a Datalog query to list countries that Con- chita can reach with this campaign. Example Queries Example: define a view relation P700 containing account numbers and balances for accounts at the Perryridge branch with a balance of over 700. P700 (A, B) :- account (A, "Perryridge, B), B > 700 Retrieve the balance of account number "A-217" in the view relation P700. ? P700("A-217, B) To find account number and balance of all accounts in P700 that have a balance greater than 800 ? P700 (A,B), B > 800 B1050 1871 OR N Valovato Example Queries Each rule defines a set of tuples that a view relation must contain. .e.g., P700 (A, B) :- account (A, Perryridge, B), B > 700 is read as - for all A, B if (A, "Perryridge", B) E account and B > 700 then (A, B) E P700 The set of tuples in a view relation is then defined as the union of all the sets of tuples defined by all the rules for the view relation. Example: interest_rate (A, 5) :- account (A, N, B), B = 10000 JBI050 18/19 6B N. Yakovets Negation in Datalog Define a view relation c that contains the names of all customers who have a deposit but no loan at the bank: C(N) :- depositor (N, A), not is_borrower (N) is_borrower (N) :- borrower (NL) NOTE: using 'not borrower (N, L)'in the first rule would result in a different meaning, namely there exists an N, L combination (N being a depositor) that is not in borrower In general, to prevent such confusion, we require all variables in negated predicates to also appear in a non-negated predicate somewhere in the rule JBI050 18/19 6B N. Yakovets A More General View Create a view relation empl that contains every tuple (X, Y) such that X is directly or indirectly managed by Y. empl (X, Y):- manager (X, Y) empl (X, Y):- manager (X, Z), empl (Z, Y) Find the direct and indirect employees of Jones. ?empl (X, Jones"). Can define the view empl in another way too: empl (X, Y):- manager (X, Y) empl (X, Y):- empl (X, Z), manager (Z, Y) Recursion in Datalog Suppose we are given a relation manager (X, Y) containing pairs of names X, Y such that Y is a manager of X (or equivalently, X is a direct employee of Y). Each manager may have direct employees, as well as indirect employees Indirect employees of a manager, say Jones, are employees of people who are direct employees of Jones, or recursively, employees of people who are indirect employees of Jones Suppose we wish to "find all (direct and indirect) employees of Jones". We can write a recursive Datalog program. empl_jones (X) :- manager (X, Jones) empl_jones (X) :- manager (X, Y), empl_jones (Y) JBI050 19/20 1B N. Yakovets

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Design a job advertisement.

Answered: 1 week ago