Exemple #1
0
    def square_fv(self):
        """Conjunction of transducer with itself (Fast Version)

        :rtype: NFA"""
        new = fa.NFA()
        notDone = set()
        done = set()
        for s1 in self.Initial:
            for s2 in self.Initial:
                sname = (s1, s2)
                i = new.addState(sname)
                new.addInitial(i)
                notDone.add(sname)
        while notDone:
            state = notDone.pop()
            done.add(state)
            (i1, i2) = state
            i = new.stateIndex(state)
            (k1, k2) = (self.inputS(i1), self.inputS(i2))
            if i1 in self.Final and i2 in self.Final:
                new.addFinal(i)
            K = k1.intersection(k2)
            for syin in K:
                for (syout, sout) in self.delta[i1][syin]:
                    for (syout2, sout2) in self.delta[i2][syin]:
                        stoutr = (sout, sout2)
                        new.addTransitionQ(i, stoutr, (syin, (syout, syout2)),
                                           notDone, done)
        return new
Exemple #2
0
    def toInNFA(self):
        """Delete the output labels in the transducer. Translate it into an NFA

        :rtype: NFA"""
        aut = fa.NFA()
        aut.setSigma(self.Sigma)
        aut.States = copy.copy(self.States)
        aut.setInitial(self.Initial)
        aut.setFinal(self.Final)
        for s in self.delta.keys():
            aut.delta[s] = {}
            for c in self.delta[s]:
                aut.delta[s][c] = set([x for (_, x) in self.delta[s][c]])
        return aut