diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-14 14:07:42 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-14 14:07:42 +0300 |
commit | 05ead45e71916c5763c5c4b6375e2ca6838f3995 (patch) | |
tree | c279bd4aacfb31758720ffbaf5aaf62022574a52 /moses/TranslationOptionCollectionLattice.cpp | |
parent | 91cb549ccf09fc33122f3d531f47c38ad0e99b3d (diff) |
beautify
Diffstat (limited to 'moses/TranslationOptionCollectionLattice.cpp')
-rw-r--r-- | moses/TranslationOptionCollectionLattice.cpp | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/moses/TranslationOptionCollectionLattice.cpp b/moses/TranslationOptionCollectionLattice.cpp index 349aa385c..d20e07fbf 100644 --- a/moses/TranslationOptionCollectionLattice.cpp +++ b/moses/TranslationOptionCollectionLattice.cpp @@ -24,7 +24,7 @@ TranslationOptionCollectionLattice::TranslationOptionCollectionLattice( : TranslationOptionCollection(input, maxNoTransOptPerCoverage, translationOptionThreshold) { UTIL_THROW_IF2(StaticData::Instance().GetUseLegacyPT(), - "Not for models using the legqacy binary phrase table"); + "Not for models using the legqacy binary phrase table"); const InputFeature &inputFeature = InputFeature::Instance(); UTIL_THROW_IF2(&inputFeature == NULL, "Input feature must be specified"); @@ -48,7 +48,7 @@ TranslationOptionCollectionLattice::TranslationOptionCollectionLattice( WordsRange range(startPos, endPos); if (range.GetNumWordsCovered() > maxPhraseLength) { - continue; + continue; } const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); @@ -73,53 +73,53 @@ TranslationOptionCollectionLattice::TranslationOptionCollectionLattice( void TranslationOptionCollectionLattice::Extend(const InputPath &prevPath, const WordLattice &input) { - size_t nextPos = prevPath.GetWordsRange().GetEndPos() + 1; - if (nextPos >= input.GetSize()) { - return; - } + size_t nextPos = prevPath.GetWordsRange().GetEndPos() + 1; + if (nextPos >= input.GetSize()) { + return; + } - size_t startPos = prevPath.GetWordsRange().GetStartPos(); - const Phrase &prevPhrase = prevPath.GetPhrase(); - const ScorePair *prevInputScore = prevPath.GetInputScore(); - UTIL_THROW_IF2(prevInputScore == NULL, - "Null previous score"); + size_t startPos = prevPath.GetWordsRange().GetStartPos(); + const Phrase &prevPhrase = prevPath.GetPhrase(); + const ScorePair *prevInputScore = prevPath.GetInputScore(); + UTIL_THROW_IF2(prevInputScore == NULL, + "Null previous score"); - const std::vector<size_t> &nextNodes = input.GetNextNodes(nextPos); + const std::vector<size_t> &nextNodes = input.GetNextNodes(nextPos); - const ConfusionNet::Column &col = input.GetColumn(nextPos); - for (size_t i = 0; i < col.size(); ++i) { - const Word &word = col[i].first; - UTIL_THROW_IF2(word.IsEpsilon(), "Epsilon not supported"); + const ConfusionNet::Column &col = input.GetColumn(nextPos); + for (size_t i = 0; i < col.size(); ++i) { + const Word &word = col[i].first; + UTIL_THROW_IF2(word.IsEpsilon(), "Epsilon not supported"); - size_t nextNode = nextNodes[i]; - size_t endPos = nextPos + nextNode - 1; + size_t nextNode = nextNodes[i]; + size_t endPos = nextPos + nextNode - 1; - WordsRange range(startPos, endPos); + WordsRange range(startPos, endPos); - size_t maxPhraseLength = StaticData::Instance().GetMaxPhraseLength(); - if (range.GetNumWordsCovered() > maxPhraseLength) { - continue; - } + size_t maxPhraseLength = StaticData::Instance().GetMaxPhraseLength(); + if (range.GetNumWordsCovered() > maxPhraseLength) { + continue; + } - const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); + const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); - Phrase subphrase(prevPhrase); - subphrase.AddWord(word); + Phrase subphrase(prevPhrase); + subphrase.AddWord(word); - const ScorePair &scores = col[i].second; - ScorePair *inputScore = new ScorePair(*prevInputScore); - inputScore->PlusEquals(scores); + const ScorePair &scores = col[i].second; + ScorePair *inputScore = new ScorePair(*prevInputScore); + inputScore->PlusEquals(scores); - InputPath *path = new InputPath(subphrase, labels, range, &prevPath, inputScore); + InputPath *path = new InputPath(subphrase, labels, range, &prevPath, inputScore); - path->SetNextNode(nextNode); - m_inputPathQueue.push_back(path); + path->SetNextNode(nextNode); + m_inputPathQueue.push_back(path); - // recursive - Extend(*path, input); + // recursive + Extend(*path, input); - } + } } void TranslationOptionCollectionLattice::CreateTranslationOptions() @@ -142,19 +142,18 @@ void TranslationOptionCollectionLattice::CreateTranslationOptions() const WordsRange &range = path.GetWordsRange(); if (tpColl && tpColl->GetSize()) { - TargetPhraseCollection::const_iterator iter; - for (iter = tpColl->begin(); iter != tpColl->end(); ++iter) { - const TargetPhrase &tp = **iter; - TranslationOption *transOpt = new TranslationOption(range, tp); - transOpt->SetInputPath(path); - transOpt->EvaluateWithSourceContext(m_source); - - Add(transOpt); - } - } - else if (path.GetPhrase().GetSize() == 1) { - // unknown word processing - ProcessOneUnknownWord(path, path.GetWordsRange().GetStartPos(), path.GetWordsRange().GetNumWordsCovered() , path.GetInputScore()); + TargetPhraseCollection::const_iterator iter; + for (iter = tpColl->begin(); iter != tpColl->end(); ++iter) { + const TargetPhrase &tp = **iter; + TranslationOption *transOpt = new TranslationOption(range, tp); + transOpt->SetInputPath(path); + transOpt->EvaluateWithSourceContext(m_source); + + Add(transOpt); + } + } else if (path.GetPhrase().GetSize() == 1) { + // unknown word processing + ProcessOneUnknownWord(path, path.GetWordsRange().GetStartPos(), path.GetWordsRange().GetNumWordsCovered() , path.GetInputScore()); } } @@ -173,16 +172,16 @@ void TranslationOptionCollectionLattice::CreateTranslationOptions() void TranslationOptionCollectionLattice::ProcessUnknownWord(size_t sourcePos) { - UTIL_THROW(util::Exception, "ProcessUnknownWord() not implemented for lattice"); + UTIL_THROW(util::Exception, "ProcessUnknownWord() not implemented for lattice"); } void TranslationOptionCollectionLattice::CreateTranslationOptionsForRange(const DecodeGraph &decodeStepList - , size_t startPosition - , size_t endPosition - , bool adhereTableLimit - , size_t graphInd) + , size_t startPosition + , size_t endPosition + , bool adhereTableLimit + , size_t graphInd) { - UTIL_THROW(util::Exception, "CreateTranslationOptionsForRange() not implemented for lattice"); + UTIL_THROW(util::Exception, "CreateTranslationOptionsForRange() not implemented for lattice"); } } // namespace |