bugfixes in VW: correct string escaping, avoid infinite loop with missing alignments

This commit is contained in:
Ales Tamchyna 2015-01-12 14:22:54 +01:00
parent 1ef31ddee3
commit 542a65a16e
3 changed files with 11 additions and 12 deletions

View File

@ -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

View File

@ -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);
};
/**

View File

@ -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