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: 75e05d7899979e5d9d669b07bd6ad77389b99323 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2  -*-
#pragma once

#include <map>
#include <iostream>
#include <vector>
#include "Phrase.h"
#include "Range.h"
#include "NonTerminal.h"
#include "moses/FactorCollection.h"
#include <boost/shared_ptr.hpp>
#include "TargetPhraseCollection.h"
namespace Moses
{

class PhraseDictionary;
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::pair<TargetPhraseCollection::shared_ptr, const void*>
  TPCollStoreEntry;

  typedef std::map<const PhraseDictionary*, TPCollStoreEntry>
  TargetPhrases;

public:
  // ttaskwptr const ttask;
  TranslationTask const* ttask;
protected:
  const InputPath *m_prevPath;
  Phrase m_phrase;
  Range 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(TranslationTask const* ttask, // ttaskwptr const ttask,
            Phrase const& phrase,
            NonTerminalSet const& sourceNonTerms,
            Range const& range,
            InputPath const* prevNode,
            ScorePair const* 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 Range &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,
                   TargetPhraseCollection::shared_ptr const& targetPhrases,
                   const void *ptNode);

  TargetPhraseCollection::shared_ptr
  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();
  }

};

};