mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-09 04:56:57 +03:00
Fixed constraint decoding - there may be a bug in Util::Tokenize
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1858 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
81c7e5118b
commit
3e1c6c39ff
@ -154,50 +154,37 @@ Hypothesis* Hypothesis::CreateNext(const TranslationOption &transOpt, const Phra
|
||||
Hypothesis* Hypothesis::Create(const Hypothesis &prevHypo, const TranslationOption &transOpt, const Phrase* constrainingPhrase)
|
||||
{
|
||||
|
||||
// This method contains code for constraint decoding, which is still in development
|
||||
// This method includes code for constraint decoding
|
||||
|
||||
bool createHypothesis = true;
|
||||
|
||||
size_t start = 1 + prevHypo.GetCurrTargetWordsRange().GetEndPos();//prevHypo.GetCurrTargetLength();
|
||||
|
||||
//if (oldSize > 100000) start=0;
|
||||
|
||||
const Phrase &transOptPhrase = transOpt.GetTargetPhrase();
|
||||
size_t transOptSize = transOptPhrase.GetSize();
|
||||
|
||||
size_t endpoint = start + transOptSize - 1;
|
||||
|
||||
//std::cerr << "SPAN (" << start << "-" << endpoint << ")" << std::endl;
|
||||
|
||||
if (constrainingPhrase != NULL)
|
||||
{
|
||||
|
||||
size_t constraintSize = constrainingPhrase->GetSize();
|
||||
|
||||
size_t start = 1 + prevHypo.GetCurrTargetWordsRange().GetEndPos();
|
||||
|
||||
const Phrase &transOptPhrase = transOpt.GetTargetPhrase();
|
||||
size_t transOptSize = transOptPhrase.GetSize();
|
||||
|
||||
size_t endpoint = start + transOptSize - 1;
|
||||
|
||||
|
||||
|
||||
if (endpoint < constraintSize)
|
||||
{ //std::cerr << "" << start << " + " << transOptSize << " - 1 <= " << constraintSize << " for translation option '" << transOpt.GetTargetPhrase() << "' from '" << *(transOpt.GetSourcePhrase()) << "'" << std::endl;
|
||||
|
||||
{
|
||||
WordsRange range(start, endpoint);
|
||||
//std::cout << "Range is " << start << " to " << (oldSize + transOptSize) << "\n";
|
||||
Phrase relevantConstraint = constrainingPhrase->GetSubString(range);
|
||||
|
||||
if ( ! relevantConstraint.IsCompatible(transOptPhrase) )
|
||||
{
|
||||
createHypothesis = false;
|
||||
//std::cerr << "Returning NULL hypothesis when constraining phrase is (" << start << "-" << endpoint << ") '" << relevantConstraint << "' and phrase is '" << transOpt.GetTargetPhrase() << "'"<< std::endl;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cerr << "COMPATABLE CONSTRAINT!!!!!!!!!!!!!!!!!!!!!!!!!!! (" << start << "-" << endpoint << ") '" << relevantConstraint << "' and '" << transOpt.GetTargetPhrase() << "'" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
createHypothesis = false;
|
||||
//std::cerr << "" << start << " + " << transOptSize << " <= " << constraintSize << " for translation option " << transOpt.GetTargetPhrase() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@ -216,6 +203,9 @@ Hypothesis* Hypothesis::Create(const Hypothesis &prevHypo, const TranslationOpti
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the previous hypothesis plus the proposed translation option
|
||||
// fail to match the provided constraint,
|
||||
// return a null hypothesis.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -289,12 +289,18 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
|
||||
while (getline(constraintFile, line))
|
||||
{
|
||||
vector<string> vecStr = Tokenize<string>(line, "\t");
|
||||
assert(vecStr.size() == 2);
|
||||
|
||||
Phrase phrase(Output);
|
||||
phrase.CreateFromString(GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter());
|
||||
//vector<string> vecStr = Tokenize<string>(line, "\t");
|
||||
//assert(vecStr.size() == 2);
|
||||
//cout << "vec size == " << vecStr.size() << endl;
|
||||
|
||||
Phrase phrase(Output);
|
||||
//phrase.CreateFromString(GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter());
|
||||
phrase.CreateFromString(GetOutputFactorOrder(), line, GetFactorDelimiter());
|
||||
|
||||
//std::istringstream i(vecStr[0]);
|
||||
//assert(i >> sentenceID);
|
||||
//cout << "Sentence read in with number " << sentenceID << " and sentence: '" << vecStr[1] << "'" << endl;
|
||||
|
||||
m_constraints.insert(make_pair(sentenceID,phrase));
|
||||
sentenceID++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user