Convert the graph into an input WFST. Each arc is converted into a transducer with epsilon input and the existing arc label as output. Optional trans is the transducer weight used for each arc.
Returns a FrozenGraph of the converted graph.
>>> GraphToWfst(FrozenGraph(GraphTables((xrange(3), (0, 1, 1), (1, 2, 2), ('A', 'B', 'C')))), trans=10)
FrozenGraph(GraphTables(((0, 1, 2), (0, 1, 1), (1, 2, 2), (Transducer((None, 'A', 10)), Transducer((None, 'B', 10)), Transducer((None, 'C', 10))))))
Simple WFST lattice composition.
>>> display = None
>>> def dot_globals(label): return 'label="%s"' % (label,), 'rankdir=LR', 'node [label="", shape=circle, height=0.15, width=0.15]'
>>> def printit(g): print 'numnodes', g.num_nodes, 'numarcs', g.num_arcs, 'self_loop', g.has_self_loop, 'cyclic', g.has_cycle, 'connected', g.is_connected, 'strict_dag', g.is_strict_dag
>>> phonemes = FrozenGraph(GraphTables(([None]*6,
... ( 0, 0, 1, 1, 2, 3, 3, 4, 4, 4),
... ( 1, 1, 2, 3, 3, 4, 4, 5, 5, 5),
... ('AY', 'AE', 'K', 'K', 'T', 'IH', 'UH', 'N', 'D', 'V',))))
>>> display and phonemes.dot_display(globals=dot_globals('phonemes')) and None
>>> phone_fst = GraphToWfst(phonemes, trans=0)
>>> ' '.join(str(x) for x in phone_fst.arclabels)
'-:AY/0 -:AE/0 -:K/0 -:K/0 -:T/0 -:IH/0 -:UH/0 -:N/0 -:D/0 -:V/0'
>>> display and phone_fst.dot_display(globals=dot_globals('phone_fst')) and None
n0 -> n1 [label=”AY”] n0 -> n1 [label=”AE”] n1 -> n2 [label=”K”] n1 -> n3 [label=”K”] n2 -> n3 [label=”T”] n3 -> n4 [label=”IH”] n3 -> n4 [label=”UH”] n4 -> n5 [label=”N”] n4 -> n5 [label=”D”] n4 -> n5 [label=”V”] I AY active AE K T IH V can K UH N could K UH D
>>> lexicon = FrozenGraph(GraphTables(([None]*8, (0, 0, 2, 3, 4, 5, 0, 6, 7, 7), (1, 2, 3, 4, 5, 1, 6, 7, 1, 1), ('AY', 'AE', 'K', 'T', 'IH', 'V', 'K', 'UH', 'N', 'D'))))
>>> display and lexicon.dot_display(globals=dot_globals('lexicon')) and None
>>> def T(arg): return Transducer((arg, None, 0))
>>> def TT(*args): return Transducer(args + (0,))
>>> lexicon_fst = FrozenGraph(GraphTables(([None]*8, (0, 0, 2, 3, 4, 5, 0, 6, 7, 7), (1, 2, 3, 4, 5, 1, 6, 7, 1, 1), (TT('AY', 'I'), T('AE'), T('K'), T('T'), T('IH'), TT('V', 'active'), T('K'), T('UH'), TT('N', 'can'), TT('D', 'could')))))
>>> display and lexicon_fst.dot_display(globals=dot_globals('lexicon_fst')) and None
>>> result_fst = LatticeWfstCompose(phone_fst, lexicon_fst)
>>> printit(result_fst)
numnodes 9 numarcs 10 self_loop False cyclic False connected True strict_dag True
>>> display and result_fst.dot_display(globals=dot_globals('result_fst'), node_label_callback=None) and None
>>> # epsilon = 'Ε'
>>> epsilon = '-'
>>> wfst1 = FrozenGraph(GraphTables(((0, 1), (0, 0, 0, 0, 0), (1, 1, 1, 1, 1), (('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D'), ('e', 'E')))))
>>> wfst1.dot_display() and None
>>> wfst2 = FrozenGraph(GraphTables(((0, 1), (0, 0, 0, 0, 0), (1, 1, 1, 1, 1), (('A', 0), ('B', 1), ('C', 2), ('D', 3), ('E', 4, ))))) #0.5)))))
>>> wfst2.dot_display() and None
>>> wfst3 = wfst1 + wfst2 + WfstCompose(wfst1, wfst2)
workset: set([(0, 0)])
a A 0
b B 1
c C 2
d D 3
e E 4
>>> wfst3.dot_display(arc_label_callback=_wfst_arc_label_callback, globals=('rankdir=LR;',)) and None
>>> wfst10 = FrozenGraph(GraphTables(((0, 1, 2, 3, 4), (0, 1, 1, 2, 3), (1, 2, 3, 1, 4), (('a', 'b'), ('p','a'), ('l','a'), ('p','n'), ('e', epsilon)))))
>>> wfst11 = FrozenGraph(GraphTables(((0, 1), (0, 0, 0, 1, ), (1, 1, 1, 0, ), (('a', 'A'), ('b', 'B'), ('n', 'N'), (epsilon, epsilon), ))))
>>> wfst12 = wfst10 + wfst11 + WfstCompose(wfst10, wfst11, epsilon)
workset: set([(0, 0)])
a b B
p a A
l a A
p n N
>>> #wfst12.dot_display(arc_label_callback=_wfst_arc_label_callback, globals=('rankdir=LR;',)) and None
>>> def printit(g): print 'numnodes', g.num_nodes, 'numarcs', g.num_arcs, 'self_loop', g.has_self_loop, 'cyclic', g.has_cycle, 'connected', g.is_connected, 'strict_dag', g.is_strict_dag
def make_random_DAG(maxnumstarts, endtime, averageoutorder, averagearclength, numnodetokens, averagearcsuccesspermil, seed=None):
>>> a = make_random_DAG(1, 10, 2, 3, 4, 600, seed=0)
>>> printit(a)
numnodes 10 numarcs 11 self_loop False cyclic False connected True strict_dag True
>>> #a.dot_display(globals=('rankdir=LR;',)) and None
>>> b = make_random_DAG(1, 10, 2, 3, 4, 600, seed=3)
>>> printit(b)
numnodes 10 numarcs 12 self_loop False cyclic False connected True strict_dag True
>>> #b.dot_display(globals=('rankdir=LR;',)) and None
>>> c = multiply_lattices(a, b)
>>> printit(c)
numnodes 38 numarcs 69 self_loop False cyclic False connected True strict_dag True
>>> #c.dot_display(globals=('rankdir=LR;',)) and None
>>> d = FrozenGraph(GraphTables(((1,2,3), (0, 0, 1),(1,2,2),(10,20,30))))
>>> #d.dot_display(globals=('rankdir=LR;',)) and None
>>> e = FrozenGraph(GraphTables(((-1,-2,-3,-4,-5), (0, 0, 1, 2,3),(1,2,3,3,4),(-10,-20,-30,-40,-50))))
>>> #e.dot_display(globals=('rankdir=LR;',)) and None
>>> f = multiply_lattices(d,e)
>>> printit(f)
numnodes 6 numarcs 6 self_loop False cyclic False connected True strict_dag True
>>> #f.dot_display(globals=('rankdir=LR;',)) and None
>>> def printit(g): print 'numnodes', g.num_nodes, 'numarcs', g.num_arcs, 'self_loop', g.has_self_loop, 'cyclic', g.has_cycle, 'connected', g.is_connected, 'strict_dag', g.is_strict_dag
>>> d = FrozenGraph(GraphTables(((1,2,3), (0, 0, 1),(1,2,2),(10,20,30))))
>>> #d.dot_display(globals=('rankdir=LR;',)) and None
>>> e = FrozenGraph(GraphTables(((-1,-2,-3,-4,-5), (0, 0, 1, 2,3),(1,2,3,3,4),(-10,-20,-30,-40,-50))))
>>> #e.dot_display(globals=('rankdir=LR;',)) and None
>>> f = multiply_lattices2(d,e)
>>> printit(f)
numnodes 15 numarcs 15 self_loop False cyclic False connected False strict_dag True
>>> #f.dot_display(globals=('rankdir=LR;',)) and None