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

SemposOverlapping.h « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b5a99f7f500e99ec8f15934317efc18c221a8a6 (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
#ifndef MERT_SEMPOSOVERLAPPING_H_
#define MERT_SEMPOSOVERLAPPING_H_

#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

namespace MosesTuning
{
  

class SemposScorer;

// TODO: need comments about this number.
const int kMaxNOC = 50;

typedef std::pair<std::string, std::string> str_item_t;
typedef std::vector<str_item_t> str_sentence_t;
typedef str_sentence_t::const_iterator str_sentence_it;

typedef std::pair<int,int> item_t;
typedef std::multiset<item_t> sentence_t;
typedef sentence_t::const_iterator sentence_it;

/**
 * An interface for classes representing overlapping formulas
 */
class SemposOverlapping
{
public:
  virtual ~SemposOverlapping() {}
  virtual std::vector<int> prepareStats(const sentence_t& cand, const sentence_t& ref) = 0;
  virtual float calculateScore(const std::vector<int>& stats) const = 0;
  virtual std::size_t NumberOfScores() const = 0;
};

class SemposOverlappingFactory {
 public:
  static SemposOverlapping* GetOverlapping(const std::string& str, const SemposScorer* sempos);

  // dependency injection for unit testing.
  static void SetOverlapping(SemposOverlapping* ovr);

 private:
  SemposOverlappingFactory() {}
  ~SemposOverlappingFactory() {}
};

/**
 * Overlapping proposed by (Bojar and Machacek, WMT 2011)
 *
 * Please refer to the paper for details:
 * http://aclweb.org/anthology-new/W/W11/W11-2108.pdf
 */
class CapMicroOverlapping : public SemposOverlapping
{
public:
  CapMicroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {}
  ~CapMicroOverlapping() {}

  virtual std::vector<int> prepareStats(const sentence_t& cand, const sentence_t& ref);
  virtual float calculateScore(const std::vector<int>& stats) const;
  virtual std::size_t NumberOfScores() const { return 2; }

 private:
  // no copying allowed.
  CapMicroOverlapping(const CapMicroOverlapping&);
  CapMicroOverlapping& operator=(const CapMicroOverlapping&);
  const SemposScorer* semposScorer;
};

/**
 * Overlapping proposed by (Kos and Bojar, 2009)
 */
class CapMacroOverlapping : public SemposOverlapping
{
public:
  CapMacroOverlapping(const SemposScorer* sempos) : semposScorer(sempos) {}
  ~CapMacroOverlapping() {}

  virtual std::vector<int> prepareStats(const sentence_t& cand, const sentence_t& ref);
  virtual float calculateScore(const std::vector<int>& stats) const;
  virtual std::size_t NumberOfScores() const { return kMaxNOC * 2; }

 private:
  // no copying allowed.
  CapMacroOverlapping(const CapMacroOverlapping&);
  CapMacroOverlapping& operator=(const CapMacroOverlapping&);
  const SemposScorer* semposScorer;
};

}

#endif  // MERT_SEMPOSOVERLAPPING_H_