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

Alignments.cpp « fuzzy-match « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 391ba662ca381712f092c1aa026c29f6d2793e0a (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

#include <cassert>
#include <vector>
#include "Alignments.h"
#include "Util.h"

using namespace std;
using namespace Moses;

Alignments::Alignments(const std::string &str, size_t sourceSize, size_t targetSize)
:m_alignS2T(sourceSize)
,m_alignT2S(targetSize)
{
  vector<string> toks   = Tokenize(str, " ");
  for (size_t i = 0; i < toks.size(); ++i)
  {
    string &tok = toks[i];

    vector<int> point = Tokenize<int>(tok, "-");
    assert(point.size() == 2);

    std::map<int, int>::iterator iter;

    // m_alignedToS
    std::map<int, int> &targets = m_alignS2T[ point[0] ];
    iter = targets.find(point[1]);
    if (iter == targets .end()) {
    	targets[ point[1] ] = 0;
    }
    else {
    	++(iter->second);
    }

    // m_alignedToT
    std::map<int, int> &sources = m_alignT2S[ point[1] ];
    iter = sources.find(point[0]);
    if (iter == targets .end()) {
    	sources[ point[0] ] = 0;
    }
    else {
    	++(iter->second);
    }
  }

}