-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextQuery.h
42 lines (35 loc) · 1.21 KB
/
TextQuery.h
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
//
// Created by Lenovo on 2022/3/14.
//
#ifndef C__PRIMER_STUDY_TEXTQUERY_H
#define C__PRIMER_STUDY_TEXTQUERY_H
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <fstream>
#include "QueryResult.h"
/* this version of the query classes includes two
* members not covered in the book:
* cleanup_str: which removes punctuation and
* converst all text to lowercase
* display_map: a debugging routine that will print the contents
* of the lookup mape
*/
class QueryResult; // declaration needed for return type in the query function
class TextQuery {
public:
using line_no = std::vector<std::string>::size_type;
TextQuery(std::ifstream&);
QueryResult query(const std::string&) const;
void display_map(); // debugging aid: print the map
private:
std::shared_ptr<std::vector<std::string>> file; // input file
// maps each word to the set of the lines in which that word appears
std::map<std::string,
std::shared_ptr<std::set<line_no>>> wm;
// canonicalizes text: removes punctuation and makes everything lower case
static std::string cleanup_str(const std::string&);
};
#endif //C__PRIMER_STUDY_TEXTQUERY_H