Beispiel #1
0
def __enable_disjunction_for_nodes__(SOA, nodes):
    """
    Enables the Disjunction Rewrite Rule for `nodes`.

    NOTE: This may introduce self-loops, so applying `rewrite` MAY
    choose the SELF-LOOP instead which effectively fools this. Thus
    we apply `__disjunctionrule__` at the end of the rule.
    """
    def is_valid(nodes):
        pred = SOA.pred(nodes[0])
        succ = SOA.succ(nodes[0])
        for which in nodes[1:]:
            pred &= SOA.pred(which)
            succ &= SOA.succ(which)
        return pred == SOA.pred(nodes[0]) and succ == SOA.succ(nodes[0])

    valid = is_valid(nodes)
    while not valid:
        pred = set()
        succ = set()
        for which in nodes:
            pred |= SOA.pred(which)
            succ |= SOA.succ(which)
        for which in nodes:
            for source in (x for x in pred if x not in SOA.pred(which)):
                SOA.addedge((source, which))
            for target in (x for x in succ if x not in SOA.succ(which)):
                SOA.addedge((which, target))
        valid = is_valid(nodes)
    assert __disjunctionrule__(SOA)
Beispiel #2
0
 def testNonApplicableDisjunction(self):
     self.assertEqual(__disjunctionrule__(self.tree), False)
     self.assertEqual(len(self.tree), 7)
Beispiel #3
0
 def testConjunctionRuleApplied(self):
     __optionalrule__(self.graph)
     __disjunctionrule__(self.graph)
     self.assertEqual(__concatrule__(self.graph), True)
     self.assert_(Conjunction([Optional('b'), Disjunction(['c', 'a'])]) in self.graph.nodes)
Beispiel #4
0
 def testDisjunctionRuleApplied(self):
     __optionalrule__(self.graph)
     self.assertEqual(__disjunctionrule__(self.graph), True)
     self.assert_(Disjunction(('a', 'c')) in self.graph.nodes)