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

combine_counts.hh « builder « lm - github.com/kpu/kenlm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2eda5170492eb971a15d567448da4acc6c4b652b (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
#ifndef LM_BUILDER_COMBINE_COUNTS_H
#define LM_BUILDER_COMBINE_COUNTS_H

#include "lm/builder/payload.hh"
#include "lm/common/ngram.hh"
#include "lm/common/compare.hh"
#include "lm/word_index.hh"
#include "util/stream/sort.hh"

#include <functional>
#include <string>

namespace lm {
namespace builder {

// Sum counts for the same n-gram.
struct CombineCounts {
  bool operator()(void *first_void, const void *second_void, const SuffixOrder &compare) const {
    NGram<BuildingPayload> first(first_void, compare.Order());
    // There isn't a const version of NGram.
    NGram<BuildingPayload> second(const_cast<void*>(second_void), compare.Order());
    if (memcmp(first.begin(), second.begin(), sizeof(WordIndex) * compare.Order())) return false;
    first.Value().count += second.Value().count;
    return true;
  }
};

} // namespace builder
} // namespace lm

#endif // LM_BUILDER_COMBINE_COUNTS_H