more lexical reordering weight stuff

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@362 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
ccorbett 2006-07-28 20:24:25 +00:00
parent a4fe78d425
commit 04a52a546f

View File

@ -95,6 +95,7 @@ void LexicalReordering::PrintTable()
float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
{
if(m_direction==LexReorderType::Bidirectional || m_direction==direction){
vector<float> val;
//this phrase declaration is to get around const mumbo jumbo and let me call a
//"convert to a string" method
@ -113,7 +114,23 @@ float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
//this key string is F from the hypothesis
val=m_orientation_table[ myphrase.GetStringRep(hypothesis->GetCurrTargetWordsRange())];
}
//will tell us where to look in the table for the probability we need
int index = 0;
//the weight will tell us what to multiply the probability we fetch by
float weight = 1;
int forward_offset = 0;
//the weight vector will be longer if this LexicalReordering is bidirectional,
//containing backward weights then forward weights.
//by probing its size we can see if the LexicalReordering is bidirectional,
//(meaning we need to access the forward weights midvector) and
//if it is Monotone or MSD (which changes where midvector is)
if(m_weights.size()==5){
forward_offset = 2;
}
else if(m_weights.size()==7){
forward_offset = 3;
}
if(m_orientation==DistortionOrientationType::Msd)
{
if(direction==LexReorderType::Backward)
@ -121,14 +138,17 @@ float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
if(orientation==DistortionOrientationType::MONO)
{
index=BACK_M;
weight=m_weights[1];
}
else if(orientation==DistortionOrientationType::SWAP)
{
index=BACK_S;
weight=m_weights[2];
}
else
{
index=BACK_D;
weight=m_weights[3];
}
}
@ -137,14 +157,17 @@ float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
if(orientation==DistortionOrientationType::MONO)
{
index=FOR_M;
weight=m_weights[1+forward_offset];
}
else if(orientation==DistortionOrientationType::SWAP)
{
index=FOR_S;
weight=m_weights[2+forward_offset];
}
else
{
index=FOR_D;
weight=m_weights[3+forward_offset];
}
}
}
@ -155,10 +178,12 @@ float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
if(orientation==DistortionOrientationType::MONO)
{
index=BACK_MONO;
weight=m_weights[1];
}
else
{
index=BACK_NONMONO;
weight=m_weights[2];
}
}
else
@ -166,14 +191,21 @@ float LexicalReordering::CalcScore(Hypothesis *hypothesis, int direction)
if(orientation==DistortionOrientationType::MONO)
{
index=FOR_MONO;
weight=m_weights[1+forward_offset];
}
else
{
index=FOR_NONMONO;
weight=m_weights[2+forward_offset];
}
}
}
return val[index];
return val[index] * weight;
}
else
{
return 0;
}
}