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

keyword_lang_matcher.hpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 16acde9022dfcb64d230f3efe86fa35f50bbe661 (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
67
68
69
70
71
72
#pragma once

#include "search/keyword_matcher.hpp"

#include "base/string_utils.hpp"

#include <array>
#include <string>
#include <utility>
#include <vector>

namespace search
{
class KeywordLangMatcher
{
public:
  class Score
  {
  public:
    Score();
    bool operator<(Score const & s) const;
    bool operator<=(Score const & s) const;

  private:
    friend class KeywordLangMatcher;
    friend std::string DebugPrint(Score const & score);

    Score(KeywordMatcher::Score const & score, int langScore);

    KeywordMatcher::Score m_parentScore;
    int m_langScore;
  };

  // Constructs a matcher that supports up to |maxLanguageTiers| tiers.
  // All languages in the same tier are considered equal.
  // The lower the tier is, the more important the languages in it are.
  explicit KeywordLangMatcher(size_t maxLanguageTiers);

  // Defines the languages in the |tier| to be exactly |languages|.
  void SetLanguages(size_t const tier, std::vector<int8_t> && languages);

  // Calls |fn| on every language in every tier. Does not make a distinction
  // between languages in different tiers.
  template <typename Fn>
  void ForEachLanguage(Fn && fn) const
  {
    for (auto const & langs : m_languagePriorities)
    {
      for (int8_t lang : langs)
        fn(lang);
    }
  }

  // Store references to keywords from source array of strings.
  inline void SetKeywords(strings::UniString const * keywords, size_t count,
                          strings::UniString const & prefix)
  {
    m_keywordMatcher.SetKeywords(keywords, count, prefix);
  }

  // Returns the Score of the name (greater is better).
  Score CalcScore(int8_t lang, std::string const & name) const;
  Score CalcScore(int8_t lang, strings::UniString const & name) const;
  Score CalcScore(int8_t lang, strings::UniString const * tokens, size_t count) const;

private:
  int CalcLangScore(int8_t lang) const;

  std::vector<std::vector<int8_t>> m_languagePriorities;
  KeywordMatcher m_keywordMatcher;
};
}  // namespace search