1 #include "penalty.h" // -*- tab-width: 2 -*-
4 //using namespace Dictionary;
7 float PenaltyDAG::edge_value(uint node_from
,uint node_to
) const
9 float value
= dag
->edge_value(node_from
,node_to
);
11 WordEntry
*we
= (WordEntry
*)dag
->node_info(node_to
);
14 for (uint i
= 0;i
< we
->len
;i
++)
15 if (we
->fuzid
& (1 << i
))
17 value
+= (float)count
*weight
*value
;
20 we
= (WordEntry
*)dag
->node_info(node_from
);
23 for (uint i
= 0;i
< we
->len
;i
++)
24 if (we
->fuzid
& (1 << i
))
26 value
+= (float)count
*weight
*value
;
31 float Penalty2DAG::edge_value(uint node_from
,uint node_to
) const
33 float value
= dag
->edge_value(node_from
,node_to
);
35 WordEntry
*we
= (WordEntry
*)dag
->node_info(node_to
);
38 for (uint i
= 0;i
< we
->len
;i
++)
39 if (we
->fuzid
& (1 << i
))
40 myweight
+= syllable_weights
[we
->pos
+i
];
42 //cerr << weight*myweight << endl;
43 value
+= (float)weight
*myweight
*value
;
46 we
= (WordEntry
*)dag
->node_info(node_from
);
49 for (uint i
= 0;i
< we
->len
;i
++)
50 if (we
->fuzid
& (1 << i
))
51 myweight
+= syllable_weights
[we
->pos
+i
];
53 //cerr << weight*myweight << endl;
54 value
+= (float)weight
*myweight
*value
;
56 return value
> 0 ? value
: 0;
59 void Penalty2DAG::set_syllable_weights(const Segmentation
&seg
)
61 uint i
,n
= seg
.size();
64 syllable_weights
.resize(seg
[n
-1].pos
+seg
[n
-1].len
);
66 for (i
= 0;i
< n
;i
++) {
67 v
[4] = i
>= 2 ? seg
[i
-2].node
.node
->get_id() : get_id(START_ID
);
68 v
[3] = i
>= 1 ? seg
[i
-1].node
.node
->get_id() : get_id(START_ID
);
69 v
[2] = seg
[i
].node
.node
->get_id();
70 v
[1] = i
+ 1 < n
? seg
[i
+1].node
.node
->get_id() : get_id(STOP_ID
);
71 v
[0] = i
+ 2 < n
? seg
[i
+2].node
.node
->get_id() : get_id(STOP_ID
);
74 double v1
= LogPtoProb(get_ngram().wordProb(v
[2],&v
[3]));
78 double v2
= LogPtoProb(get_ngram().wordProb(v
[1],&v
[2]));
83 double v3
= LogPtoProb(get_ngram().wordProb(v
[0],&v
[1]));
86 for (uint j
= seg
[i
].pos
;j
< seg
[i
].pos
+seg
[i
].len
;j
++)
87 syllable_weights
[j
] = (v1
+v2
+v3
)/3;