Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InputPath.h « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c67d88795ce3b08cbafdef69c1fe080f408f9517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#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;
class ScoreComponentCollection;
class TargetPhrase;
class InputPath;
struct ScorePair;

typedef std::vector<InputPath*> 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<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> > 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<std::vector<const Word*> > m_ruleSourceFromInputPath;
  const NonTerminalSet m_sourceNonTerms;
  std::vector<bool> 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<bool> &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<const Word*> &AddRuleSourceFromInputPath() const {
    m_ruleSourceFromInputPath.push_back(std::vector<const Word*>());
    return m_ruleSourceFromInputPath.back();
  }

};

};