summaryrefslogtreecommitdiff
path: root/word-aligner/ttables.cc
blob: 64d54bdf3d746aabfc16c2d86b15a7fc922ec81b (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
#include "ttables.h"

#include <cassert>

#include "dict.h"

using namespace std;

void TTable::DeserializeProbsFromText(std::istream* in) {
  int c = 0;
  string e;
  string f;
  double p;
  while(*in) {
    (*in) >> e >> f >> p;
    if (e.empty()) break;
    ++c;
    WordID ie = TD::Convert(e);
    if (ie >= static_cast<int>(ttable.size())) ttable.resize(ie + 1);
    ttable[ie][TD::Convert(f)] = p;
  }
  cerr << "Loaded " << c << " translation parameters.\n";
}

void TTable::DeserializeLogProbsFromText(std::istream* in) {
  int c = 0;
  string e;
  string f;
  double p;
  while(*in) {
    (*in) >> e >> f >> p;
    if (e.empty()) break;
    ++c;
    WordID ie = TD::Convert(e);
    if (ie >= static_cast<int>(ttable.size())) ttable.resize(ie + 1);
    ttable[ie][TD::Convert(f)] = exp(p);
  }
  cerr << "Loaded " << c << " translation parameters.\n";
}

void TTable::SerializeHelper(string* out, const Word2Word2Double& o) {
  assert(!"not implemented");
}

void TTable::DeserializeHelper(const string& in, Word2Word2Double* o) {
  assert(!"not implemented");
}