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

ug_bitext_jstats.cc « mm « UG « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5debcec82e84bc4464b0fc8ce851e93757aa9cf (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
#include "ug_bitext_jstats.h"
namespace Moses
{
  namespace bitext
  {

    uint32_t jstats::rcnt() const { return my_rcnt; }
    float    jstats::wcnt() const { return my_wcnt; }
    float    jstats::bcnt() const { return my_bcnt; }
    uint32_t jstats::cnt2() const { return my_cnt2; }

    // What was that used for again? UG
    bool jstats::valid() { return my_wcnt >= 0; }
    void jstats::validate()   { if (my_wcnt < 0) my_wcnt *= -1; }
    void jstats::invalidate() { if (my_wcnt > 0) my_wcnt *= -1; }

    jstats::
    jstats()
      : my_rcnt(0), my_cnt2(0), my_wcnt(0), my_bcnt(0)
    {
      for (int i = 0; i <= Moses::LRModel::NONE; ++i)
	ofwd[i] = obwd[i] = 0;
      my_aln.reserve(1);
    }

    jstats::
    jstats(jstats const& other)
    {
      my_rcnt = other.rcnt();
      my_wcnt = other.wcnt();
      my_bcnt = other.bcnt();
      my_aln  = other.aln();
      indoc   = other.indoc;
      for (int i = 0; i <= Moses::LRModel::NONE; i++)
	{
	  ofwd[i] = other.ofwd[i];
	  obwd[i] = other.obwd[i];
	}
    }

    uint32_t
    jstats::
    dcnt_fwd(PhraseOrientation const idx) const
    {
      assert(idx <= Moses::LRModel::NONE);
      return ofwd[idx];
    }

    uint32_t
    jstats::
    dcnt_bwd(PhraseOrientation const idx) const
    {
      assert(idx <= Moses::LRModel::NONE);
      return obwd[idx];
    }

    void
    jstats::
    add(float w, float b, std::vector<unsigned char> const& a, uint32_t const cnt2,
	uint32_t fwd_orient, uint32_t bwd_orient, int const docid)
    {
      boost::lock_guard<boost::mutex> lk(this->lock);
      my_cnt2 = cnt2;
      my_rcnt += 1;
      my_wcnt += w;
      my_bcnt += b;
      if (a.size())
	{
	  size_t i = 0;
	  while (i < my_aln.size() && my_aln[i].second != a) ++i;
	  if (i == my_aln.size())
	    my_aln.push_back(std::pair<size_t,std::vector<unsigned char> >(1,a));
	  else
	    my_aln[i].first++;
	  if (my_aln[i].first > my_aln[i/2].first)
	    push_heap(my_aln.begin(),my_aln.begin()+i+1);
	}
      ++ofwd[fwd_orient];
      ++obwd[bwd_orient];
      if (docid >= 0)
	{
	  // while (int(indoc.size()) <= docid) indoc.push_back(0);
	  ++indoc[docid];
	}
    }

    std::vector<std::pair<size_t, std::vector<unsigned char> > > const&
    jstats::
    aln() const
    { return my_aln; }

  } // namespace bitext
} // namespace Moses