From 71c51f2e45cbcd6d34a29a036e103e9c0c3d5ec2 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 27 Jan 2016 03:18:53 -0500 Subject: [PATCH] [language_classification] Making directory optional on language_classifier client/test program --- src/language_classifier_cli.c | 16 +++++++++++----- src/language_classifier_test.c | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/language_classifier_cli.c b/src/language_classifier_cli.c index 08860f1c..dbde9dc0 100644 --- a/src/language_classifier_cli.c +++ b/src/language_classifier_cli.c @@ -7,14 +7,20 @@ int main(int argc, char **argv) { - if (argc < 3) { - printf("Usage: ./language_classifier dir address\n"); + if (argc < 2) { + printf("Usage: ./language_classifier [dir] address\n"); exit(EXIT_FAILURE); } - char *dir = argv[1]; - char *address = strdup(argv[2]); - printf("address=%s\n", address); + char *dir = LIBPOSTAL_LANGUAGE_CLASSIFIER_DIR; + char *address = NULL; + + if (argc >= 3) { + dir = argv[1]; + address = strdup(argv[2]); + } else { + address = strdup(argv[1]); + } if (!address_dictionary_module_setup(NULL) || !language_classifier_module_setup(dir)) { log_error("Could not load language classifiers\n"); diff --git a/src/language_classifier_test.c b/src/language_classifier_test.c index 90e45b5d..b60ac72f 100644 --- a/src/language_classifier_test.c +++ b/src/language_classifier_test.c @@ -64,15 +64,25 @@ double test_accuracy(char *filename) { int main(int argc, char **argv) { - if (argc < 3) { - log_error("Usage: language_classifier_test dir filename\n"); + if (argc < 2) { + log_error("Usage: language_classifier_test [dir] filename\n"); exit(EXIT_FAILURE); } + char *dir = LIBPOSTAL_LANGUAGE_CLASSIFIER_DIR; + char *filename = NULL; + + if (argc >= 3) { + dir = argv[1]; + filename = argv[2]; + } else { + filename = argv[1]; + } + if (!language_classifier_module_setup(argv[1]) || !address_dictionary_module_setup(NULL)) { log_error("Error setting up classifier\n"); } - double accuracy = test_accuracy(argv[2]); + double accuracy = test_accuracy(filename); log_info("Done. Accuracy: %f\n", accuracy); } \ No newline at end of file