blob: eb11f9f42486a43a5bf8d6417b42066671ce6cbb (
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
|
#pragma once
#include "search/keyword_matcher.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
namespace search
{
class KeywordLangMatcher
{
public:
class ScoreT
{
public:
ScoreT();
bool operator < (ScoreT const & s) const;
private:
friend class KeywordLangMatcher;
friend string DebugPrint(ScoreT const & score);
ScoreT(KeywordMatcher::ScoreT const & score, int langScore);
KeywordMatcher::ScoreT m_parentScore;
int m_langScore;
};
private:
typedef KeywordMatcher::StringT StringT;
public:
/// @param[in] languagePriorities Should match the constants above (checked by assertions).
void SetLanguages(vector<vector<int8_t> > const & languagePriorities);
void SetLanguage(pair<int, int> const & ind, int8_t lang);
int8_t GetLanguage(pair<int, int> const & ind) const;
/// Store references to keywords from source array of strings.
inline void SetKeywords(StringT const * keywords, size_t count, StringT const & prefix)
{
m_keywordMatcher.SetKeywords(keywords, count, prefix);
}
/// @return Score of the name (greater is better).
//@{
ScoreT Score(int8_t lang, string const & name) const;
ScoreT Score(int8_t lang, StringT const & name) const;
ScoreT Score(int8_t lang, StringT const * tokens, size_t count) const;
//@}
private:
int GetLangScore(int8_t lang) const;
vector<vector<int8_t> > m_languagePriorities;
KeywordMatcher m_keywordMatcher;
};
} // namespace search
|