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
|
/***********************************************************************
Moses - statistical machine translation system
Copyright (C) 2006-2011 University of Edinburgh
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
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "DotChart.h"
#include "PhraseDictionaryNodeSCFG.h"
#include "util/check.hh"
#include <vector>
namespace Moses
{
class DottedRuleInMemory : public DottedRule
{
public:
// used only to init dot stack.
explicit DottedRuleInMemory(const PhraseDictionaryNodeSCFG &node)
: DottedRule()
, m_node(node) {}
DottedRuleInMemory(const PhraseDictionaryNodeSCFG &node,
const ChartCellLabel &cellLabel,
const DottedRuleInMemory &prev)
: DottedRule(cellLabel, prev)
, m_node(node) {}
const PhraseDictionaryNodeSCFG &GetLastNode() const { return m_node; }
private:
const PhraseDictionaryNodeSCFG &m_node;
};
typedef std::vector<const DottedRuleInMemory*> DottedRuleList;
// Collection of all in-memory DottedRules that share a common start point,
// grouped by end point. Additionally, maintains a list of all
// DottedRules that could be expanded further, i.e. for which the
// corresponding PhraseDictionaryNodeSCFG is not a leaf.
class DottedRuleColl
{
protected:
typedef std::vector<DottedRuleList> CollType;
CollType m_coll;
DottedRuleList m_expandableDottedRuleList;
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();
}
DottedRuleColl(size_t size)
: m_coll(size)
{}
~DottedRuleColl();
const DottedRuleList &Get(size_t pos) const {
return m_coll[pos];
}
DottedRuleList &Get(size_t pos) {
return m_coll[pos];
}
void Add(size_t pos, const DottedRuleInMemory *dottedRule) {
CHECK(dottedRule);
m_coll[pos].push_back(dottedRule);
if (!dottedRule->GetLastNode().IsLeaf()) {
m_expandableDottedRuleList.push_back(dottedRule);
}
}
void Clear(size_t pos) {
#ifdef USE_BOOST_POOL
m_coll[pos].clear();
#endif
}
const DottedRuleList &GetExpandableDottedRuleList() const {
return m_expandableDottedRuleList;
}
};
}
|