blob: 3786dc107f0ffe8f2ea5a10173fc8951c0b3cfae (
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
|
#pragma once
#include "keyword_matcher.hpp"
#include "../std/vector.hpp"
namespace search
{
class KeywordLangMatcher
{
public:
class ScoreT
{
public:
ScoreT() {}
bool operator < (ScoreT const & s) const;
private:
friend class KeywordLangMatcher;
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
|