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
;
28 return value
> 0 ? value
: 0;
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
);
39 for (uint i
= 0;i
< we
->len
;i
++)
40 if (we
->fuzid
& (1 << i
))
41 myweight
+= weight
*syllable_weights
[we
->pos
+i
];
42 value
+= (float)myweight
*value
;
45 we
= (WordEntry
*)dag
->node_info(node_from
);
49 for (uint i
= 0;i
< we
->len
;i
++)
50 if (we
->fuzid
& (1 << i
))
51 myweight
+= weight
*syllable_weights
[we
->pos
+i
];
52 value
+= (float)count
*weight
*value
;
54 return value
> 0 ? value
: 0;
57 void Penalty2DAG::set_syllable_weights(const Segmentation
&seg
)
59 uint i
,n
= seg
.size();
62 syllable_weights
.resize(seg
[n
-1].pos
+seg
[n
-1].len
);
64 for (i
= 0;i
< n
;i
++) {
65 v
[0] = i
>= 2 ? seg
[i
-2].node
.node
->get_id() : get_id(START_ID
);
66 v
[1] = i
>= 1 ? seg
[i
-1].node
.node
->get_id() : get_id(START_ID
);
67 v
[2] = seg
[i
].node
.node
->get_id();
68 v
[3] = i
+ 1 < n
? seg
[i
+1].node
.node
->get_id() : get_id(STOP_ID
);
69 v
[4] = i
+ 2 < n
? seg
[i
+2].node
.node
->get_id() : get_id(STOP_ID
);
73 float v1
= LogPtoProb(get_ngram().wordProb(ov
,v
));
78 float v2
= LogPtoProb(get_ngram().wordProb(ov
,v
+1));
83 float v3
= LogPtoProb(get_ngram().wordProb(ov
,v
+2));
86 for (uint j
= seg
[i
].pos
;j
< seg
[i
].pos
+seg
[i
].len
;j
++)
87 syllable_weights
[j
] = (v1
+v2
+v3
)/3;