summaryrefslogtreecommitdiff
path: root/extractor/matchings_sampler.cc
blob: bb916e49ea10454c115cea7fe05a1177e58b0b76 (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
#include "matchings_sampler.h"

#include "data_array.h"
#include "phrase_location.h"

namespace extractor {

MatchingsSampler::MatchingsSampler(
    shared_ptr<DataArray> data_array, int max_samples) :
    BackoffSampler(data_array, max_samples) {}

MatchingsSampler::MatchingsSampler() {}

int MatchingsSampler::GetNumSubpatterns(const PhraseLocation& location) const {
  return location.num_subpatterns;
}

int MatchingsSampler::GetRangeLow(const PhraseLocation&) const {
  return 0;
}

int MatchingsSampler::GetRangeHigh(const PhraseLocation& location) const {
  return location.matchings->size() / location.num_subpatterns;
}

int MatchingsSampler::GetPosition(const PhraseLocation& location,
                                  int index) const {
  return (*location.matchings)[index * location.num_subpatterns];
}

void MatchingsSampler::AppendMatching(vector<int>& samples, int index,
                                      const PhraseLocation& location) const {
  copy(location.matchings->begin() + index,
       location.matchings->begin() + index + location.num_subpatterns,
       back_inserter(samples));
}

} // namespace extractor