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

DotChartOnDisk.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4473b7685af939987f0aa3db7803a49d8ce1841f (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// $Id$
/***********************************************************************
 Moses - factored phrase-based language decoder
 Copyright (C) 2010 Hieu Hoang

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 ***********************************************************************/
#pragma once

#include <vector>
#include "util/check.hh"

#include "DotChart.h"

namespace OnDiskPt
{
class PhraseNode;
}


namespace Moses
{
class DottedRuleOnDisk : public DottedRule
{
 public:
  // used only to init dot stack.
  explicit DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode)
      : DottedRule()
      , m_lastNode(lastNode)
      , m_done(false) {}

  DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode,
                   const ChartCellLabel &cellLabel,
                   const DottedRuleOnDisk &prev)
      : DottedRule(cellLabel, prev)
      , m_lastNode(lastNode)
      , m_done(false) {}

  const OnDiskPt::PhraseNode &GetLastNode() const { return m_lastNode; }

  bool Done() const { return m_done; }
  void Done(bool value) const { m_done = value; }

 private:
  const OnDiskPt::PhraseNode &m_lastNode;
  mutable bool m_done;
};

class DottedRuleCollOnDisk
{
  friend std::ostream& operator<<(std::ostream&, const DottedRuleCollOnDisk&);

protected:
  typedef std::vector<const DottedRuleOnDisk*> CollType;
  CollType m_coll;

public:
  typedef CollType::iterator iterator;
  typedef CollType::const_iterator const_iterator;

  const_iterator begin() const {
    return m_coll.begin();
  }
  const_iterator end() const {
    return m_coll.end();
  }
  iterator begin() {
    return m_coll.begin();
  }
  iterator end() {
    return m_coll.end();
  }

  const DottedRuleOnDisk &Get(size_t ind) const {
    return *m_coll[ind];
  }

  void Add(const DottedRuleOnDisk *dottedRule) {
    m_coll.push_back(dottedRule);
  }
  void Delete(size_t ind) {
    //delete m_coll[ind];
    m_coll.erase(m_coll.begin() + ind);
  }

  size_t GetSize() const {
    return m_coll.size();
  }

};

class SavedNodeOnDisk
{
  const DottedRuleOnDisk *m_dottedRule;

public:
  SavedNodeOnDisk(const DottedRuleOnDisk *dottedRule)
    :m_dottedRule(dottedRule) {
    CHECK(m_dottedRule);
  }

  ~SavedNodeOnDisk() {
    delete m_dottedRule;
  }

  const DottedRuleOnDisk &GetDottedRule() const {
    return *m_dottedRule;
  }
};

class DottedRuleStackOnDisk
{
  // coll of coll of processed rules
public:
  typedef std::vector<SavedNodeOnDisk*> SavedNodeColl;

protected:
  typedef std::vector<DottedRuleCollOnDisk*> CollType;
  CollType m_coll;

  SavedNodeColl m_savedNode;

public:
  typedef CollType::iterator iterator;
  typedef CollType::const_iterator const_iterator;

  const_iterator begin() const {
    return m_coll.begin();
  }
  const_iterator end() const {
    return m_coll.end();
  }
  iterator begin() {
    return m_coll.begin();
  }
  iterator end() {
    return m_coll.end();
  }

  DottedRuleStackOnDisk(size_t size);
  ~DottedRuleStackOnDisk();

  const DottedRuleCollOnDisk &Get(size_t pos) const {
    return *m_coll[pos];
  }
  DottedRuleCollOnDisk &Get(size_t pos) {
    return *m_coll[pos];
  }

  const DottedRuleCollOnDisk &back() const {
    return *m_coll.back();
  }

  void Add(size_t pos, const DottedRuleOnDisk *dottedRule) {
    CHECK(dottedRule);

    m_coll[pos]->Add(dottedRule);
    m_savedNode.push_back(new SavedNodeOnDisk(dottedRule));
  }

  const SavedNodeColl &GetSavedNodeColl() const {
    return m_savedNode;
  }

  void SortSavedNodes();

};

}