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

#include "matchings_sampler.h"
#include "phrase_location.h"
#include "suffix_array.h"
#include "suffix_array_sampler.h"

namespace extractor {

PhraseLocationSampler::PhraseLocationSampler(
    shared_ptr<SuffixArray> suffix_array, int max_samples) {
  matchings_sampler = make_shared<MatchingsSampler>(
      suffix_array->GetData(), max_samples);
  suffix_array_sampler = make_shared<SuffixArrayRangeSampler>(
      suffix_array, max_samples);
}

PhraseLocationSampler::PhraseLocationSampler(
    shared_ptr<MatchingsSampler> matchings_sampler,
    shared_ptr<SuffixArrayRangeSampler> suffix_array_sampler) :
    matchings_sampler(matchings_sampler),
    suffix_array_sampler(suffix_array_sampler) {}

PhraseLocation PhraseLocationSampler::Sample(
    const PhraseLocation& location,
    const unordered_set<int>& blacklisted_sentence_ids) const {
  if (location.matchings == NULL) {
    return suffix_array_sampler->Sample(location, blacklisted_sentence_ids);
  } else {
    return matchings_sampler->Sample(location, blacklisted_sentence_ids);
  }
}

} // namespace extractor