def startTRANSSemRule(self, lst, context=None): """ :param lst: :param context:""" if self.TRtype is None: new = SFT() elif self.TRtype == "GFT": new = GFT() else: raise common.TRError new.Sigma = self.alphabet new.Output = self.alphabetOut while self.states: x = self.states.pop() new.addState(x) while self.initials: x = self.initials.pop() new.addInitial(new.stateIndex(x)) while self.finals: x = self.finals.pop() new.addFinal(new.stateIndex(x)) while self.transitions: (x1, x2, x3, x4) = self.transitions.pop() new.addTransition(new.stateIndex(x1), x2, x3, new.stateIndex(x4)) self.theList.append(new) self.initLocal()
def trajToTransducer(traj, Sigma): """ Input Altering Tranducer corresponding to a Trajectory :param NFA traj: trajectory language :param set Sigma: alphabet :rtype: SFT""" t = SFT() t.Sigma = Sigma for s, sn in enumerate(traj.States): no = t.stateIndex((sn, False), True) yes = t.stateIndex((sn, True), True) if s in traj.Final: t.addFinal(yes) if s in traj.Initial: t.addInitial(no) for b in traj.delta.get(s, {}): for c in Sigma: for st in traj.delta[s][b]: fNo = t.stateIndex((traj.States[st], False), True) fYes = t.stateIndex((traj.States[st], True), True) if b == "0": t.addTransition(no, c, c, fNo) t.addTransition(yes, c, c, fYes) if b == "1": t.addTransition(no, Epsilon, c, fYes) t.addTransition(yes, Epsilon, c, fYes) return t
def createInputAlteringSIDTrans(n, sigmaSet): """Create an input-altering SID transducer based :param int n: max number of errors :param set sigmaSet: alphabet :return: a transducer representing the SID channel :rtype: SFT""" new = SFT() new.setSigma(sigmaSet) new.setOutput(sigmaSet) init = new.stateIndex((0, None), True) new.addInitial(init) for sy in new.Sigma: new.addTransition(init, sy, sy, init) i = 1 while i <= n: d1 = new.stateIndex((i, None), True) new.addFinal(d1) for s in new.Sigma: new.addTransition(d1, s, s, d1) d = new.stateIndex((i, s), True) new.addFinal(d) if i == 1: new.addTransition(init, s, Epsilon, d) for s1 in new.Sigma - {s}: new.addTransition(init, s, s1, d1) else: bar = new.stateIndex((i - 1, None)) new.addTransition(bar, s, Epsilon, d1) new.addTransition(bar, Epsilon, s, d1) for s1 in new.Sigma: foo = new.stateIndex((i - 1, s)) new.addTransition(foo, s1, Epsilon, d) if s1 != s: new.addTransition(bar, s, s1, d1) new.addTransition(foo, Epsilon, s1, d1) for s2 in new.Sigma: new.addTransition(foo, s2, s1, d1) for s1 in new.Sigma - {s}: new.addTransition(d, s1, s1, d1) i += 1 return new