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

DotChartInMemory.h « CYKPlusParser « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a95b5599ecb6d9d42c9d3d1658f0a1baedd3c14d (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
/***********************************************************************
 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

#include "DotChart.h"
#include "moses/TranslationModel/PhraseDictionaryNodeMemory.h"

#include <vector>

namespace Moses
{

/** @todo what is this?
 */
class DottedRuleInMemory : public DottedRule
{
public:
  // used only to init dot stack.
  explicit DottedRuleInMemory(const PhraseDictionaryNodeMemory &node)
    : DottedRule()
    , m_node(node) {}

  DottedRuleInMemory(const PhraseDictionaryNodeMemory &node,
                     const ChartCellLabel &cellLabel,
                     const DottedRuleInMemory &prev)
    : DottedRule(cellLabel, prev)
    , m_node(node) {}

  const PhraseDictionaryNodeMemory &GetLastNode() const {
    return m_node;
  }

private:
  const PhraseDictionaryNodeMemory &m_node;
};

typedef std::vector<const DottedRuleInMemory*> DottedRuleList;
typedef std::map<size_t, DottedRuleList> DottedRuleMap;

// 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 PhraseDictionaryNodeMemory is not a leaf.
class DottedRuleColl
{
protected:
  typedef std::vector<DottedRuleList> CollType;
  CollType m_coll;
  DottedRuleList m_expandableDottedRuleList;
  DottedRuleMap m_expandableDottedRuleListTerminalsOnly;

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) {
    UTIL_THROW_IF2(dottedRule == NULL, "Dotted rule is null");
    m_coll[pos].push_back(dottedRule);
    if (!dottedRule->GetLastNode().IsLeaf()) {
      if (dottedRule->GetLastNode().GetNonTerminalMap().empty() && !dottedRule->IsRoot()) {
        size_t startPos = dottedRule->GetWordsRange().GetEndPos() + 1;
        m_expandableDottedRuleListTerminalsOnly[startPos].push_back(dottedRule);
      } else {
        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;
  }

  DottedRuleMap &GetExpandableDottedRuleListTerminalsOnly() {
    return m_expandableDottedRuleListTerminalsOnly;
  }

};

}