File tree Expand file tree Collapse file tree 5 files changed +114
-0
lines changed
Expand file tree Collapse file tree 5 files changed +114
-0
lines changed Original file line number Diff line number Diff line change 1+ /cmake-build-debug /
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.21)
2+ project (search_engine)
3+ include (FetchContent)
4+
5+ set (CMAKE_CXX_STANDARD 14)
6+
7+ FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz)
8+ FetchContent_MakeAvailable(json)
9+
10+ add_executable (search_engine main.cpp ConverterJSON.cpp ConverterJSON.h)
11+
12+ target_link_libraries (search_engine PRIVATE nlohmann_json::nlohmann_json)
Original file line number Diff line number Diff line change 1+ //
2+ // Created by ksv on 27.03.2022.
3+ //
4+
5+ #include " ConverterJSON.h"
6+
7+ std::vector<std::string> ConverterJSON::GetTextDocuments () {
8+ std::vector<std::string> response = std::vector<std::string>();
9+
10+ return response;
11+ }
Original file line number Diff line number Diff line change 1+ #include < vector>
2+ #include < string>
3+ #include < fstream>
4+
5+ #include " nlohmann/json.hpp"
6+
7+ struct config_json {
8+ struct {
9+ std::string name;
10+ std::string version;
11+ int max_responses;
12+ } config;
13+ std::vector<std::string> files;
14+ };
15+
16+ /* *
17+ * Класс для работы с JSON-файлами
18+ */
19+ class ConverterJSON {
20+ public:
21+ ConverterJSON () = default ;
22+ /* *
23+ * Метод получения содержимого файлов
24+ * @return Возвращает список с содержимым файлов перечисленных
25+ * в config.json
26+ */
27+ std::vector<std::string> GetTextDocuments ();
28+ /* *
29+ * Метод считывает поле max_responses для определения предельного
30+ * количества ответов на один запрос
31+ * @return
32+ */
33+ int GetResponsesLimit ();
34+ /* *
35+ * Метод получения запросов из файла requests.json
36+ * @return возвращает список запросов из файла requests.json
37+ */
38+ std::vector<std::string> GetRequests ();
39+ /* *
40+ * Положить в файл answers.json результаты поисковых запросов
41+ */
42+ void putAnswers (std::vector<std::vector<std::pair<int , float >>>
43+ answers);
44+ };
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ #include " ConverterJSON.h"
4+
5+ int main () {
6+
7+ auto config_file = std::ifstream (" config.json" );
8+
9+ if (!config_file.is_open ()){
10+ std::cerr << " config file is missing." << std::endl;
11+ return 1 ;
12+ }
13+
14+ nlohmann::json conf;
15+ config_file >> conf;
16+
17+ auto cf = config_json ();
18+
19+ if (conf[" config" ].is_null ()){
20+ std::cerr << " config file is empty." << std::endl;
21+ return 1 ;
22+ }
23+
24+ if (!conf[" config" ][" name" ].is_null ()){
25+ cf.config .name = conf[" config" ][" name" ];
26+ }else {
27+ cf.config .name = " Undefined" ;
28+ }
29+ if (!conf[" config" ][" version" ].is_null ()) {
30+ cf.config .version = conf[" config" ][" version" ];
31+ }
32+ cf.config .max_responses = conf[" config" ][" max_responses" ];
33+
34+ for (auto f: conf[" files" ]) {
35+ cf.files .push_back (f);
36+ }
37+
38+ std::cout << cf.config .name << ((cf.config .version == " " )? " " : " version: " ) << cf.config .version << std::endl;
39+
40+ // for (auto f: cf.files) {
41+ // std::cout << f << std::endl;
42+ // }
43+
44+ return 0 ;
45+
46+ }
You can’t perform that action at this time.
0 commit comments