summaryrefslogtreecommitdiff
path: root/mteval/ns_ssk.cc
blob: c94e62ca1f77fde23158f555c39c9c4797d0d797 (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
#include "ns_ssk.h"

#include <vector>

#include "kernel_string_subseq.h"
#include "tdict.h"

static const unsigned kNUMFIELDS = 2;
static const unsigned kSIMILARITY = 0;
static const unsigned kCOUNT = 1;

unsigned SSKMetric::SufficientStatisticsVectorSize() const {
  return kNUMFIELDS;
}

void SSKMetric::ComputeSufficientStatistics(const std::vector<WordID>& hyp,
                                            const std::vector<std::vector<WordID> >& refs,
                                            SufficientStats* out) const {
  out->fields.resize(kNUMFIELDS);
  out->fields[kCOUNT] = 1;
  float bestsim = 0;
  for (unsigned i = 0; i < refs.size(); ++i) {
    float s = ssk<4>(hyp, refs[i], 0.8);
    if (s > bestsim) bestsim = s;
  }
  out->fields[kSIMILARITY] = bestsim;
}

float SSKMetric::ComputeScore(const SufficientStats& stats) const {
  return stats.fields[kSIMILARITY] / stats.fields[kCOUNT];
}