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

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

#include <ostream>
#include <string>
#include <vector>

#include "Types.h"
#include "ScoreData.h"
#include "Scorer.h"
#include "ScopedVector.h"

using namespace std;

const int kBleuNgramOrder = 4;

class NgramCounts;

/**
 * Bleu scoring
 */
class BleuScorer: public StatisticsBasedScorer
{
public:
  explicit BleuScorer(const string& config = "");
  ~BleuScorer();

  virtual void setReferenceFiles(const vector<string>& referenceFiles);
  virtual void prepareStats(size_t sid, const string& text, ScoreStats& entry);
  virtual float calculateScore(const vector<int>& comps) const;
  virtual size_t NumberOfScores() const { return 2 * kBleuNgramOrder + 1; }

private:
  enum ReferenceLengthType {
    AVERAGE,
    SHORTEST,
    CLOSEST
  };

  /**
   * Count the ngrams of each type, up to the given length in the input line.
   */
  size_t countNgrams(const string& line, NgramCounts& counts, unsigned int n);

  void dump_counts(std::ostream* os, const NgramCounts& counts) const;

  // For calculating effective reference length.
  void CalcAverage(size_t sentence_id,
                   vector<ScoreStatsType>& stats) const;
  void CalcClosest(size_t sentence_id, size_t length,
                   vector<ScoreStatsType>& stats) const;
  void CalcShortest(size_t sentence_id,
                    vector<ScoreStatsType>& stats) const;

  ReferenceLengthType m_ref_length_type;

  // data extracted from reference files
  ScopedVector<NgramCounts> m_ref_counts;
  vector<vector<size_t> > m_ref_lengths;

  // no copying allowed
  BleuScorer(const BleuScorer&);
  BleuScorer& operator=(const BleuScorer&);
};

#endif  // MERT_BLEU_SCORER_H_