From 9abbf42bf46dde72ceb0d59896102a5078f27891 Mon Sep 17 00:00:00 2001 From: Al Date: Tue, 26 Jan 2016 01:20:59 -0500 Subject: [PATCH] [language_classifier] Command-line client for language classification --- src/language_classifier_cli.c | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/language_classifier_cli.c diff --git a/src/language_classifier_cli.c b/src/language_classifier_cli.c new file mode 100644 index 00000000..08860f1c --- /dev/null +++ b/src/language_classifier_cli.c @@ -0,0 +1,42 @@ +#include +#include +#include + +#include "address_dictionary.h" +#include "language_classifier.h" + + +int main(int argc, char **argv) { + if (argc < 3) { + printf("Usage: ./language_classifier dir address\n"); + exit(EXIT_FAILURE); + } + + char *dir = argv[1]; + char *address = strdup(argv[2]); + printf("address=%s\n", address); + + if (!address_dictionary_module_setup(NULL) || !language_classifier_module_setup(dir)) { + log_error("Could not load language classifiers\n"); + exit(EXIT_FAILURE); + } + + + language_classifier_response_t *response = classify_languages(address); + if (response == NULL) { + printf("Could not classify language\n"); + exit(EXIT_FAILURE); + } + + printf("Languages:\n\n"); + + for (size_t i = 0; i < response->num_languages; i++) { + printf("%s (%f)\n", response->languages[i], response->probs[i]); + } + + free(address); + language_classifier_response_destroy(response); + + language_classifier_module_teardown(); + address_dictionary_module_teardown(); +}