8 #include "propername.h"
12 void lattice_to_dot(ostream
&os
,const Lattice
&w2
,bool spare
,bool edge_value
)
15 const Sentence
&st
= *w2
.st
;
16 const WordEntries
&wes
= *w2
.we
;
19 os
<< "digraph wordlattice {" << endl
;
20 os
<< "\trankdir=LR;" << endl
;
21 os
<< "\tstyle=invis;" << endl
;
22 os
<< "\thead;" << endl
;
23 os
<< "\ttail;" << endl
;
27 int anchor
[st
.get_syllable_count()];
28 for (i
= 0;i
< n
;i
++) {
29 //if (nodes.find(wes[i].node.node->get_id()) == nodes.end()) {
30 //nodes.insert(wes[i].node.node->get_id());
31 if (wes
[i
].pos
!= old_pos
) {
35 os
<< "\tsubgraph cluster_" << wes
[i
].pos
<< " {" << endl
;
40 if (spare
&& cc
++ == w2
.get_we(wes
[i
].pos
).size()/2)
41 //os << "\tanchor_" << wes[i].pos << " [shape=\"point\"];" << endl;
42 anchor
[wes
[i
].pos
] = i
;
44 os
<< "\tn" << i
<< " [label=\"";
45 std::vector
<strid
> syll
;
46 if (wes
[i
].node
.node
) {
47 wes
[i
].node
.node
->get_syllables(syll
);
48 for (std::vector
<strid
>::size_type ii
= 0;ii
< syll
.size();ii
++) {
52 if (sy
.parse(get_ngram()[syll
[ii
]]))
55 os
<< get_ngram()[syll
[ii
]];
63 os
<< "\t}" << endl
; // end of the last cluster
66 for (i
= 0;i
< st
.get_syllable_count()-1;i
++) {
67 //os << "anchor_" << i << " -> anchor_" << (i+1) << " [style=invis, weight=10000];" << endl;
68 os
<< "n" << anchor
[i
] << " -> n" << anchor
[i
+1] << " [style=invis, weight=10000];" << endl
;
75 for (i
= 0;i
< n
;i
++) {
76 const WordEntry
&we
= wes
[i
];
80 vi
[0] = get_id(START_ID
);
81 val
= -get_ngram().wordProb(we
.node
.node
->get_id(),vi
);
82 os
<< "\thead -> n" << we
.id
<< " [ label=\"" << val
<< "\"];" << endl
;
84 os
<< "\thead -> n" << we
.id
<< ";" << endl
;
86 if (we
.pos
+we
.len
>= w2
.get_word_count()) {
88 vi
[0] = we
.node
.node
->get_id();
89 val
= -get_ngram().wordProb(get_id(STOP_ID
),vi
);
90 os
<< "\tn" << we
.id
<< " -> tail [ label=\"" << val
<< "\"];" << endl
;
92 os
<< "\tn" << we
.id
<< " -> tail;" << endl
;
95 os
<< "\tn" << we
.id
<< " -> n" << anchor
[(we
.pos
+we
.len
)] << ";" << endl
;
97 const WordEntryRefs
&wers
= w2
.get_we(we
.pos
+we
.len
);
99 for (ii
= 0;ii
< nn
; ii
++) {
101 vi
[0] = we
.node
.node
->get_id();
102 val
= -get_ngram().wordProb(wers
[ii
]->node
.node
->get_id(),vi
);
103 os
<< "\tn" << we
.id
<< " -> n" << wers
[ii
]->id
<< " [label=\"" << val
<< "\"];" << endl
;
105 os
<< "\tn" << we
.id
<< " -> n" << wers
[ii
]->id
<< ";" << endl
;
114 int main(int argc
,char **argv
)
117 bool edge_value
= false;
119 for (int i
= 1;i
< argc
;i
++) {
120 if (!strcmp(argv
[i
],"--spare")) {
124 if (!strcmp(argv
[i
],"--edge")) {
126 cerr
<< "ngram is needed for --edge" << endl
;
129 if (!get_ngram().read(argv
[i
+1])) {
130 cerr
<< "ngram " << argv
[i
+1] << " failed to load" << endl
;
137 cerr
<< "Unknown parameter " << argv
[i
] << endl
;
141 warch
.load("wordlist");
145 if (++count
% 200 == 0) cerr
<< count
<< endl
;
148 lattice_to_dot(cout
,l
,spare
,edge_value
);