-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ksv
committed
Mar 27, 2022
0 parents
commit e379453
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/cmake-build-debug/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
project(search_engine) | ||
include(FetchContent) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz) | ||
FetchContent_MakeAvailable(json) | ||
|
||
add_executable(search_engine main.cpp ConverterJSON.cpp ConverterJSON.h) | ||
|
||
target_link_libraries(search_engine PRIVATE nlohmann_json::nlohmann_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// Created by ksv on 27.03.2022. | ||
// | ||
|
||
#include "ConverterJSON.h" | ||
|
||
std::vector<std::string> ConverterJSON::GetTextDocuments() { | ||
std::vector<std::string> response = std::vector<std::string>(); | ||
|
||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <vector> | ||
#include <string> | ||
#include <fstream> | ||
|
||
#include "nlohmann/json.hpp" | ||
|
||
struct config_json { | ||
struct { | ||
std::string name; | ||
std::string version; | ||
int max_responses; | ||
} config; | ||
std::vector<std::string> files; | ||
}; | ||
|
||
/** | ||
* Класс для работы с JSON-файлами | ||
*/ | ||
class ConverterJSON { | ||
public: | ||
ConverterJSON() = default; | ||
/** | ||
* Метод получения содержимого файлов | ||
* @return Возвращает список с содержимым файлов перечисленных | ||
* в config.json | ||
*/ | ||
std::vector<std::string> GetTextDocuments(); | ||
/** | ||
* Метод считывает поле max_responses для определения предельного | ||
* количества ответов на один запрос | ||
* @return | ||
*/ | ||
int GetResponsesLimit(); | ||
/** | ||
* Метод получения запросов из файла requests.json | ||
* @return возвращает список запросов из файла requests.json | ||
*/ | ||
std::vector<std::string> GetRequests(); | ||
/** | ||
* Положить в файл answers.json результаты поисковых запросов | ||
*/ | ||
void putAnswers(std::vector<std::vector<std::pair<int, float>>> | ||
answers); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <iostream> | ||
|
||
#include "ConverterJSON.h" | ||
|
||
int main() { | ||
|
||
auto config_file = std::ifstream("config.json"); | ||
|
||
if(!config_file.is_open()){ | ||
std::cerr << "config file is missing." << std::endl; | ||
return 1; | ||
} | ||
|
||
nlohmann::json conf; | ||
config_file >> conf; | ||
|
||
auto cf = config_json(); | ||
|
||
if(conf["config"].is_null()){ | ||
std::cerr << "config file is empty." << std::endl; | ||
return 1; | ||
} | ||
|
||
if(!conf["config"]["name"].is_null()){ | ||
cf.config.name = conf["config"]["name"]; | ||
}else{ | ||
cf.config.name = "Undefined"; | ||
} | ||
if(!conf["config"]["version"].is_null()) { | ||
cf.config.version = conf["config"]["version"]; | ||
} | ||
cf.config.max_responses = conf["config"]["max_responses"]; | ||
|
||
for (auto f: conf["files"]) { | ||
cf.files.push_back(f); | ||
} | ||
|
||
std::cout << cf.config.name << ((cf.config.version == "")? "" : " version: ") << cf.config.version << std::endl; | ||
|
||
// for (auto f: cf.files) { | ||
// std::cout << f << std::endl; | ||
// } | ||
|
||
return 0; | ||
|
||
} |