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

ActiveChart.cpp « SCFG « moses2 - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb4d84bfb2481dbdea1998d92c7fc0b1f8066991 (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
#include <boost/foreach.hpp>
#include <boost/functional/hash_fwd.hpp>
#include "ActiveChart.h"
#include "InputPath.h"
#include "Word.h"
#include "Hypothesis.h"
#include "../Vector.h"

using namespace std;

namespace Moses2
{
namespace SCFG
{
SymbolBindElement::SymbolBindElement()
{
}

SymbolBindElement::SymbolBindElement(
  const Moses2::Range &range,
  const SCFG::Word &word,
  const Moses2::Hypotheses *hypos)
  :m_range(&range)
  ,word(&word)
  ,hypos(hypos)
{
  assert( (word.isNonTerminal && hypos) || (!word.isNonTerminal && hypos == NULL));
}

size_t hash_value(const SymbolBindElement &obj)
{
  size_t ret = (size_t) obj.hypos;
  boost::hash_combine(ret, obj.word);

  return ret;
}

std::string SymbolBindElement::Debug(const System &system) const
{
  stringstream out;
  out << "(";
  out << *m_range;
  out << word->Debug(system);
  out << ")";

  return out.str();
}

////////////////////////////////////////////////////////////////////////////
SymbolBind::SymbolBind(MemPool &pool)
  :coll(pool)
  ,numNT(0)
{
}

void SymbolBind::Add(const Range &range, const SCFG::Word &word, const Moses2::Hypotheses *hypos)
{
  SymbolBindElement ele(range, word, hypos);
  coll.push_back(ele);

  if (word.isNonTerminal) {
    ++numNT;
  }
}

std::vector<const SymbolBindElement*> SymbolBind::GetNTElements() const
{
  std::vector<const SymbolBindElement*> ret;

  for (size_t i = 0; i < coll.size(); ++i) {
    const SymbolBindElement &ele = coll[i];
    //cerr << "ele=" << ele.word->isNonTerminal << " " << ele.hypos << endl;

    if (ele.word->isNonTerminal) {
      ret.push_back(&ele);
    }
  }

  return ret;
}

std::string SymbolBind::Debug(const System &system) const
{
  stringstream out;
  BOOST_FOREACH(const SymbolBindElement &ele, coll) {
    out << ele.Debug(system) << " ";
  }
  return out.str();
}
////////////////////////////////////////////////////////////////////////////
ActiveChartEntry::ActiveChartEntry(MemPool &pool)
  :m_symbolBind(pool)
{
}

////////////////////////////////////////////////////////////////////////////
ActiveChart::ActiveChart(MemPool &pool)
  :entries(pool)
{
}

ActiveChart::~ActiveChart()
{

}

}
}