Skip to content

Commit

Permalink
Add: 辞書コンパイルに-qオプションを追加 (r9y9#8)
Browse files Browse the repository at this point in the history
* Add: 辞書コンパイルに-qを追加

* Delete: 関数のquietオプションを削除

* Fix: quietオプションが残っているのを修正

* Fix: quiet引数を使っていたのを修正

* Fix: thread_localのフォールバックを追加

* Fix: msvcでの動作を修正

* Update src/mecab/src/dictionary_generator.cpp

Co-authored-by: Hiroshiba <[email protected]>

* Delete: thread_localを削除

* Change: CHECK_DIEはquietでも出るように

* Fix: まだ出力が出ていたのを修正

* cerr2箇所を戻す

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
sevenc-nanashi and Hiroshiba authored Jul 6, 2023
1 parent acd0cc6 commit 7e7a946
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/mecab/src/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ bool Dictionary::compile(const Param &param,
}
}

std::cout << "reading " << dics[i] << " ... ";
if (!MeCab::quiet_mode)
std::cout << "reading " << dics[i] << " ... ";

scoped_fixed_array<char, BUF_SIZE> line;
size_t num = 0;
Expand Down Expand Up @@ -455,7 +456,8 @@ bool Dictionary::compile(const Param &param,
++lexsize;
}

std::cout << num << std::endl;
if (!MeCab::quiet_mode)
std::cout << num << std::endl;
}

if (wakati) {
Expand Down
17 changes: 14 additions & 3 deletions src/mecab/src/dictionary_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include <string>
#include "char_property.h"
#include "common.h"
#include "connector.h"
#include "dictionary.h"
#include "dictionary_rewriter.h"
Expand All @@ -20,6 +21,8 @@

namespace MeCab {

bool quiet_mode = false;

class DictionaryComplier {
public:
static int run(int argc, char **argv) {
Expand Down Expand Up @@ -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 }
Expand All @@ -74,8 +78,11 @@ class DictionaryComplier {
bool opt_model = param.get<bool>("build-model");
bool opt_assign_user_dictionary_costs = param.get<bool>
("assign-user-dictionary-costs");
bool opt_quiet = param.get<bool>("quiet");
const std::string userdic = param.get<std::string>("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()

Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -141,7 +150,9 @@ class DictionaryComplier {
}
}

std::cout << "\ndone!\n";
if (!opt_quiet) {
std::cout << "\ndone!\n";
}

return 0;
}
Expand Down
10 changes: 6 additions & 4 deletions src/mecab/src/dictionary_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class DictionaryGenerator {
std::ifstream ifs(WPATH(filename));
CHECK_DIE(ifs) << "no such file or directory: " << filename;
scoped_fixed_array<char, BUF_SIZE> 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];
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions src/mecab/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/mecab/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 7e7a946

Please sign in to comment.