fixed a minor bug introduced by previous commit

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2781 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
bojar 2010-01-29 17:11:34 +00:00
parent c12c8d85dd
commit 9e7c97ddbc
2 changed files with 29 additions and 26 deletions

View File

@ -25,7 +25,9 @@ SearchNormal::SearchNormal(Manager& manager, const InputType &source, const Tran
// only if constraint decoding (having to match a specified output)
long sentenceID = source.GetTranslationId();
m_constraint = staticData.GetConstrainingPhrase(sentenceID);
VERBOSE(1, "Search constraint to output: " << *m_constraint<<endl);
if (m_constraint) {
VERBOSE(1, "Search constraint to output: " << *m_constraint<<endl);
}
// initialize the stacks: create data structure and set limits
std::vector < HypothesisStackNormal >::iterator iterStack;

View File

@ -338,35 +338,36 @@ bool StaticData::LoadData(Parameter *parameter)
// Read in constraint decoding file, if provided
if(m_parameter->GetParam("constraint").size()) {
if (m_parameter->GetParam("search-algorithm").size() > 0
&& Scan<size_t>(m_parameter->GetParam("search-algorithm")[0]) != 0) {
cerr << "Can use -constraint only with stack-based search (-search-algorithm 0)" << endl;
exit(1);
}
&& Scan<size_t>(m_parameter->GetParam("search-algorithm")[0]) != 0) {
cerr << "Can use -constraint only with stack-based search (-search-algorithm 0)" << endl;
exit(1);
}
m_constraintFileName = m_parameter->GetParam("constraint")[0];
}
InputFileStream constraintFile(m_constraintFileName);
InputFileStream constraintFile(m_constraintFileName);
std::string line;
long sentenceID = -1;
while (getline(constraintFile, line))
{
vector<string> vecStr = Tokenize(line, "\t");
std::string line;
if (vecStr.size() == 1) {
sentenceID++;
Phrase phrase(Output);
phrase.CreateFromString(GetOutputFactorOrder(), vecStr[0], GetFactorDelimiter());
m_constraints.insert(make_pair(sentenceID,phrase));
} else if (vecStr.size() == 2) {
sentenceID = Scan<long>(vecStr[0]);
Phrase phrase(Output);
phrase.CreateFromString(GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter());
m_constraints.insert(make_pair(sentenceID,phrase));
} else {
assert(false);
long sentenceID = -1;
while (getline(constraintFile, line))
{
vector<string> vecStr = Tokenize(line, "\t");
if (vecStr.size() == 1) {
sentenceID++;
Phrase phrase(Output);
phrase.CreateFromString(GetOutputFactorOrder(), vecStr[0], GetFactorDelimiter());
m_constraints.insert(make_pair(sentenceID,phrase));
}
else if (vecStr.size() == 2) {
sentenceID = Scan<long>(vecStr[0]);
Phrase phrase(Output);
phrase.CreateFromString(GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter());
m_constraints.insert(make_pair(sentenceID,phrase));
}
else {
assert(false);
}
}
}