refactoring to minimize overhead from flexibility score code (if off)

This commit is contained in:
Rico Sennrich 2013-09-07 23:04:20 +02:00
parent 7138056b8f
commit b421f7c9b0

View File

@ -706,8 +706,6 @@ void ExtractTask::addPhrase( SentenceAlignment &sentence, int startE, int endE,
ostringstream outextractstr;
ostringstream outextractstrInv;
ostringstream outextractstrOrientation;
ostringstream outextractstrContext;
ostringstream outextractstrContextInv;
if (m_options.isOnlyOutputSpanInfo()) {
cout << startF << " " << endF << " " << startE << " " << endE << endl;
@ -721,25 +719,19 @@ void ExtractTask::addPhrase( SentenceAlignment &sentence, int startE, int endE,
for(int fi=startF; fi<=endF; fi++) {
if (m_options.isTranslationFlag()) outextractstr << sentence.source[fi] << " ";
if (m_options.isOrientationFlag()) outextractstrOrientation << sentence.source[fi] << " ";
if (m_options.isFlexScoreFlag()) outextractstrContext << sentence.source[fi] << " ";
}
if (m_options.isTranslationFlag()) outextractstr << "||| ";
if (m_options.isOrientationFlag()) outextractstrOrientation << "||| ";
if (m_options.isFlexScoreFlag()) outextractstrContext << "||| ";
// target
for(int ei=startE; ei<=endE; ei++) {
if (m_options.isTranslationFlag()) outextractstr << sentence.target[ei] << " ";
if (m_options.isTranslationFlag()) outextractstrInv << sentence.target[ei] << " ";
if (m_options.isOrientationFlag()) outextractstrOrientation << sentence.target[ei] << " ";
if (m_options.isFlexScoreFlag()) outextractstrContext << sentence.target[ei] << " ";
if (m_options.isFlexScoreFlag()) outextractstrContextInv << sentence.target[ei] << " ";
}
if (m_options.isTranslationFlag()) outextractstr << "|||";
if (m_options.isTranslationFlag()) outextractstrInv << "||| ";
if (m_options.isOrientationFlag()) outextractstrOrientation << "||| ";
if (m_options.isFlexScoreFlag()) outextractstrContext << "||| ";
if (m_options.isFlexScoreFlag()) outextractstrContextInv << "||| ";
// source (for inverse)
@ -748,11 +740,6 @@ void ExtractTask::addPhrase( SentenceAlignment &sentence, int startE, int endE,
outextractstrInv << sentence.source[fi] << " ";
outextractstrInv << "|||";
}
if (m_options.isFlexScoreFlag()) {
for(int fi=startF; fi<=endF; fi++)
outextractstrContextInv << sentence.source[fi] << " ";
outextractstrContextInv << "|||";
}
// alignment
if (m_options.isTranslationFlag()) {
@ -788,6 +775,27 @@ void ExtractTask::addPhrase( SentenceAlignment &sentence, int startE, int endE,
// once with left, once with right context
if (m_options.isFlexScoreFlag()) {
ostringstream outextractstrContext;
ostringstream outextractstrContextInv;
for(int fi=startF; fi<=endF; fi++) {
outextractstrContext << sentence.source[fi] << " ";
}
outextractstrContext << "||| ";
// target
for(int ei=startE; ei<=endE; ei++) {
outextractstrContext << sentence.target[ei] << " ";
outextractstrContextInv << sentence.target[ei] << " ";
}
outextractstrContext << "||| ";
outextractstrContextInv << "||| ";
for(int fi=startF; fi<=endF; fi++)
outextractstrContextInv << sentence.source[fi] << " ";
outextractstrContextInv << "|||";
string strContext = outextractstrContext.str();
string strContextInv = outextractstrContextInv.str();
@ -862,8 +870,10 @@ void ExtractTask::writePhrasesToFile()
m_extractFile << outextractFile.str();
m_extractFileInv << outextractFileInv.str();
m_extractFileOrientation << outextractFileOrientation.str();
m_extractFileContext << outextractFileContext.str();
m_extractFileContextInv << outextractFileContextInv.str();
if (m_options.isFlexScoreFlag()) {
m_extractFileContext << outextractFileContext.str();
m_extractFileContextInv << outextractFileContextInv.str();
}
}
// if proper conditioning, we need the number of times a source phrase occured