Safe Datalog Rule: A Datalog rule is of the form:p :- q1, ..., qn. where n>0 and p is a positive atomic formula and q1, ..., and qn are positive or negative atomic formulas. A positive atomic formula is of the form:r(x1, ..., xm) and a negative atomic formulas of the form:not r(x1, ..., xm) where m>0 and r is a relation name and x1 , ..., xm are either numbers or variables. Relation names and variables are made up of alphabetic letters or digits and start with a lower-case alphabetic letter. Even though the variables are made up of lower and upper-case letters, these

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  1. Safe Datalog Rule: A Datalog rule is of the form:p :- q1, ..., qn. where n>0 and p is a positive atomic formula and q1, ..., and qn are positive or negative atomic formulas. A positive atomic formula is of the form:r(x1, ..., xm) and a negative atomic formulas of the form:not r(x1, ..., xm) where m>0 and r is a relation name and x1 , ..., xm are either numbers or variables. Relation names and variables are made up of alphabetic letters or digits and start with a lower-case alphabetic letter. Even though the variables are made up of lower and upper-case letters, these should be considered case-insensitive. For example, cno, CNO, cNO, etc all should be treated as the same variable.

    Some examples of Datalog rules are given below:

    ancestor(x1, y1) :- parent(x1, y1). teaches(tno,cno) :- faculty(tno), course(cno), assigned(tno,cno). p(x,y) :- q(2,x), r(u,45,z), s(a,b,22). p(x,y,z) :- q(x), not r(y,20), s(x,z). A Datalog rule is considered “Safe” if all variables that appear to the left of :- also appear to its right in positive atoms. For example in rule 2 above, the variables that appear to the left of :- are tno and cno. Both these variables appear to the right of :- in positive atomic formulas as well. So, this rule is “Safe”. However, rule 3 above is not “Safe” because the variable y appearing to the left of :- does not appear to the right of :-. Similarly, rule 4 is also not "Safe" because even though x, y, and z appear on the right hand side, unfortunately y appears only in a negative atomic formula, thereby rendering the rule "Unsafe".

    Using PLY, implement an Attribute Grammar that checks for "Safe" Datalog rules. In the first rule, return a Boolean value indicating whether the rule is safe (True) or unsafe (False). The main program, DLOG.py, can be used as a driver program. Here is a sample run:

    Mac-mini:dlog raj$ python3 DLOG.py Enter Datalog rule: ancestor(x1, y1) :- parent(x1, y1). SAFE Datalog Rule Enter Datalog rule: teaches(tno,cno) :- faculty(tno), course(cno), assigned(tno,cno). SAFE Datalog Rule Enter Datalog rule: p(x,y) :- q(2,x), r(u,45,z), s(a,b,22). UNSAFE Datalog Rule Enter Datalog rule: p(x,y,z) :- q(x), not r(y,20), s(x,z). UNSAFE Datalog Rule Enter Datalog rule: exit Mac-mini:dlog raj$
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY