コード例 #1
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])
     x_0_1 = apply_renaming_to_atom_values(x_0, renamings[1])
     DatalogQuery.__init__(
         self, Atom("Trans_" + str(rewriting_index), x_0 + x_0_0))
     self.add_atom(Atom("Trans_" + str(rewriting_index), x_0 + x_0_1))
     self.add_atom(Atom("Link_" + str(rewriting_index), x_0_1 + x_0_0))
コード例 #2
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])[0]
     x_0_1 = apply_renaming_to_atom_values(x_0, renamings[1])[0]
     x_0 = x_0[0]
     DatalogQuery.__init__(
         self, Atom("Lower_" + str(rewriting_index), [x_0, x_0_0]))
     self.add_atom(Atom("Trans_" + str(rewriting_index), [x_0, x_0_0]))
     self.add_atom(Atom("Trans_" + str(rewriting_index), [x_0, x_0_1]))
     self.add_atom(CompareAtom(x_0_0, x_0_1, True))
コード例 #3
0
 def __init__(self, cycle, q, index, rewriting_index, renamings):
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])
     x_0_1 = apply_renaming_to_atom_values(x_0, renamings[1])
     DatalogQuery.__init__(
         self, Atom("Lower_" + str(rewriting_index), x_0 + x_0_0))
     self.add_atom(Atom("Trans_" + str(rewriting_index), x_0 + x_0_0))
     self.add_atom(Atom("Trans_" + str(rewriting_index), x_0 + x_0_1))
     for i in range(0, index - 1):
         self.add_atom(EqualityAtom(x_0_0[i], x_0_1[i]))
     self.add_atom(CompareAtom(x_0_0[index], x_0_1[index], True))
コード例 #4
0
 def __init__(self, atom, cycle, q, rewriting_index, renamings):
     index = cycle.index(atom)
     k = len(cycle)
     _, x, _ = q.decompose_atom(atom)
     head_atom = Atom("Garbage_" + atom.name,
                      apply_renaming_to_atom_values(x, renamings[index]))
     DatalogQuery.__init__(self, head_atom)
     irr_content = []
     for i in range(k):
         _, x, _ = q.decompose_atom(cycle[i])
         irr_content += apply_renaming_to_atom_values(x, renamings[i])
     self.add_atom(Atom("Irr1Emb_" + str(rewriting_index), irr_content))
コード例 #5
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     for i in range(k):
         _, x, _ = q.decompose_atom(cycle[i])
         head_content += apply_renaming_to_atom_values(x, renamings[i])
     head_atom = Atom("InLongDCycle_" + str(rewriting_index), head_content)
     DatalogQuery.__init__(self, head_atom)
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_k = apply_renaming_to_atom_values(x_0, renamings[k])
     self.add_atom(Atom("Pk_" + str(rewriting_index), head_content + x_0_k))
     self.add_atom(
         Atom("DCon_" + str(rewriting_index), x_0_k + head_content))
コード例 #6
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     any_content = []
     for i in range(k):
         _, x, y = q.decompose_atom(cycle[i])
         head_content += apply_renaming_to_atom_values(x, renamings[i])
         any_content += apply_renaming_to_atom_values(x, renamings[i])
         any_content += apply_renaming_to_atom_values(y, renamings[i])
     head_atom = Atom("Irr1Emb_" + str(rewriting_index), head_content)
     DatalogQuery.__init__(self, head_atom)
     self.add_atom(Atom("Any1Emb_" + str(rewriting_index), any_content))
     self.add_atom(Atom("Rel1Emb_" + str(rewriting_index), any_content),
                   True)
コード例 #7
0
 def __init__(self, atom, cycle, q, rewriting_index, renaming):
     k = len(cycle)
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_ren = apply_renaming_to_atom_values(x_0, renaming)
     DatalogQuery.__init__(
         self, Atom("Link_" + str(rewriting_index), x_0 + x_0_ren))
     for i in range(k):
         _, x, y = q.decompose_atom(cycle[i])
         self.add_atom(Atom("Keep_" + cycle[i].name, x + y))
         x = apply_renaming_to_atom_values(x, renaming)
         y = apply_renaming_to_atom_values(y, renaming)
         self.add_atom(Atom("Keep_" + cycle[i].name, x + y))
     index = cycle.index(atom)
     _, x_i, _ = q.decompose_atom(cycle[index])
     x_i_ren = apply_renaming_to_atom_values(x_i, renaming)
     self.add_atom(Atom("Eq_" + atom.name, x_i + x_i_ren))
コード例 #8
0
ファイル: rewriting.py プロジェクト: aeaziz/cqapk_to_datalog
def new_atoms(cycle: List[structures.Atom], q: structures.ConjunctiveQuery, rewriting_index: int,
              renaming: Dict[structures.AtomValue, structures.AtomValue]) -> \
        Tuple[Tuple[structures.Atom, structures.FunctionalDependencySet, List[bool], bool],
              List[Tuple[structures.Atom, structures.FunctionalDependencySet, List[bool], bool]]]:
    """
    Generates the atoms needed for the reduction
    :param cycle:				Cycle being reduced
    :param q:					A ConjunctiveQuery
    :param rewriting_index:		Index used to enumerate the Datalog rules
    :param renaming:			Necessary renaming
    :return:					Atoms needed for the reduction
    """
    _, x_0, _ = q.decompose_atom(cycle[0])
    x_0_ren = algorithms.apply_renaming_to_atom_values(x_0, renaming)
    n_atoms = []
    t_content = []
    t_released = set()
    for atom in cycle:
        _, x, y = q.decompose_atom(atom)
        n = structures.Atom("N_" + atom.name, x + x_0_ren, atom.released)
        t_released = t_released.union(atom.released)
        fd = structures.FunctionalDependencySet()
        for var in x_0_ren:
            fd.add(structures.FunctionalDependency(x, var))
        is_key = [True] * len(x) + [False] * len(x_0_ren)
        n_atoms.append((n, fd, is_key, True))
        t_content += x
        t_content += y
    t = structures.Atom("T_" + str(rewriting_index), x_0_ren + t_content, t_released)
    fd = structures.FunctionalDependencySet()
    for var in t_content:
        fd.add(structures.FunctionalDependency(x_0_ren, var))
    is_key = [True] * len(x_0_ren) + [False] * len(t_content)
    return (t, fd, is_key, False), n_atoms
コード例 #9
0
 def __init__(self, cycle, q, rewriting_index, renaming):
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_ren = apply_renaming_to_atom_values(x_0, renaming)
     DatalogQuery.__init__(
         self, Atom("IdentifiedBy_" + str(rewriting_index), x_0 + x_0_ren))
     self.add_atom(Atom("Lower_" + str(rewriting_index), x_0 + x_0_ren),
                   True)
     self.add_atom(Atom("Trans_" + str(rewriting_index), x_0 + x_0_ren))
コード例 #10
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     for i in range(k):
         _, x, y = q.decompose_atom(cycle[i])
         head_content += apply_renaming_to_atom_values(x, renamings[i])
         head_content += apply_renaming_to_atom_values(y, renamings[i])
     head_atom = Atom("Any1Emb_" + str(rewriting_index), head_content)
     DatalogQuery.__init__(self, head_atom)
     for i in range(k):
         for atom in q.get_atoms():
             self.add_atom(apply_renaming_to_atom(atom, renamings[i]))
     for i in range(k):
         _, x, y = q.decompose_atom(cycle[i])
         key1 = apply_renaming_to_atom_values(x, renamings[i])
         key2 = apply_renaming_to_atom_values(x, renamings[(k - 1 + i) % k])
         self.add_atom(Atom("Eq_" + cycle[i].name, key1 + key2))
コード例 #11
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])
     x_0_2k = apply_renaming_to_atom_values(x_0, renamings[2 * k])
     head_content += x_0_0
     head_content += x_0_2k
     common = []
     for i in range(1, k):
         _, x, _ = q.decompose_atom(cycle[i])
         common += apply_renaming_to_atom_values(x, renamings[i])
     head_atom = Atom("DCon_" + str(rewriting_index), head_content + common)
     DatalogQuery.__init__(self, head_atom)
     x_0_2k_1 = apply_renaming_to_atom_values(x_0, renamings[2 * k + 1])
     self.add_atom(
         Atom("DCon_" + str(rewriting_index), x_0_0 + x_0_2k_1 + common))
     pk_content = x_0_2k_1
     for i in range(1, k):
         _, x, _ = q.decompose_atom(cycle[i])
         pk_content += apply_renaming_to_atom_values(x, renamings[k + i])
     pk_content += x_0_2k
     self.add_atom(Atom("Pk_" + str(rewriting_index), pk_content))
     for i in range(1, k):
         _, x, _ = q.decompose_atom(cycle[i])
         key1 = apply_renaming_to_atom_values(x, renamings[k + i])
         key2 = apply_renaming_to_atom_values(x, renamings[i])
         self.add_atom(Atom("Neq_" + cycle[i].name, key1 + key2))
