Skip to content

Commit 7e7a946

Browse files
Add: 辞書コンパイルに-qオプションを追加 (r9y9#8)
* 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]>
1 parent acd0cc6 commit 7e7a946

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src/mecab/src/dictionary.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ bool Dictionary::compile(const Param &param,
319319
}
320320
}
321321

322-
std::cout << "reading " << dics[i] << " ... ";
322+
if (!MeCab::quiet_mode)
323+
std::cout << "reading " << dics[i] << " ... ";
323324

324325
scoped_fixed_array<char, BUF_SIZE> line;
325326
size_t num = 0;
@@ -455,7 +456,8 @@ bool Dictionary::compile(const Param &param,
455456
++lexsize;
456457
}
457458

458-
std::cout << num << std::endl;
459+
if (!MeCab::quiet_mode)
460+
std::cout << num << std::endl;
459461
}
460462

461463
if (wakati) {

src/mecab/src/dictionary_compiler.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88
#include <string>
99
#include "char_property.h"
10+
#include "common.h"
1011
#include "connector.h"
1112
#include "dictionary.h"
1213
#include "dictionary_rewriter.h"
@@ -20,6 +21,8 @@
2021

2122
namespace MeCab {
2223

24+
bool quiet_mode = false;
25+
2326
class DictionaryComplier {
2427
public:
2528
static int run(int argc, char **argv) {
@@ -48,6 +51,7 @@ class DictionaryComplier {
4851
{ "posid", 'p', 0, 0, "assign Part-of-speech id" },
4952
{ "node-format", 'F', 0, "STR",
5053
"use STR as the user defined node format" },
54+
{ "quiet", 'q', 0, 0, "don't print progress" },
5155
{ "version", 'v', 0, 0, "show the version and exit." },
5256
{ "help", 'h', 0, 0, "show this help and exit." },
5357
{ 0, 0, 0, 0 }
@@ -74,8 +78,11 @@ class DictionaryComplier {
7478
bool opt_model = param.get<bool>("build-model");
7579
bool opt_assign_user_dictionary_costs = param.get<bool>
7680
("assign-user-dictionary-costs");
81+
bool opt_quiet = param.get<bool>("quiet");
7782
const std::string userdic = param.get<std::string>("userdic");
7883

84+
MeCab::quiet_mode = opt_quiet;
85+
7986
#define DCONF(file) create_filename(dicdir, std::string(file)).c_str()
8087
#define OCONF(file) create_filename(outdir, std::string(file)).c_str()
8188

@@ -124,8 +131,10 @@ class DictionaryComplier {
124131
DCONF(MODEL_DEF_FILE),
125132
OCONF(MODEL_FILE));
126133
} else {
127-
std::cout << DCONF(MODEL_DEF_FILE)
128-
<< " is not found. skipped." << std::endl;
134+
if (!opt_quiet) {
135+
std::cout << DCONF(MODEL_DEF_FILE)
136+
<< " is not found. skipped." << std::endl;
137+
}
129138
}
130139
}
131140

@@ -141,7 +150,9 @@ class DictionaryComplier {
141150
}
142151
}
143152

144-
std::cout << "\ndone!\n";
153+
if (!opt_quiet) {
154+
std::cout << "\ndone!\n";
155+
}
145156

146157
return 0;
147158
}

src/mecab/src/dictionary_generator.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class DictionaryGenerator {
4747
std::ifstream ifs(WPATH(filename));
4848
CHECK_DIE(ifs) << "no such file or directory: " << filename;
4949
scoped_fixed_array<char, BUF_SIZE> line;
50-
std::cout << "reading " << filename << " ... " << std::flush;
50+
if (!MeCab::quiet_mode)
51+
std::cout << "reading " << filename << " ... " << std::flush;
5152
size_t num = 0;
5253
std::string feature, ufeature, lfeature, rfeature;
5354
char *col[8];
@@ -252,9 +253,10 @@ class DictionaryGenerator {
252253
gencid(it->c_str(), &rewrite, &cid);
253254
}
254255

255-
std::cout << "emitting "
256-
<< OCONF(LEFT_ID_FILE) << "/ "
257-
<< OCONF(RIGHT_ID_FILE) << std::endl;
256+
if (!MeCab::quiet_mode)
257+
std::cout << "emitting "
258+
<< OCONF(LEFT_ID_FILE) << "/ "
259+
<< OCONF(RIGHT_ID_FILE) << std::endl;
258260

259261
cid.build();
260262
cid.save(OCONF(LEFT_ID_FILE), OCONF(RIGHT_ID_FILE));

src/mecab/src/utils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ bool escape_csv_element(std::string *w) {
278278
}
279279

280280
int progress_bar(const char* message, size_t current, size_t total) {
281+
if (MeCab::quiet_mode)
282+
return 1;
281283
static char bar[] = "###########################################";
282284
static int scale = sizeof(bar) - 1;
283285
static int prev = 0;

src/mecab/src/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ typedef unsigned __int64 uint64_t;
3838

3939
namespace MeCab {
4040

41+
extern bool quiet_mode;
42+
4143
class Param;
4244

4345
enum { EUC_JP, CP932, UTF8, UTF16, UTF16LE, UTF16BE, ASCII };

0 commit comments

Comments
 (0)