Make Phrase::CreateFromString() more efficient

This commit is contained in:
Hieu Hoang 2013-05-22 12:03:00 +01:00
parent f4a75b30f7
commit 112bcdc925
10 changed files with 16 additions and 16 deletions

View File

@ -87,9 +87,9 @@ int main(int argc, char** argv)
c_mask.push_back(0);
}
Phrase e( 0),f(0),c(0);
e.CreateFromString(Output, e_mask, query_e, "|");
f.CreateFromString(Input, f_mask, query_f, "|");
c.CreateFromString(Input, c_mask, query_c,"|");
e.CreateFromString(Output, e_mask, query_e, "|", NULL);
f.CreateFromString(Input, f_mask, query_f, "|", NULL);
c.CreateFromString(Input, c_mask, query_c,"|", NULL);
LexicalReorderingTable* table;
if(FileExists(inFilePath+".binlexr.idx")) {
std::cerr << "Loading binary table...\n";

View File

@ -66,7 +66,7 @@ int main(int argc, char **argv)
std::string line;
while(getline(std::cin, line)) {
Phrase sourcePhrase;
sourcePhrase.CreateFromString(Input, input, line, "||dummy_string||");
sourcePhrase.CreateFromString(Input, input, line, "||dummy_string||", NULL);
TargetPhraseVectorPtr decodedPhraseColl
= pdc.GetTargetPhraseCollectionRaw(sourcePhrase);

View File

@ -63,7 +63,7 @@ MockHypothesisGuard::MockHypothesisGuard(
Hypothesis* prevHypo = m_hypothesis;
WordsRange wordsRange(ai->first,ai->second);
m_targetPhrases.push_back(TargetPhrase());
m_targetPhrases.back().CreateFromString(Input, factors, *ti, "|");
m_targetPhrases.back().CreateFromString(Input, factors, *ti, "|", NULL);
m_toptions.push_back(new TranslationOption
(wordsRange,m_targetPhrases.back()));
m_hypothesis = Hypothesis::Create(*prevHypo,*m_toptions.back(),NULL);

View File

@ -75,7 +75,7 @@ public:
, const std::vector<FactorType> &factorOrder
, const StringPiece &phraseString
, const StringPiece &factorDelimiter
, Word *lhs = NULL);
, Word *lhs);
/** copy factors from the other phrase to this phrase.
IsCompatible() must be run beforehand to ensure incompatible factors aren't overwritten

View File

@ -123,7 +123,7 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)
throw runtime_error(msg);
}
}
Phrase::CreateFromString(Input, factorOrder, line, factorDelimiter);
Phrase::CreateFromString(Input, factorOrder, line, factorDelimiter, NULL);
if (staticData.IsChart()) {
InitStartEndWord();
@ -229,7 +229,7 @@ void Sentence::CreateFromString(const std::vector<FactorType> &factorOrder
, const std::string &phraseString
, const std::string &factorDelimiter)
{
Phrase::CreateFromString(Input, factorOrder, phraseString, factorDelimiter);
Phrase::CreateFromString(Input, factorOrder, phraseString, factorDelimiter, NULL);
}

View File

@ -515,12 +515,12 @@ bool StaticData::LoadData(Parameter *parameter)
if (vecStr.size() == 1) {
sentenceID++;
Phrase phrase(0);
phrase.CreateFromString(Output, GetOutputFactorOrder(), vecStr[0], GetFactorDelimiter());
phrase.CreateFromString(Output, GetOutputFactorOrder(), vecStr[0], GetFactorDelimiter(), NULL);
m_constraints.insert(make_pair(sentenceID,phrase));
} else if (vecStr.size() == 2) {
sentenceID = Scan<long>(vecStr[0]);
Phrase phrase(0);
phrase.CreateFromString(Output, GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter());
phrase.CreateFromString(Output, GetOutputFactorOrder(), vecStr[1], GetFactorDelimiter(), NULL);
m_constraints.insert(make_pair(sentenceID,phrase));
} else {
CHECK(false);

View File

@ -47,7 +47,7 @@ TargetPhrase::TargetPhrase( std::string out_string)
//ACAT
const StaticData &staticData = StaticData::Instance();
CreateFromString(Output, staticData.GetInputFactorOrder(), out_string, staticData.GetFactorDelimiter());
CreateFromString(Output, staticData.GetInputFactorOrder(), out_string, staticData.GetFactorDelimiter(), NULL);
}
TargetPhrase::TargetPhrase()

View File

@ -226,7 +226,7 @@ int BilingualDynSuffixArray::LoadCorpus(FactorDirection direction, InputFileStre
sntArray.push_back(sntIdx);
Phrase phrase(ARRAY_SIZE_INCR);
// parse phrase
phrase.CreateFromString(direction, factors, line, factorDelimiter);
phrase.CreateFromString(direction, factors, line, factorDelimiter, NULL);
// store words in vocabulary and corpus
for( size_t i = 0; i < phrase.GetSize(); ++i) {
cArray.push_back( vocab->GetWordID(phrase.GetWord(i)) );
@ -499,7 +499,7 @@ void BilingualDynSuffixArray::addSntPair(string& source, string& target, string&
const unsigned oldSrcCrpSize = m_srcCorpus->size(), oldTrgCrpSize = m_trgCorpus->size();
cerr << "old source corpus size = " << oldSrcCrpSize << "\told target size = " << oldTrgCrpSize << endl;
Phrase sphrase(ARRAY_SIZE_INCR);
sphrase.CreateFromString(Input, m_inputFactors, source, factorDelimiter);
sphrase.CreateFromString(Input, m_inputFactors, source, factorDelimiter, NULL);
m_srcVocab->MakeOpen();
std::vector<wordID_t> sIDs(sphrase.GetSize());
// store words in vocabulary and corpus
@ -514,7 +514,7 @@ void BilingualDynSuffixArray::addSntPair(string& source, string& target, string&
m_srcSntBreaks.push_back(oldSrcCrpSize); // former end of corpus is index of new sentence
m_srcVocab->MakeClosed();
Phrase tphrase(ARRAY_SIZE_INCR);
tphrase.CreateFromString(Output, m_outputFactors, target, factorDelimiter);
tphrase.CreateFromString(Output, m_outputFactors, target, factorDelimiter, NULL);
m_trgVocab->MakeOpen();
std::vector<wordID_t> tIDs(tphrase.GetSize());
for(int i = tphrase.GetSize()-1; i >= 0; --i) {

View File

@ -169,7 +169,7 @@ bool TreeInput::ProcessAndStripXMLTags(string &line, std::vector<XMLParseOutput>
for (size_t i=0; i<altTexts.size(); ++i) {
// set target phrase
TargetPhrase targetPhrase;
targetPhrase.CreateFromString(Output, outputFactorOrder,altTexts[i],factorDelimiter);
targetPhrase.CreateFromString(Output, outputFactorOrder,altTexts[i],factorDelimiter, NULL);
// set constituent label
string targetLHSstr;

View File

@ -341,7 +341,7 @@ bool ProcessAndStripXMLTags(string &line, vector<XmlOption*> &res, ReorderingCon
WordsRange range(startPos,endPos-1); // span covered by phrase
TargetPhrase targetPhrase;
targetPhrase.CreateFromString(Output, outputFactorOrder,altTexts[i],factorDelimiter);
targetPhrase.CreateFromString(Output, outputFactorOrder,altTexts[i],factorDelimiter, NULL);
targetPhrase.SetXMLScore(scoreValue);
targetPhrase.Evaluate();