diff options
author | Peng Wu <alexepico@gmail.com> | 2011-05-13 10:49:13 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-05-13 10:49:13 +0800 |
commit | 82c49d8b7337dca828c142c902682bb991382df0 (patch) | |
tree | fc6cdb1cad7061d99fbbf0a7f7dc3e6c69f3bb39 | |
parent | 58f510f72eb5cbb321dd6783a98b6c8e0ac304bb (diff) | |
download | libpinyin-82c49d8b7337dca828c142c902682bb991382df0.tar.gz libpinyin-82c49d8b7337dca828c142c902682bb991382df0.tar.xz libpinyin-82c49d8b7337dca828c142c902682bb991382df0.zip |
add cmd options for merge k mixture model
-rw-r--r-- | utils/training/gen_k_mixture_model.cpp | 2 | ||||
-rw-r--r-- | utils/training/merge_k_mixture_model.cpp | 36 |
2 files changed, 35 insertions, 3 deletions
diff --git a/utils/training/gen_k_mixture_model.cpp b/utils/training/gen_k_mixture_model.cpp index a2731e9..a720a66 100644 --- a/utils/training/gen_k_mixture_model.cpp +++ b/utils/training/gen_k_mixture_model.cpp @@ -42,7 +42,7 @@ void print_help(){ printf(" [--maximum-ocurrs-allowed <INT>]\n"); printf(" [--maximum-increase-rates-allowed <FLOAT>]\n"); printf(" [--k-mixture-model-file <FILENAME>]\n"); - printf(" {<FILENAME>}+"); + printf(" {<FILENAME>}+\n"); } diff --git a/utils/training/merge_k_mixture_model.cpp b/utils/training/merge_k_mixture_model.cpp index 79434db..d91c03f 100644 --- a/utils/training/merge_k_mixture_model.cpp +++ b/utils/training/merge_k_mixture_model.cpp @@ -19,11 +19,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <locale.h> #include "pinyin.h" #include "k_mixture_model.h" void print_help(){ - printf("merge_k_mixture_model <RESULT_FILENAME> {<SOURCE_FILENAME>}+\n"); + printf("merge_k_mixture_model [--result-file <RESULT_FILENAME>]\n"); + printf(" {<SOURCE_FILENAME>}+\n"); } @@ -196,7 +198,7 @@ static bool merge_array_items( /* in & out */ KMixtureModelBigram * target, } bool merge_two_k_mixture_model( /* in & out */ KMixtureModelBigram * target, - /* in */ KMixtureModelBigram * new_one ){ + /* in */ KMixtureModelBigram * new_one ){ assert(NULL != target); assert(NULL != new_one); return merge_array_items(target, new_one) && @@ -205,6 +207,36 @@ 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; + } + + KMixtureModelBigram target(K_MIXTURE_MODEL_MAGIC_NUMBER); + target.attach(result_filename, ATTACH_READWRITE|ATTACH_CREATE); + + while ( i < argc ){ + const char * new_filename = argv[i]; + KMixtureModelBigram new_one(K_MIXTURE_MODEL_MAGIC_NUMBER); + new_one.attach(new_filename, ATTACH_READONLY); + merge_two_k_mixture_model(&target, &new_one); + ++i; + } + return 0; } |