1
0
Fork 0
mirror of https://gitlab.com/niansa/anyproc.git synced 2025-03-06 20:49:24 +01:00
anyproc/examples/dictionary.cpp
2023-05-21 17:44:31 +02:00

36 lines
922 B
C++

#include "anyproc.hpp"
#include <iostream>
#include <string>
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <model file>" << std::endl;
return -1;
}
const auto progress_indicator = [](float progress) {
std::cout << unsigned(progress) << "% \r" << std::flush;
return true;
};
const auto result_printer = [](const char *token) {
std::cout << token << std::flush;
return true;
};
Dictionary dict(argv[1]);
for (;;) {
std::string what;
std::cout << "What: " << std::flush;
std::getline(std::cin, what);
for (;;) {
std::string word;
std::cout << "\rWord: " << std::flush;
std::getline(std::cin, word);
if (word.empty()) break;
dict.lookup(word, what, progress_indicator, result_printer);
}
}
}