コード例 #12
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_2k = apply_renaming_to_atom_values(x_0, renamings[2 * k])
     head_content += x_0_2k * 2
     common = []
     for i in range(1, k):
         _, x, _ = q.decompose_atom(cycle[i])
         common += apply_renaming_to_atom_values(x, renamings[i])
     head_atom = Atom("DCon_" + str(rewriting_index), head_content + common)
     DatalogQuery.__init__(self, head_atom)
     for atom in cycle:
         self.add_atom(apply_renaming_to_atom(atom, renamings[2 * k]))
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])
     x_0_k = apply_renaming_to_atom_values(x_0, renamings[k])
     self.add_atom(
         Atom("Pk_" + str(rewriting_index), x_0_0 + common + x_0_k))
コード例 #13
0
 def __init__(self, atom, q, renaming):
     v, x, _ = q.decompose_atom(atom)
     renamed_x = apply_renaming_to_atom_values(x, renaming)
     head_atom = Atom("Neq_" + atom.name, x + renamed_x)
     renamed_atom = apply_renaming_to_atom(atom, renaming)
     eq_atom = Atom("Eq_" + atom.name, x + renamed_x)
     DatalogQuery.__init__(self, head_atom)
     self.add_atom(atom)
     self.add_atom(renamed_atom)
     self.add_atom(eq_atom, True)
コード例 #14
0
 def __init__(self, atom, cycle, q, rewriting_index, renaming):
     _, x, _ = q.decompose_atom(atom)
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_ren = apply_renaming_to_atom_values(x_0, renaming)
     DatalogQuery.__init__(self, Atom("N_" + atom.name, x + x_0_ren))
     t_atom_content = x_0_ren
     for atom in cycle:
         _, x, y = q.decompose_atom(atom)
         t_atom_content += x
         t_atom_content += y
     self.add_atom(Atom("T_" + str(rewriting_index), t_atom_content))
コード例 #15
0
 def __init__(self, cycle, q, rewriting_index, renaming):
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_ren = apply_renaming_to_atom_values(x_0, renaming)
     head_content = []
     body_atoms = []
     head_content += x_0_ren
     for atom in cycle:
         _, x, y = q.decompose_atom(atom)
         head_content += x + y
         body_atoms.append(Atom("Keep_" + atom.name, x + y))
     DatalogQuery.__init__(self,
                           Atom("T_" + str(rewriting_index), head_content))
     for atom in body_atoms:
         self.add_atom(atom)
     self.add_atom(
         Atom("IdentifiedBy_" + str(rewriting_index), x_0 + x_0_ren))
コード例 #16
0
 def __init__(self, cycle, q, rewriting_index, renamings):
     k = len(cycle)
     head_content = []
     for i in range(k):
         _, x, _ = q.decompose_atom(cycle[i])
         head_content += apply_renaming_to_atom_values(x, renamings[i])
     _, x_0, _ = q.decompose_atom(cycle[0])
     x_0_k = apply_renaming_to_atom_values(x_0, renamings[k])
     head_content += x_0_k
     head_atom = Atom("Pk_" + str(rewriting_index), head_content)
     DatalogQuery.__init__(self, head_atom)
     for i in range(k + 1):
         for atom in q.get_atoms():
             self.add_atom(apply_renaming_to_atom(atom, renamings[i]))
     for i in range(1, k):
         _, x, y = q.decompose_atom(cycle[i])
         key1 = apply_renaming_to_atom_values(x, renamings[i])
         key2 = apply_renaming_to_atom_values(x, renamings[i - 1])
         self.add_atom(Atom("Eq_" + cycle[i].name, key1 + key2))
     x_0_k_1 = apply_renaming_to_atom_values(x_0, renamings[k - 1])
     x_0_0 = apply_renaming_to_atom_values(x_0, renamings[0])
     self.add_atom(Atom("Eq_" + cycle[0].name, x_0_k + x_0_k_1))
     self.add_atom(Atom("Neq_" + cycle[0].name, x_0_0 + x_0_k))