Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Safe Datalog Rule: A Datalog rule is of the form: p :- q1, ..., qn. where n>0 and p, q1, ..., and qn are positive

  1. Safe Datalog Rule: A Datalog rule is of the form:
    p :- q1, ..., qn. 
    where n>0 and p, q1, ..., and qn are positive atomic formulas of the form:
    r(x1, ..., xm) 
    or 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.

    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$ 

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago