diff --git a/moses/InputPath.cpp b/moses/InputPath.cpp index d6e78e7ae..8e75c2251 100644 --- a/moses/InputPath.cpp +++ b/moses/InputPath.cpp @@ -14,11 +14,12 @@ InputPath:: InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode, const ScorePair *inputScore) - :m_prevNode(prevNode) + :m_prevPath(prevNode) ,m_phrase(phrase) ,m_range(range) ,m_inputScore(inputScore) ,m_sourceNonTerms(sourceNonTerms) + ,m_nextNode(1) { //cerr << "phrase=" << phrase << " m_inputScore=" << *m_inputScore << endl; @@ -67,7 +68,7 @@ const Word &InputPath::GetLastWord() const std::ostream& operator<<(std::ostream& out, const InputPath& obj) { - out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevNode() << " " << obj.GetPhrase(); + out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevPath() << " " << obj.GetPhrase(); out << "pt: "; std::map >::const_iterator iter; diff --git a/moses/InputPath.h b/moses/InputPath.h index f580e2ec5..4edc54e97 100644 --- a/moses/InputPath.h +++ b/moses/InputPath.h @@ -30,10 +30,11 @@ class InputPath friend std::ostream& operator<<(std::ostream& out, const InputPath &obj); protected: - const InputPath *m_prevNode; + const InputPath *m_prevPath; Phrase m_phrase; WordsRange m_range; const ScorePair *m_inputScore; + size_t m_nextNode; // distance to next node. For lattices // for phrase-based model only std::map > m_targetPhrases; @@ -43,13 +44,13 @@ protected: const NonTerminalSet m_sourceNonTerms; - bool SetPlaceholders(TargetPhrase *targetPhrase) const; public: explicit InputPath() - : m_prevNode(NULL) + : m_prevPath(NULL) , m_range(NOT_FOUND, NOT_FOUND) - , m_inputScore(NULL) { - } + , m_inputScore(NULL) + , m_nextNode(NOT_FOUND) + {} InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode ,const ScorePair *inputScore); @@ -66,10 +67,17 @@ public: } const Word &GetLastWord() const; - const InputPath *GetPrevNode() const { - return m_prevNode; + const InputPath *GetPrevPath() const { + return m_prevPath; } + //! distance to next node in input lattice. For sentences and confusion networks, this should be 1 (default) + size_t GetNextNode() const + { return m_nextNode; } + + void SetNextNode(size_t nextNode) + { m_nextNode = nextNode; } + void SetTargetPhrases(const PhraseDictionary &phraseDictionary , const TargetPhraseCollection *targetPhrases , const void *ptNode); diff --git a/moses/TranslationModel/PhraseDictionaryMemory.cpp b/moses/TranslationModel/PhraseDictionaryMemory.cpp index 3264b0a01..352a0e241 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryMemory.cpp @@ -141,12 +141,12 @@ GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const for (iter = phraseDictionaryQueue.begin(); iter != phraseDictionaryQueue.end(); ++iter) { InputPath &node = **iter; const Phrase &phrase = node.GetPhrase(); - const InputPath *prevNode = node.GetPrevNode(); + const InputPath *prevPath = node.GetPrevPath(); const PhraseDictionaryNodeMemory *prevPtNode = NULL; - if (prevNode) { - prevPtNode = static_cast(prevNode->GetPtNode(*this)); + if (prevPath) { + prevPtNode = static_cast(prevPath->GetPtNode(*this)); } else { // Starting subphrase. assert(phrase.GetSize() == 1); diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index 7e9f694bb..b8fc434fb 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -106,7 +106,7 @@ void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(InputPath &inputPath { OnDiskPt::OnDiskWrapper &wrapper = const_cast(GetImplementation()); const Phrase &phrase = inputPath.GetPhrase(); - const InputPath *prevInputPath = inputPath.GetPrevNode(); + const InputPath *prevInputPath = inputPath.GetPrevPath(); const OnDiskPt::PhraseNode *prevPtNode = NULL; diff --git a/moses/TranslationOptionCollectionConfusionNet.cpp b/moses/TranslationOptionCollectionConfusionNet.cpp index 30aa87d78..ed116b3f7 100644 --- a/moses/TranslationOptionCollectionConfusionNet.cpp +++ b/moses/TranslationOptionCollectionConfusionNet.cpp @@ -45,10 +45,10 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet const ScorePair &scores = col[i].second; ScorePair *inputScore = new ScorePair(scores); - InputPath *node = new InputPath(subphrase, labels, range, NULL, inputScore); - list.push_back(node); + InputPath *path = new InputPath(subphrase, labels, range, NULL, inputScore); + list.push_back(path); - m_phraseDictionaryQueue.push_back(node); + m_phraseDictionaryQueue.push_back(path); } } @@ -65,17 +65,17 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet InputPathList &list = vec.back(); // loop thru every previous path - const InputPathList &prevNodes = GetInputPathList(startPos, endPos - 1); + const InputPathList &prevPaths = GetInputPathList(startPos, endPos - 1); int prevNodesInd = 0; InputPathList::const_iterator iterPath; - for (iterPath = prevNodes.begin(); iterPath != prevNodes.end(); ++iterPath) { - //for (size_t pathInd = 0; pathInd < prevNodes.size(); ++pathInd) { - const InputPath &prevNode = **iterPath; - //const InputPath &prevNode = *prevNodes[pathInd]; + for (iterPath = prevPaths.begin(); iterPath != prevPaths.end(); ++iterPath) { + //for (size_t pathInd = 0; pathInd < prevPaths.size(); ++pathInd) { + const InputPath &prevPath = **iterPath; + //const InputPath &prevPath = *prevPaths[pathInd]; - const Phrase &prevPhrase = prevNode.GetPhrase(); - const ScorePair *prevInputScore = prevNode.GetInputScore(); + const Phrase &prevPhrase = prevPath.GetPhrase(); + const ScorePair *prevInputScore = prevPath.GetInputScore(); CHECK(prevInputScore); // loop thru every word at this position @@ -90,14 +90,14 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet ScorePair *inputScore = new ScorePair(*prevInputScore); inputScore->PlusEquals(scores); - InputPath *node = new InputPath(subphrase, labels, range, &prevNode, inputScore); - list.push_back(node); + InputPath *path = new InputPath(subphrase, labels, range, &prevPath, inputScore); + list.push_back(path); - m_phraseDictionaryQueue.push_back(node); + m_phraseDictionaryQueue.push_back(path); } // for (size_t i = 0; i < col.size(); ++i) { ++prevNodesInd; - } // for (iterPath = prevNodes.begin(); iterPath != prevNodes.end(); ++iterPath) { + } // for (iterPath = prevPaths.begin(); iterPath != prevPaths.end(); ++iterPath) { } } diff --git a/moses/TranslationOptionCollectionText.cpp b/moses/TranslationOptionCollectionText.cpp index 90fbc106e..c002e0420 100644 --- a/moses/TranslationOptionCollectionText.cpp +++ b/moses/TranslationOptionCollectionText.cpp @@ -46,17 +46,17 @@ TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos))); const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos); - InputPath *node; + InputPath *path; if (range.GetNumWordsCovered() == 1) { - node = new InputPath(subphrase, labels, range, NULL, NULL); - vec.push_back(node); + path = new InputPath(subphrase, labels, range, NULL, NULL); + vec.push_back(path); } else { - const InputPath &prevNode = GetInputPath(startPos, endPos - 1); - node = new InputPath(subphrase, labels, range, &prevNode, NULL); - vec.push_back(node); + const InputPath &prevPath = GetInputPath(startPos, endPos - 1); + path = new InputPath(subphrase, labels, range, &prevPath, NULL); + vec.push_back(path); } - m_phraseDictionaryQueue.push_back(node); + m_phraseDictionaryQueue.push_back(path); } } }