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

WordCoocTable.cpp « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3223942ec984d9cec14a44b06ae43d7f8dfff56 (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
#include "moses/TranslationModel/WordCoocTable.h"
using namespace std;
namespace Moses
{

WordCoocTable::
WordCoocTable()
{
  m_cooc.reserve(1000000);
  m_marg1.reserve(1000000);
  m_marg2.reserve(1000000);
}

WordCoocTable::
WordCoocTable(wordID_t const VocabSize1, wordID_t const VocabSize2)
  : m_cooc(VocabSize1), m_marg1(VocabSize1,0), m_marg2(VocabSize2, 0)
{}

void
WordCoocTable::
Count(size_t const a, size_t const b)
{
  while (a >= m_marg1.size()) {
    m_cooc.push_back(my_map_t());
    m_marg1.push_back(0);
  }
  while (b >= m_marg2.size())
    m_marg2.push_back(0);
  ++m_marg1[a];
  ++m_marg2[b];
  ++m_cooc[a][b];
}

uint32_t
WordCoocTable::
GetJoint(size_t const a, size_t const b) const
{
  if (a >= m_marg1.size() || b >= m_marg2.size()) return 0;
  my_map_t::const_iterator m = m_cooc.at(a).find(b);
  if (m == m_cooc[a].end()) return 0;
  return m->second;
}

uint32_t
WordCoocTable::
GetMarg1(size_t const x) const
{
  return x >= m_marg1.size() ? 0 : m_marg1[x];
}

uint32_t
WordCoocTable::
GetMarg2(size_t const x) const
{
  return x >= m_marg2.size() ? 0 : m_marg2[x];
}

float
WordCoocTable::
pfwd(size_t const a, size_t const b) const
{
  return float(GetJoint(a,b))/GetMarg1(a);
}

float
WordCoocTable::
pbwd(size_t const a, size_t const b) const
{
  // cerr << "at " << __FILE__ << ":" << __LINE__ << endl;
  return float(GetJoint(a,b))/GetMarg2(b);
}
}