diff options
author | Peng Wu <alexepico@gmail.com> | 2013-04-02 12:47:57 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-04-02 12:47:57 +0800 |
commit | db89cdf49dc5609ae42f9d6d83f0f1a929d258e0 (patch) | |
tree | 20741b2e30a562568069f0034b0acc6434202b4d /utils/training | |
parent | 9e910111bfb85e34284413a9e377497ee18fa5a2 (diff) | |
download | libpinyin-db89cdf49dc5609ae42f9d6d83f0f1a929d258e0.tar.gz |
update merge_k_mixture_model.cpp
Diffstat (limited to 'utils/training')
-rw-r--r-- | utils/training/merge_k_mixture_model.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/utils/training/merge_k_mixture_model.cpp b/utils/training/merge_k_mixture_model.cpp index 72397ef..ab08010 100644 --- a/utils/training/merge_k_mixture_model.cpp +++ b/utils/training/merge_k_mixture_model.cpp @@ -28,6 +28,13 @@ void print_help(){ printf(" {<SOURCE_FILENAME>}+\n"); } +static const gchar * result_filename = NULL; + +static GOptionEntry entries[] = +{ + {"result-file", 0, 0, G_OPTION_ARG_FILENAME, &result_filename, "merged result file", NULL}, + {NULL} +}; static bool merge_two_phrase_array( /* in */ FlexibleBigramPhraseArray first, /* in */ FlexibleBigramPhraseArray second, @@ -203,29 +210,23 @@ bool merge_two_k_mixture_model( /* in & out */ KMixtureModelBigram * target, int main(int argc, char * argv[]){ int i = 1; - const char * result_filename = NULL; setlocale(LC_ALL, ""); - while (i < argc) { - if ( strcmp("--help", argv[i]) == 0 ){ - print_help(); - exit(0); - } else if ( strcmp("--result-file", argv[i]) == 0 ){ - if ( ++i >= argc ){ - print_help(); - exit(EINVAL); - } - result_filename = argv[i]; - } else { - break; - } - ++i; + + GError * error = NULL; + GOptionContext * context; + + context = g_option_context_new("- merge k mixture model"); + g_option_context_add_main_entries(context, entries, NULL); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed:%s\n", error->message); + exit(EINVAL); } KMixtureModelBigram target(K_MIXTURE_MODEL_MAGIC_NUMBER); target.attach(result_filename, ATTACH_READWRITE|ATTACH_CREATE); - while ( i < argc ){ + while (i < argc){ const char * new_filename = argv[i]; KMixtureModelBigram new_one(K_MIXTURE_MODEL_MAGIC_NUMBER); new_one.attach(new_filename, ATTACH_READONLY); |