#pragma once #include #include #include #include "Phrase.h" #include "WordsRange.h" #include "NonTerminal.h" #include "moses/FactorCollection.h" namespace Moses { class PhraseDictionary; class TargetPhraseCollection; class ScoreComponentCollection; class TargetPhrase; class InputPath; struct ScorePair; typedef std::vector InputPathList; /** Each node contains 1. substring used to searching the phrase table 2. the source range it covers 3. a list of InputPath that it is a prefix of This is for both sentence input, and confusion network/lattices */ class InputPath { friend std::ostream& operator<<(std::ostream& out, const InputPath &obj); public: typedef std::map > TargetPhrases; protected: 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 TargetPhrases m_targetPhrases; // for syntax model only mutable std::vector > m_ruleSourceFromInputPath; const NonTerminalSet m_sourceNonTerms; std::vector m_sourceNonTermArray; public: explicit InputPath() : m_prevPath(NULL) , m_range(NOT_FOUND, NOT_FOUND) , m_inputScore(NULL) , m_nextNode(NOT_FOUND) { } InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode ,const ScorePair *inputScore); ~InputPath(); const Phrase &GetPhrase() const { return m_phrase; } const NonTerminalSet &GetNonTerminalSet() const { return m_sourceNonTerms; } const std::vector &GetNonTerminalArray() const { return m_sourceNonTermArray; } const WordsRange &GetWordsRange() const { return m_range; } const Word &GetLastWord() const; 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); const TargetPhraseCollection *GetTargetPhrases(const PhraseDictionary &phraseDictionary) const; const TargetPhrases &GetTargetPhrases() const { return m_targetPhrases; } // pointer to internal node in phrase-table. Since this is implementation dependent, this is a void* const void *GetPtNode(const PhraseDictionary &phraseDictionary) const; const ScorePair *GetInputScore() const { return m_inputScore; } size_t GetTotalRuleSize() const; std::vector &AddRuleSourceFromInputPath() const { m_ruleSourceFromInputPath.push_back(std::vector()); return m_ruleSourceFromInputPath.back(); } }; };