mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
bugfixes in VW: correct string escaping, avoid infinite loop with missing alignments
This commit is contained in:
parent
1ef31ddee3
commit
542a65a16e
@ -211,12 +211,21 @@ private:
|
||||
|
||||
bool IsCorrectTranslationOption(const TranslationOption &topt) const {
|
||||
size_t sourceStart = topt.GetSourceWordsRange().GetStartPos();
|
||||
size_t sourceEnd = topt.GetSourceWordsRange().GetEndPos() + 1;
|
||||
|
||||
const VWTargetSentence &targetSentence = *GetStored();
|
||||
|
||||
// get the left-most alignment point withitn sourceRange
|
||||
std::set<size_t> aligned;
|
||||
while ((aligned = targetSentence.m_alignment->GetAlignmentsForSource(sourceStart)).empty())
|
||||
while ((aligned = targetSentence.m_alignment->GetAlignmentsForSource(sourceStart)).empty()) {
|
||||
sourceStart++;
|
||||
|
||||
if (sourceStart >= sourceEnd) {
|
||||
// no alignment point between source and target sentence within current source span;
|
||||
// return immediately
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t targetSentOffset = *aligned.begin(); // index of first aligned target word covered in source span
|
||||
|
||||
|
@ -73,7 +73,7 @@ protected:
|
||||
static std::string EscapeSpecialChars(const std::string &str)
|
||||
{
|
||||
std::string out;
|
||||
out = Moses::Replace(str, "\\", "\\\\");
|
||||
out = Moses::Replace(str, "\\", "_/_");
|
||||
out = Moses::Replace(out, "|", "\\/");
|
||||
out = Moses::Replace(out, ":", "\\;");
|
||||
out = Moses::Replace(out, " ", "\\_");
|
||||
@ -113,7 +113,6 @@ private:
|
||||
std::deque<std::string> m_outputBuffer;
|
||||
|
||||
void WriteBuffer();
|
||||
std::string EscapeSpecialChars(const std::string &str);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -80,13 +80,4 @@ void VWTrainer::WriteBuffer()
|
||||
m_outputBuffer.clear();
|
||||
}
|
||||
|
||||
std::string VWTrainer::EscapeSpecialChars(const std::string &str)
|
||||
{
|
||||
string out;
|
||||
out = Replace(str, "|", "_PIPE_");
|
||||
out = Replace(out, ":", "_COLON_");
|
||||
out = Replace(out, " ", "_");
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Discriminative
|
||||
|
Loading…
Reference in New Issue
Block a user