예제 #1
0
 def __rmod__(self, formatter):
     return " / ".join(" ".join(formatter(x) for x in s)
                       for s in (self.set1, self.set2))
예제 #2
0
    @classmethod
    def break_apart(cls, cutpoints, input_string):
        c = [0] + cutpoints
        return [input_string[c[i]:c[i + 1]] for i in xrange(len(cutpoints))]


if __name__ == "__main__":
    from adt.graph.format import DEFAULT as formatter
    from tcs.regexp import RegExpAssistant

    res = [('+', [('*', ['g']), 'h']), ('+', [('*', ['g']), ('*', ['g'])]),
           ('+', [('*', ['g']), 'g'])]
    inputs = ["gggh", "gg", "ggg", "g7ggh"]

    r2a = RegExp2FSA()

    for re in res:
        r = RegExpAssistant.build(re)
        print r

        am = r2a(r)
        print formatter(am.g)

        for input in inputs:
            #decision, transitions = am.with_transitions(input)
            decision, stuff = MealyMachine(am)(input)
            if decision:
                match = RegExpMatch(r, input, stuff)
                stuff = match.cutpoints
            print u"   %-40s %-7r %r" % (input, decision, stuff)
예제 #3
0
        for refiner in refinery:
            partial_matching.refine(refiner)

        return len(refinery) > 0


if __name__ == "__main__":
    from adt.graph.build import FlowGraphTool
    from adt.graph.format import DEFAULT as formatter

    inputs = [((["o1"], lambda a: a), (["o2"], lambda a: a)),
              ((["1x", "2", "3", "4"], lambda a, b, c, d: a >>
                (b >> c >> "y" >> d | d)), (["1y", "2", "3",
                                             "4y"], lambda a, b, c, d: a >>
                                            (d | b >> c >> "y" >> d)))]

    for (inx, iny) in inputs:
        gx = FlowGraphTool(inx)()
        gy = FlowGraphTool(iny)()

        formatter = DigraphFormatter()
        print formatter(gx)
        print '-' * 10
        print formatter(gy)
        print '-' * 10

        iso = DAGIsomorphism(color_func=lambda x: x.label and x.label[0])
        iso.trace = trace.out
        print iso(gx, gy)
        print '-' * 30
예제 #4
0
            buildup_set = BuildupSet(buildup_set)
        while buildup_set.dirty:
            buildup_set.accept()
            buildup_set.update(func(buildup_set))
        return buildup_set


if __name__ == "__main__":
    from adt.graph.build import FlowGraphTool
    from adt.graph.format import DEFAULT as formatter
    from adt.graph.transform.apply import ApplyTo

    am_specs = [(["(0)", "((1))"],
                 lambda a,b: a >> 0 >> b >> 0 >> a),
                (["0", "1", "2", "3", "4", "((5))"],
                 lambda a,b,c,d,e,f: a >> 'c' >> a >> b >> 'a' >> c >> 'b' >> d >> \
                    'a' >> (c | e >> 'c' >> f))]

    inputs = [[0] * 3, "ccababac"]

    for am_spec in am_specs:
        g = FlowGraphTool(am_spec)()
        ApplyTo(nodes=DigraphBasedAutomaton.StateLabel.parse).inplace(g)
        print formatter(g)

        a = DigraphBasedAutomaton(g)
        for input in inputs:  #@ReservedAssignment
            decision, transitions = a.with_transitions(input)
            print "%-40s %-8r %r" % (input, decision, (transitions))
            print "%-40s %-8r %r" % (input, decision, a.reduce(transitions))