C++ Standard Template Library browser.
1/* ========================================================================
2 *
3 * Filename: main.cpp
4 * Description: HTML Parser and Browser for cppreference
5 * Author: Diego A. Estrada Rivera
6 * Version: 0.0.1
7 *
8 * ======================================================================== */
9#include "indexer.hpp"
10#include "prelude.hpp"
11#include <cctype>
12
13namespace filesystem = std::filesystem;
14
15proc Main([[maybe_unused]] std::span<const std::string_view> args) noexcept
16 -> I32
17{
18 let cppref =
19 filesystem::path{"/home/Michorron/Git/cppreference-doc/"
20 "reference/en.cppreference.com"};
21
22 let cache = get_cache_dir() / "cache.txt";
23 var cache_created = exists(cache);
24 let documents = cache_created ? load_index() : index_directory(cppref) ;
25 if (not cache_created) cache_index(documents);
26
27 std::cout << "Succesfully indexed " << cppref.filename() << "!"
28 << std::endl;
29
30 var query = String();
31 std::cout << "What is your query?\nType here: ";
32 std::getline(std::cin, query);
33
34 cache_index(documents);
35
36 let greater = [](let& x, let& y) { return x.second > y.second; };
37
38 for (var& c : query) c = std::toupper(c);
39 var matches = count_tfidf(documents, query);
40 if (matches.size() < 5)
41 ra::sort(matches, greater);
42 else
43 ra::partial_sort(matches, matches.begin() + 5, greater);
44
45 for (var idx = 0LLU; let & [ name, score ] : matches) {
46 if (idx > 5)
47 break;
48 std::cout << name << " had " << score << " score.\n";
49 ++idx;
50 }
51 return 0;
52}