diff --git a/src/mecab/src/dictionary.cpp b/src/mecab/src/dictionary.cpp index 04b080c..a95053b 100644 --- a/src/mecab/src/dictionary.cpp +++ b/src/mecab/src/dictionary.cpp @@ -319,7 +319,8 @@ bool Dictionary::compile(const Param ¶m, } } - std::cout << "reading " << dics[i] << " ... "; + if (!MeCab::quiet_mode) + std::cout << "reading " << dics[i] << " ... "; scoped_fixed_array line; size_t num = 0; @@ -455,7 +456,8 @@ bool Dictionary::compile(const Param ¶m, ++lexsize; } - std::cout << num << std::endl; + if (!MeCab::quiet_mode) + std::cout << num << std::endl; } if (wakati) { diff --git a/src/mecab/src/dictionary_compiler.cpp b/src/mecab/src/dictionary_compiler.cpp index 9155398..8b443d5 100644 --- a/src/mecab/src/dictionary_compiler.cpp +++ b/src/mecab/src/dictionary_compiler.cpp @@ -7,6 +7,7 @@ #include #include #include "char_property.h" +#include "common.h" #include "connector.h" #include "dictionary.h" #include "dictionary_rewriter.h" @@ -20,6 +21,8 @@ namespace MeCab { +bool quiet_mode = false; + class DictionaryComplier { public: static int run(int argc, char **argv) { @@ -48,6 +51,7 @@ class DictionaryComplier { { "posid", 'p', 0, 0, "assign Part-of-speech id" }, { "node-format", 'F', 0, "STR", "use STR as the user defined node format" }, + { "quiet", 'q', 0, 0, "don't print progress" }, { "version", 'v', 0, 0, "show the version and exit." }, { "help", 'h', 0, 0, "show this help and exit." }, { 0, 0, 0, 0 } @@ -74,8 +78,11 @@ class DictionaryComplier { bool opt_model = param.get("build-model"); bool opt_assign_user_dictionary_costs = param.get ("assign-user-dictionary-costs"); + bool opt_quiet = param.get("quiet"); const std::string userdic = param.get("userdic"); + MeCab::quiet_mode = opt_quiet; + #define DCONF(file) create_filename(dicdir, std::string(file)).c_str() #define OCONF(file) create_filename(outdir, std::string(file)).c_str() @@ -124,8 +131,10 @@ class DictionaryComplier { DCONF(MODEL_DEF_FILE), OCONF(MODEL_FILE)); } else { - std::cout << DCONF(MODEL_DEF_FILE) - << " is not found. skipped." << std::endl; + if (!opt_quiet) { + std::cout << DCONF(MODEL_DEF_FILE) + << " is not found. skipped." << std::endl; + } } } @@ -141,7 +150,9 @@ class DictionaryComplier { } } - std::cout << "\ndone!\n"; + if (!opt_quiet) { + std::cout << "\ndone!\n"; + } return 0; } diff --git a/src/mecab/src/dictionary_generator.cpp b/src/mecab/src/dictionary_generator.cpp index fdbbf26..6f133dc 100644 --- a/src/mecab/src/dictionary_generator.cpp +++ b/src/mecab/src/dictionary_generator.cpp @@ -47,7 +47,8 @@ class DictionaryGenerator { std::ifstream ifs(WPATH(filename)); CHECK_DIE(ifs) << "no such file or directory: " << filename; scoped_fixed_array line; - std::cout << "reading " << filename << " ... " << std::flush; + if (!MeCab::quiet_mode) + std::cout << "reading " << filename << " ... " << std::flush; size_t num = 0; std::string feature, ufeature, lfeature, rfeature; char *col[8]; @@ -252,9 +253,10 @@ class DictionaryGenerator { gencid(it->c_str(), &rewrite, &cid); } - std::cout << "emitting " - << OCONF(LEFT_ID_FILE) << "/ " - << OCONF(RIGHT_ID_FILE) << std::endl; + if (!MeCab::quiet_mode) + std::cout << "emitting " + << OCONF(LEFT_ID_FILE) << "/ " + << OCONF(RIGHT_ID_FILE) << std::endl; cid.build(); cid.save(OCONF(LEFT_ID_FILE), OCONF(RIGHT_ID_FILE)); diff --git a/src/mecab/src/utils.cpp b/src/mecab/src/utils.cpp index 7bcc30f..1c1f9a0 100644 --- a/src/mecab/src/utils.cpp +++ b/src/mecab/src/utils.cpp @@ -278,6 +278,8 @@ bool escape_csv_element(std::string *w) { } int progress_bar(const char* message, size_t current, size_t total) { + if (MeCab::quiet_mode) + return 1; static char bar[] = "###########################################"; static int scale = sizeof(bar) - 1; static int prev = 0; diff --git a/src/mecab/src/utils.h b/src/mecab/src/utils.h index ea5c9e9..00f3b95 100644 --- a/src/mecab/src/utils.h +++ b/src/mecab/src/utils.h @@ -38,6 +38,8 @@ typedef unsigned __int64 uint64_t; namespace MeCab { +extern bool quiet_mode; + class Param; enum { EUC_JP, CP932, UTF8, UTF16, UTF16LE, UTF16BE, ASCII };