Exemple #1
0
def mk_r():
    v1 = ast.Variable('V1')
    v2 = ast.Variable('V2')
    v3 = ast.Variable('V3')
    a1 = ast.Atom('p', [v1, v2])
    a2 = ast.Atom('q', [v1, v3])
    a3 = ast.Atom('r', [v3, v2])
    r = ast.Rule(a1, [a2, a3])
    return r, v1, v2, v3
Exemple #2
0
 def test_eq(self):
     a1 = ast.Atom('p', [])
     a2 = ast.Atom('q', [])
     a3 = ast.Atom('r', [])
     self.assertIs(True, ast.Rule(a1, [a2, a3]) == ast.Rule(a1, [a2, a3]))
     self.assertIs(False, ast.Rule(a2, [a2, a3]) == ast.Rule(a1, [a2, a3]))
     self.assertIs(False, ast.Rule(a1, [a1, a3]) == ast.Rule(a1, [a2, a3]))
Exemple #3
0
 def find_base_relations(self):
     """Extracts base relations of the theory"""
     aux_counter = 0
     new_rules = []
     for rule in self.rules:
         if self.datasource.is_extensible(rule.head):
             raise base.Z3NotWellFormed(
                 "No base predicate allowed in head: " + rule.head.table)
         for i, atom in enumerate(rule.body):
             if not self.datasource.is_extensible(atom):
                 continue
             fields = self.extensible_tables.setdefault(atom.table, [])
             if atom.labels is None:
                 raise base.Z3NotWellFormed(
                     "No labels for extensible atom {}".format(atom))
             for label in atom.labels:
                 if label not in fields:
                     fields.append(label)
             if atom.negated:
                 new_table = "_negated_%d" % aux_counter
                 aux_counter += 1
                 new_atom = ast.Atom(new_table, atom.args, negated=True)
                 var_row = [
                     ast.Variable("V%d" % i) for i in range(len(atom.args))
                 ]
                 atom_head = ast.Atom(new_table, var_row)
                 atom_body = ast.Atom(atom.table,
                                      var_row,
                                      labels=atom.labels)
                 new_rule = ast.Rule(atom_head, [atom_body])
                 new_rules.append(new_rule)
                 rule.body[i] = new_atom
     self.rules.extend(new_rules)
     for fields in self.extensible_tables.values():
         fields.sort()
     for rule in self.rules:
         for atom in rule.body:
             if self.datasource.is_extensible(atom):
                 self.flatten(atom, self.extensible_tables[atom.table])
Exemple #4
0
def p_rule_no_body(t):
    'rule : predicate DOT'
    t[0] = ast.Rule(head=t[1], body=[])
Exemple #5
0
def p_rule(t):
    'rule : predicate ENTAIL predicate_list DOT'
    t[0] = ast.Rule(head=t[1], body=t[3])