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

keyword_lang_matcher.cpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 11b674d0ad8cb1ce86013a5c0fd0e79fd11e5ab0 (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
73
74
#include "keyword_lang_matcher.hpp"

#include "../indexer/search_string_utils.hpp"
#include "../indexer/search_delimiters.hpp"

#include "../base/stl_add.hpp"

#include "../std/algorithm.hpp"


namespace search
{

KeywordLangMatcher::ScoreT::ScoreT(KeywordMatcher::ScoreT const & score, int langScore)
  : m_parentScore(score), m_langScore(langScore)
{
}

bool KeywordLangMatcher::ScoreT::operator <(KeywordLangMatcher::ScoreT const & score) const
{
  if (m_parentScore < score.m_parentScore)
    return true;
  if (score.m_parentScore < m_parentScore)
    return false;

  if (m_langScore != score.m_langScore)
    return m_langScore < score.m_langScore;

  return false;
}

void KeywordLangMatcher::SetLanguages(vector<vector<int8_t> > const & languagePriorities)
{
  m_languagePriorities = languagePriorities;
}

void KeywordLangMatcher::SetLanguage(pair<int, int> const & ind, int8_t lang)
{
  m_languagePriorities[ind.first][ind.second] = lang;
}

int8_t KeywordLangMatcher::GetLanguage(pair<int, int> const & ind) const
{
  return m_languagePriorities[ind.first][ind.second];
}

int KeywordLangMatcher::GetLangScore(int8_t lang) const
{
  int const prioritiesTiersCount = static_cast<int>(m_languagePriorities.size());
  for (int i = 0; i < prioritiesTiersCount; ++i)
    for (int j = 0; j < m_languagePriorities[i].size(); ++j)
      if (m_languagePriorities[i][j] == lang)
        return -i; // All languages in the same tier are equal.

  return -prioritiesTiersCount;
}

KeywordLangMatcher::ScoreT KeywordLangMatcher::Score(int8_t lang, string const & name) const
{
  return ScoreT(m_keywordMatcher.Score(name), GetLangScore(lang));
}

KeywordLangMatcher::ScoreT KeywordLangMatcher::Score(int8_t lang, StringT const & name) const
{
  return ScoreT(m_keywordMatcher.Score(name), GetLangScore(lang));
}

KeywordLangMatcher::ScoreT KeywordLangMatcher::Score(int8_t lang,
                                                     StringT const * tokens, size_t count) const
{
  return ScoreT(m_keywordMatcher.Score(tokens, count), GetLangScore(lang));
}

}  // namespace search