-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (58 loc) · 3.24 KB
/
main.cpp
File metadata and controls
64 lines (58 loc) · 3.24 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <boost/program_options.hpp>
#include <iostream>
#include "KaggleFinanceSourceEngine.h"
#include "SearchEngine.h"
int main(int argc, char** argv) {
std::string path;
int64_t parser_thread_count;
int64_t filler_thread_count;
try {
boost::program_options::options_description desc("Options");
desc.add_options()
/* help flag */ ("help", "Help screen")
/* path flag */ ("path", boost::program_options::value<std::string>(&path)->default_value("../sample_kaggle_finance_data"), "Sets the path to the file or folder of files you wish to parse.")
/* thread flag */ ("parser-threads,pt", boost::program_options::value<int64_t>(&parser_thread_count)->default_value(1), "Sets the number of threads to be used to parse the given file or folder of files.")
/* thread flag */ ("filler-threads,ft", boost::program_options::value<int64_t>(&filler_thread_count)->default_value(1), "Sets the number of threads to be used to fill the database while parsing the given file or folder of files.")
/* print flag */ ("print-database,pd", "Prints the contents of the database after completely parsing the given file or folder of files.")
/* search flag */ ("search,s", "Prompts the user to enter a query and then searches the database for the given query.")
/* ui flag */ ("ui", "Initializes the command line interface for the search engine.");
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << desc << '\n';
return 1;
}
search_engine::KaggleFinanceEngine source_engine(parser_thread_count, filler_thread_count);
source_engine.ParseSources(path);
const search_engine::source_util::RunTimeDatabase<size_t, size_t, std::string> *const database_ptr = source_engine.GetRuntimeDatabase();
search_engine::SearchEngine<size_t, size_t, std::string> search_engine(std::make_unique<search_engine::KaggleFinanceEngine>(source_engine));
if (vm.count("print-database")) {
std::cout << "value_index: " << std::endl;
for (auto&& map : database_ptr->value_index) {
for (auto&& pair : map) {
std::cout << pair.first << " -> " << std::endl;
for (auto&& pair2 : pair.second) {
std::cout << "\t" << pair2.first << " -> " << pair2.second << std::endl;
}
}
}
}
if (vm.count("search")) {
std::string query;
std::cout << "Enter a query: ";
std::getline(std::cin, query);
std::cout << "Results for query: " << query << std::endl;
std::vector<std::string> results = search_engine.HandleQuery(query);
for (auto&& result : results) {
std::cout << "\t" << result << std::endl;
}
}
if (vm.count("ui")) {
search_engine.InitCommandLineInterface();
}
} catch (const boost::program_options::error& ex) {
std::cerr << ex.what() << '\n';
}
return 0;
}