minor error. Segfault if phrase length is bigger than max-phrase-length

This commit is contained in:
Hieu Hoang 2014-05-01 16:47:17 +01:00
parent d4b270e796
commit 2beed771d2
6 changed files with 27 additions and 8 deletions

View File

@ -1781,6 +1781,16 @@
<type>1</type> <type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/SkeletonPT.h</locationURI> <locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/SkeletonPT.h</locationURI>
</link> </link>
<link>
<name>TranslationModel/UnknownWordPenalty2.cpp</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/UnknownWordPenalty2.cpp</locationURI>
</link>
<link>
<name>TranslationModel/UnknownWordPenalty2.h</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationModel/UnknownWordPenalty2.h</locationURI>
</link>
<link> <link>
<name>TranslationModel/WordCoocTable.cpp</name> <name>TranslationModel/WordCoocTable.cpp</name>
<type>1</type> <type>1</type>

View File

@ -102,14 +102,6 @@ void Manager::ProcessSentence()
} }
m_transOptColl->CreateTranslationOptions(); m_transOptColl->CreateTranslationOptions();
for (size_t i = 0; i < m_transOptColl->GetInputPaths().size(); ++i) {
const InputPath &path = *m_transOptColl->GetInputPaths()[i];
if (path.GetTotalRuleSize()) {
cerr << "path=" << path << endl;
}
}
// some reporting on how long this took // some reporting on how long this took
IFVERBOSE(1) { IFVERBOSE(1) {
GetSentenceStats().StopTimeCollectOpts(); GetSentenceStats().StopTimeCollectOpts();

View File

@ -610,6 +610,12 @@ void TranslationOptionCollection::CreateXmlOptionsForRange(size_t, size_t)
void TranslationOptionCollection::Add(TranslationOption *translationOption) void TranslationOptionCollection::Add(TranslationOption *translationOption)
{ {
const WordsRange &coverage = translationOption->GetSourceWordsRange(); const WordsRange &coverage = translationOption->GetSourceWordsRange();
if (coverage.GetEndPos() - coverage.GetStartPos() >= m_collection[coverage.GetStartPos()].size()) {
cerr << "translationOption=" << *translationOption << endl;
cerr << "coverage=" << coverage << endl;
}
UTIL_THROW_IF2(coverage.GetEndPos() - coverage.GetStartPos() >= m_collection[coverage.GetStartPos()].size(), UTIL_THROW_IF2(coverage.GetEndPos() - coverage.GetStartPos() >= m_collection[coverage.GetStartPos()].size(),
"Out of bound access: " << coverage); "Out of bound access: " << coverage);
m_collection[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()].Add(translationOption); m_collection[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()].Add(translationOption);

View File

@ -46,6 +46,11 @@ TranslationOptionCollectionLattice::TranslationOptionCollectionLattice(
size_t endPos = startPos + nextNode - 1; size_t endPos = startPos + nextNode - 1;
WordsRange range(startPos, endPos); WordsRange range(startPos, endPos);
if (range.GetNumWordsCovered() > maxPhraseLength) {
continue;
}
const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos);
Phrase subphrase; Phrase subphrase;
@ -91,6 +96,12 @@ void TranslationOptionCollectionLattice::Extend(const InputPath &prevPath, const
size_t endPos = nextPos + nextNode - 1; size_t endPos = nextPos + nextNode - 1;
WordsRange range(startPos, endPos); WordsRange range(startPos, endPos);
size_t maxPhraseLength = StaticData::Instance().GetMaxPhraseLength();
if (range.GetNumWordsCovered() > maxPhraseLength) {
continue;
}
const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos);
Phrase subphrase(prevPhrase); Phrase subphrase(prevPhrase);