-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.h
More file actions
38 lines (27 loc) · 1.26 KB
/
search.h
File metadata and controls
38 lines (27 loc) · 1.26 KB
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
#pragma once
#include <string_view>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <iostream>
const long double EPS = 1e-9;
const char DIFFERENCE_BETWEEN_LOW_AND_BIG_LETTERS = 'a' - 'A';
class SearchEngine {
public:
std::vector<std::string_view> strings_of_text;
bool IsWordsEqualWithNoRegisterMatters(const std::string_view& a,
const std::string_view& b) const;
long double ComputeTermFrequency(const std::string_view& query_word,
const std::string_view& document) const;
long double ComputeInverseDocumentFrequency(const std::string_view& query_word) const;
long double CompeteTFIDFForWordsFromQuery(
const std::vector<std::string_view>& unique_words_from_query,
const std::string_view& document,
const std::vector<long double>& idfs_of_unique_words_of_query) const;
std::vector<std::string_view> SplitQueryIntoWords(const std::string_view& query) const;
std::vector<std::string_view> GetUniqueWords(const std::vector<std::string_view>& words) const;
void BuildIndex(std::string_view text);
std::vector<std::string_view> Search(std::string_view query, size_t results_count) const;
};