Make Phrase::CreateFromString() more efficient

This commit is contained in:
Hieu Hoang 2013-05-22 12:28:32 +01:00
parent 369e3411f9
commit bce3b36170
4 changed files with 10 additions and 10 deletions

View File

@ -156,7 +156,7 @@ void Phrase::CreateFromString(FactorDirection direction
,const std::vector<FactorType> &factorOrder ,const std::vector<FactorType> &factorOrder
,const StringPiece &phraseString ,const StringPiece &phraseString
,const StringPiece &factorDelimiter ,const StringPiece &factorDelimiter
,Word *lhs) ,Word **lhs)
{ {
// parse // parse
vector<StringPiece> annotatedWordVector; vector<StringPiece> annotatedWordVector;
@ -181,8 +181,8 @@ void Phrase::CreateFromString(FactorDirection direction
// lhs // lhs
CHECK(lhs); CHECK(lhs);
lhs->CreateFromString(direction, factorOrder, annotatedWord.substr(1, annotatedWord.size() - 2), true); (*lhs)->CreateFromString(direction, factorOrder, annotatedWord.substr(1, annotatedWord.size() - 2), true);
assert(lhs->IsNonTerminal()); assert((*lhs)->IsNonTerminal());
} }
else { else {
//CHECK(lhs == NULL); //CHECK(lhs == NULL);

View File

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

View File

@ -220,12 +220,12 @@ bool RuleTableLoaderStandard::Load(FormatType format
// parse source & find pt node // parse source & find pt node
// constituent labels // constituent labels
Word sourceLHS; Word *sourceLHS = new Word(true);
Word *targetLHS = new Word(true); Word *targetLHS = new Word(true);
// create target phrase obj // create target phrase obj
TargetPhrase *targetPhrase = new TargetPhrase(); TargetPhrase *targetPhrase = new TargetPhrase();
targetPhrase->CreateFromString(Output, output, targetPhraseString, factorDelimiter, targetLHS); targetPhrase->CreateFromString(Output, output, targetPhraseString, factorDelimiter, &targetLHS);
// source // source
targetPhrase->MutableSourcePhrase().CreateFromString(Input, input, sourcePhraseString, factorDelimiter, &sourceLHS); targetPhrase->MutableSourcePhrase().CreateFromString(Input, input, sourcePhraseString, factorDelimiter, &sourceLHS);
@ -244,7 +244,7 @@ bool RuleTableLoaderStandard::Load(FormatType format
targetPhrase->GetScoreBreakdown().Assign(&ruleTable, scoreVector); targetPhrase->GetScoreBreakdown().Assign(&ruleTable, scoreVector);
targetPhrase->Evaluate(); targetPhrase->Evaluate();
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, targetPhrase->GetSourcePhrase(), *targetPhrase, sourceLHS); TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, targetPhrase->GetSourcePhrase(), *targetPhrase, *sourceLHS);
phraseColl.Add(targetPhrase); phraseColl.Add(targetPhrase);
count++; count++;

View File

@ -217,7 +217,7 @@ namespace Moses
// parse source & find pt node // parse source & find pt node
// constituent labels // constituent labels
Word sourceLHS; Word *sourceLHS = new Word(true);
Word *targetLHS = new Word(true); Word *targetLHS = new Word(true);
// source // source
@ -226,7 +226,7 @@ namespace Moses
// create target phrase obj // create target phrase obj
TargetPhrase *targetPhrase = new TargetPhrase(); TargetPhrase *targetPhrase = new TargetPhrase();
targetPhrase->CreateFromString(Output, *m_output, targetPhraseString, factorDelimiter, targetLHS); targetPhrase->CreateFromString(Output, *m_output, targetPhraseString, factorDelimiter, &targetLHS);
// rest of target phrase // rest of target phrase
targetPhrase->SetAlignmentInfo(alignString); targetPhrase->SetAlignmentInfo(alignString);
@ -240,7 +240,7 @@ namespace Moses
targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
targetPhrase->Evaluate(); targetPhrase->Evaluate();
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, sourceLHS); TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, *sourceLHS);
phraseColl.Add(targetPhrase); phraseColl.Add(targetPhrase);
count++; count++;