2013-07-02 02:27:13 +04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2013-07-03 22:07:36 +04:00
|
|
|
#include <iostream>
|
2013-10-03 19:58:47 +04:00
|
|
|
#include <vector>
|
2013-07-02 02:27:13 +04:00
|
|
|
#include "Phrase.h"
|
|
|
|
#include "WordsRange.h"
|
2013-08-02 18:54:49 +04:00
|
|
|
#include "NonTerminal.h"
|
2013-07-02 02:27:13 +04:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
class PhraseDictionary;
|
|
|
|
class TargetPhraseCollection;
|
2013-07-09 01:47:02 +04:00
|
|
|
class ScoreComponentCollection;
|
2013-07-19 20:41:52 +04:00
|
|
|
class TargetPhrase;
|
2013-07-09 17:19:35 +04:00
|
|
|
class InputPath;
|
2013-09-22 20:24:32 +04:00
|
|
|
struct ScorePair;
|
2013-09-08 17:57:31 +04:00
|
|
|
|
2013-10-03 19:58:47 +04:00
|
|
|
typedef std::vector<InputPath*> InputPathList;
|
2013-07-09 17:19:35 +04:00
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
/** Each node contains
|
|
|
|
1. substring used to searching the phrase table
|
|
|
|
2. the source range it covers
|
2013-07-07 05:14:51 +04:00
|
|
|
3. a list of InputPath that it is a prefix of
|
2013-07-02 02:27:13 +04:00
|
|
|
This is for both sentence input, and confusion network/lattices
|
|
|
|
*/
|
2013-07-07 05:14:51 +04:00
|
|
|
class InputPath
|
2013-07-02 02:27:13 +04:00
|
|
|
{
|
2013-07-07 05:14:51 +04:00
|
|
|
friend std::ostream& operator<<(std::ostream& out, const InputPath &obj);
|
2013-07-03 22:07:36 +04:00
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
protected:
|
2013-10-02 19:51:16 +04:00
|
|
|
const InputPath *m_prevPath;
|
2013-07-02 02:27:13 +04:00
|
|
|
Phrase m_phrase;
|
|
|
|
WordsRange m_range;
|
2013-09-08 17:57:31 +04:00
|
|
|
const ScorePair *m_inputScore;
|
2013-10-02 19:51:16 +04:00
|
|
|
size_t m_nextNode; // distance to next node. For lattices
|
2013-07-02 02:27:13 +04:00
|
|
|
|
2013-09-22 18:15:00 +04:00
|
|
|
// for phrase-based model only
|
|
|
|
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> > m_targetPhrases;
|
|
|
|
|
2013-09-28 22:06:04 +04:00
|
|
|
// for syntax model only
|
2013-09-22 18:15:00 +04:00
|
|
|
mutable std::vector<std::vector<const Word*> > m_ruleSourceFromInputPath;
|
2013-09-28 22:06:04 +04:00
|
|
|
const NonTerminalSet m_sourceNonTerms;
|
2013-09-22 18:15:00 +04:00
|
|
|
|
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
public:
|
2013-07-07 05:14:51 +04:00
|
|
|
explicit InputPath()
|
2013-10-02 19:51:16 +04:00
|
|
|
: m_prevPath(NULL)
|
2013-07-09 01:47:02 +04:00
|
|
|
, m_range(NOT_FOUND, NOT_FOUND)
|
2013-10-02 19:51:16 +04:00
|
|
|
, m_inputScore(NULL)
|
|
|
|
, m_nextNode(NOT_FOUND)
|
|
|
|
{}
|
2013-07-04 12:24:13 +04:00
|
|
|
|
2013-08-02 18:54:49 +04:00
|
|
|
InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode
|
2013-09-08 17:57:31 +04:00
|
|
|
,const ScorePair *inputScore);
|
2013-07-09 01:47:02 +04:00
|
|
|
~InputPath();
|
2013-07-02 02:27:13 +04:00
|
|
|
|
|
|
|
const Phrase &GetPhrase() const {
|
|
|
|
return m_phrase;
|
|
|
|
}
|
2013-08-02 18:54:49 +04:00
|
|
|
const NonTerminalSet &GetNonTerminalSet() const {
|
|
|
|
return m_sourceNonTerms;
|
|
|
|
}
|
2013-07-02 02:27:13 +04:00
|
|
|
const WordsRange &GetWordsRange() const {
|
|
|
|
return m_range;
|
|
|
|
}
|
2013-07-30 18:28:20 +04:00
|
|
|
const Word &GetLastWord() const;
|
|
|
|
|
2013-10-02 19:51:16 +04:00
|
|
|
const InputPath *GetPrevPath() const {
|
|
|
|
return m_prevPath;
|
2013-07-03 22:07:36 +04:00
|
|
|
}
|
2013-07-02 02:27:13 +04:00
|
|
|
|
2013-10-02 19:51:16 +04:00
|
|
|
//! distance to next node in input lattice. For sentences and confusion networks, this should be 1 (default)
|
2013-10-03 14:33:48 +04:00
|
|
|
size_t GetNextNode() const {
|
|
|
|
return m_nextNode;
|
|
|
|
}
|
2013-10-02 19:51:16 +04:00
|
|
|
|
2013-10-03 14:33:48 +04:00
|
|
|
void SetNextNode(size_t nextNode) {
|
|
|
|
m_nextNode = nextNode;
|
|
|
|
}
|
2013-10-02 19:51:16 +04:00
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
void SetTargetPhrases(const PhraseDictionary &phraseDictionary
|
2013-07-05 02:38:18 +04:00
|
|
|
, const TargetPhraseCollection *targetPhrases
|
2013-07-18 23:23:44 +04:00
|
|
|
, const void *ptNode);
|
2013-07-02 02:27:13 +04:00
|
|
|
const TargetPhraseCollection *GetTargetPhrases(const PhraseDictionary &phraseDictionary) const;
|
2013-07-18 23:23:44 +04:00
|
|
|
|
|
|
|
// pointer to internal node in phrase-table. Since this is implementation dependent, this is a void*
|
2013-07-03 22:07:36 +04:00
|
|
|
const void *GetPtNode(const PhraseDictionary &phraseDictionary) const;
|
2013-09-08 17:57:31 +04:00
|
|
|
const ScorePair *GetInputScore() const {
|
2013-07-09 19:56:49 +04:00
|
|
|
return m_inputScore;
|
|
|
|
}
|
2013-07-02 02:27:13 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
std::vector<const Word*> &AddRuleSourceFromInputPath() const {
|
|
|
|
m_ruleSourceFromInputPath.push_back(std::vector<const Word*>());
|
|
|
|
return m_ruleSourceFromInputPath.back();
|
2013-09-22 18:15:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 02:27:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|