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

View File

@ -75,7 +75,7 @@ public:
, const std::vector<FactorType> &factorOrder
, const StringPiece &phraseString
, const StringPiece &factorDelimiter
, Word *lhs);
, 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

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

View File

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