mosesdecoder/moses/InputPath.h

116 lines
3.0 KiB
C
Raw Normal View History

#pragma once
#include <map>
#include <iostream>
#include <vector>
#include "Phrase.h"
#include "WordsRange.h"
#include "NonTerminal.h"
#include "moses/FactorCollection.h"
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;
class InputPath;
2013-09-22 20:24:32 +04:00
struct ScorePair;
2013-09-08 17:57:31 +04:00
typedef std::vector<InputPath*> InputPathList;
/** 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
This is for both sentence input, and confusion network/lattices
*/
2013-07-07 05:14:51 +04:00
class InputPath
{
2013-07-07 05:14:51 +04:00
friend std::ostream& operator<<(std::ostream& out, const InputPath &obj);
public:
typedef std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> > TargetPhrases;
protected:
2013-10-02 19:51:16 +04:00
const InputPath *m_prevPath;
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-09-22 18:15:00 +04:00
// for phrase-based model only
TargetPhrases m_targetPhrases;
2013-09-22 18:15:00 +04:00
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;
std::vector<bool> m_sourceNonTermArray;
2013-09-22 18:15:00 +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)
2015-01-14 14:07:42 +03:00
, m_nextNode(NOT_FOUND) {
}
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();
const Phrase &GetPhrase() const {
return m_phrase;
}
const NonTerminalSet &GetNonTerminalSet() const {
return m_sourceNonTerms;
}
const std::vector<bool> &GetNonTerminalArray() const {
return m_sourceNonTermArray;
}
const WordsRange &GetWordsRange() const {
return m_range;
}
const Word &GetLastWord() const;
2013-10-02 19:51:16 +04:00
const InputPath *GetPrevPath() const {
return m_prevPath;
}
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
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);
const TargetPhraseCollection *GetTargetPhrases(const PhraseDictionary &phraseDictionary) const;
2014-01-15 19:42:02 +04:00
const TargetPhrases &GetTargetPhrases() const {
return m_targetPhrases;
}
2013-07-18 23:23:44 +04:00
// pointer to internal node in phrase-table. Since this is implementation dependent, this is a void*
const void *GetPtNode(const PhraseDictionary &phraseDictionary) const;
2013-09-08 17:57:31 +04:00
const ScorePair *GetInputScore() const {
return m_inputScore;
}
2014-04-30 23:20:07 +04:00
size_t GetTotalRuleSize() const;
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
}
};
};