
目次
サンプル・プログラム
normalizetextwin.msi | インストーラ |
bin/normalizetextwin.exe | 実行プログラム本体(GUI版) |
bin/nmtxt.exe | 実行プログラム本体(CUI版) |
bin/option.txt | 正規化オプションを保存するファイル |
bin/libgcc_s_seh-1.dll bin/libiconv-2.dll bin/libmecab-2.dll bin/libstdc++-6.dll bin/libwinpthread-1.dll | 実行時に必要になるDLL |
bin/etc/help.chm | ヘルプ・ファイル |
bin/etc/char.bin bin/etc/dicrc bin/etc/matrix.bin bin/etc/sys.dic bin/etc/unk.dic bin/etc/user_wiki.dic | MeCabが参照する辞書ファイル等 |
sour/normalizetextwin.cpp | ソース・プログラム |
sour/resource.h | リソース・ヘッダ |
sour/resource.rc | リソース・ファイル(GUI版) |
sour/resource2.rc | リソース・ファイル(CUI版) |
sour/application.ico | アプリケーション・アイコン(GUI版) |
sour/application2.ico | アプリケーション・アイコン(CUI版) |
sour/pahooNormalizeText.cpp | テキスト正規化クラス(ソース) |
sour/pahooNormalizeText.hpp | テキスト正規化クラス(ヘッダ) |
sour/makefile | GUI版ビルド |
sour/makefile_cmd | CUI版ビルド |
バージョン | 更新日 | 内容 |
---|---|---|
1.9.4 | 2025/03/29 | MeCabユーザー辞書更新,使用ライブラリ更新 |
1.9.3 | 2024/12/15 | MeCabユーザー辞書更新,使用ライブラリ更新 |
1.9.2 | 2024/08/24 | MeCabユーザー辞書更新,使用ライブラリ更新 |
1.9.1 | 2024/04/07 | MeCabユーザー辞書更新,使用ライブラリ更新 |
1.9.0 | 2023/10/25 | 全角二重引用符の開閉置換処理を追加 |
バージョン | 更新日 | 内容 |
---|---|---|
1.9.1 | 2023/12/17 | pahooNormalizeText() - MECAB非使用時の対策 |
1.9.0 | 2023/10/25 | normalizeText() - 二重引用符の開閉処理 |
1.8.0 | 2023/10/25 | pahooNormalizeText() - MeCab動作チェック追加 |
1.7.2 | 2023/07/30 | bignum2scale() - wsourの中に400万と4億が混在する場合にも対応 |
1.7.1 | 2023/04/22 | toHankaku() - 「一九」対応 |
使用ライブラリ
また、CUI版でコマンダイン・オプションを操作する場合などに、オープンソースのライブラリ Boost C++ライブラリが必要になる。Boost C++ライブラリの導入方法等については、「C++ 開発環境の準備」をご覧いただきたい。
リソースの準備
ResEdit を起動し、resource.rc を用意する。

Eclipse に戻り、ソース・プログラム "normalizetextwin.cpp" を追加する。
リンカー・フラグを -mwindows -static-libstdc++ -static-libgcc -lpthread -lwinpthread -static "(任意のパス)\libboost_program_options-mt.dll" -static "(任意のパス)\libmecab-2.dll" に設定する。
また、CUI版をビルドするために、構成 CMD を追加し、リンカー・フラグを -static-libstdc++ -static-libgcc -lpthread -static "(任意のパス)\libboost_program_options-mt.dll" -static "(任意のパス)\libmecab-2.dll"" に設定する。

MSYS2 コマンドラインからビルドするのであれば、"makefile" と "makefile_cmd" を利用してほしい。
日本語形態素解析システム「MeCab」の導入

公式ダウンロートサイトから Binary package for MS-Windows をダウンロードする。2023年(令和5年)10月現在、"mecab-0.996.exe" がダウンロードできる。ダウンロードした実行プログラムを実行すると、インストールがはじまる。
インストール先は任意。辞書ファイルのエンコードは Shift-JIS を指定すること。

MeCab については「PHPで MeCabのユーザー辞書を作成する」で紹介したが、簡単に振り返っておくと、入力されたテキストを日本語の品詞に分解する形態素解析エンジンと呼ばれるプログラムである。
なぜテキストの正規化に形態素解析エンジンが必要かというと、たとえば「千と千尋の神隠しという映画を見た」というテキストをそのまま正規化してしまうと、「千」を数字と解釈し、「1000と1000尋の神隠しという映画を見た」という変換結果になってしまうためである。
テキスト中にある固有名詞は数字変換の対象としないように除外するため、形態素解析エンジンを利用する。形態素解析エンジンであれば MeCab でなくても構わないのだが、C++から利用可能なDLLファイルが利用できることから、ここでは MeCab を採用する。

MeCab を64ビット環境でビルドすると、"libmecab-2.dll" が得られる。これを適当なディレクトリに配置し、リンクするようにする。

MSYS2 開発環境では、次のように pacman を使い iconv と MeCab ライブラリをインストールできる。
64ビット版:
pacman -S mingw-w64-x86_64-libiconv
pacman -S mingw-w64-x86_64-mecab

MeCab のユーザー辞書であるが、前述の通り、固有名詞を識別するのが目的であるので、Wikipediaの見出し語をユーザー辞書として用意することにした。Wikipediaユーザー辞書の作るプログラムは、前述の「PHPで MeCabのユーザー辞書を作成する」で紹介している。
プログラムの流れ

変換ボタンがクリックされたら、toHankaku メソッドを使って半角か可能な文字を全て半角にする。その後、正規化オプションの値に応じて全角化、漢数字化を行ってゆく。
解説:テキスト正規化クラス
pahooNormalizeText.hpp
32: //正規化オプション
33: #define OPTION_SPC_TRIM1 't' //行頭・行末の空白文字を除く
34: #define OPTION_SPC_TRIM2 'T' //全角文字と隣り合う空白文字を除く
35: #define OPTION_NUM_HAN 'n' //数字を半角に統一
36: #define OPTION_NUM_ZEN 'N' //数字を全角に統一
37: #define OPTION_NUM_KAN 'K' //数字を漢字に統一
38: #define OPTION_NUM_KAN2 'k' //数字を漢字(単純)に統一
39: #define OPTION_ALP_HAN 'a' //英字を半角に統一
40: #define OPTION_ALP_ZEN 'A' //英字を全角に統一
41: #define OPTION_YAK_HAN 'y' //記号を半角に統一
42: #define OPTION_YAK_ZEN 'Y' //記号を全角に統一
43: #define OPTION_KANA_HAN 'h' //カタカナを半角に統一
44: #define OPTION_KANA_ZEN 'H' //カタカナを全角に統一
45: #define OPTION_SPEC_HAN 's' //特殊文字を半角に統一
46: #define OPTION_SPEC_ZEN 'S' //特殊文字を全角に統一
47: #define OPTION_NUM_SCALE 'F' //数字を位取り記法にする
48: #define OPTION_NUM_NOSCALE 'f' //数字を位取り記法にしない
49: #define OPTION_CONTROL_DEL 'c' //制御文字を削除する
50: #define OPTION_DBL_QUOTE 'D' //二重引用符の開閉置換
51:
52: //正規化オプションの初期値
53: #define OPTION_INIT "anYSHF"
解説:MeCabの呼び出し
pahooNormalizeText.hpp
123: private:
124: #ifdef MECAB
125: MeCab::Tagger *tagger = MeCab::createTagger("--dicdir=etc --userdic=etc/user_wiki.dic --node-format=%M\\t%f[0],%f[1],%f[2],%f[3],%f[4],%f[5],%f[6],%f[7],%f[8]\\n --unk-format=%M\\t%f[0],%f[1],%f[2],%f[3],%f[4],%f[5]\\n");
ここで、前述のWikipediaユーザー辞書 "user_wiki.dic" などを指定する。
解説:半角数字を漢数字に変換
pahooNormalizeText.cpp
230: /**
231: * 半角数字を漢数字に変換する
232: * @param wstring instr 半角数字
233: * 小数、負数に対応;指数表記には未対応
234: * カンマは削除
235: * @return wstring 漢数字
236: */
237: wstring pahooNormalizeText::num2kanji(wstring instr) {
238: static wchar_t kantbl1[] =
239: { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
240: L'8', L'9', L'.', L'-' };
241: static wchar_t kantbl2[] =
242: { 0x0000, 0x4E00, 0x4E8C, 0x4E09, 0x56DB, 0x4E94, 0x516D, //一〜九
243: 0x4E03, 0x516B, 0x4E5D, 0xFF0E, 0xFF0D }; //.−
244: static wchar_t kantbl3[] = { 0x0000, 0x5341, 0x767E, 0x5343 }; //十百千
245: static wchar_t kantbl4[] = { 0x0000, 0x4E07, 0x5104, 0x5146, 0x4EAC }; //万億兆京
246:
247: wstring outstr = L"";;
248: wstring ws2;
249: wchar_t wch1, wch2;
250: int m = (int)instr.length() / 4;
251: //一、万、億、兆‥‥の繰り返し
252: for (int i = 0; i <= m; i++) {
253: ws2 = L"";
254: //一、十、百、千の繰り返し
255: for (int j = 0; j < 4; j++) {
256: int pos = instr.length() - i * 4 - j - 1;
257: if (pos >= 0) {
258: wchar_t* wch = (wchar_t*)instr.substr(pos, 1).c_str();
259: if (*wch == L',') continue; //カンマは無視
260: for (int k = 0; k < (int)(sizeof(kantbl1) / sizeof(kantbl1[0])); k++) {
261: //漢数字 or 半角数字のまま
262: wch1 = 0x0000;
263: if (*wch == kantbl1[k]) {
264: wch1 = kantbl2[k];
265: break;
266: }
267: }
268: wch2 = 0x0000;;
269: if ((j >= 0) && (j <= 3)) {
270: wch2 = kantbl3[j];
271: }
272:
273: //冒頭が「一」の場合の処理
274: if (wch1 != 0x0000) {
275: if ((wch1 == 0x4E00) && (wch2 != 0x0000)) {
276: ws2 = (wstring){wch2} + ws2;
277: } else if (wch2 != 0x0000) {
278: ws2 = (wstring){wch1} + (wstring){wch2} + ws2;
279: } else {
280: ws2 = (wstring){wch1} + ws2;
281: }
282: }
283: }
284: }
285: if (ws2 != L"") {
286: if (kantbl4[i] == 0x0000) {
287: outstr = ws2 + outstr;
288: } else {
289: outstr = ws2 + (wstring){kantbl4[i]} + outstr;
290: }
291: }
292: }
293:
294: return outstr;
295: }
右から左へ向かって逆順に処理し、4桁ごとに、万、億、兆、京の単位を付けてゆく。各々の4桁の中で、十、百、千を付ける。冒頭が「一」の場合は「一百」にならないよう配慮する。
解説:解説:半角数字を漢数字(単純)に変換
pahooNormalizeText.cpp
360: /**
361: * 半角数字を漢数字に変換する(単純変換)
362: * @param wstring wsour 半角数字を含む文字列
363: * @return wstring 漢数字
364: */
365: wstring pahooNormalizeText::num2kanSimple(wstring wsour) {
366: static wchar_t kantbl1[] =
367: { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
368: L'8', L'9', L'.', L'-' };
369: static wchar_t kantbl2[] =
370: { 0x3007, 0x4E00, 0x4E8C, 0x4E09, 0x56DB, 0x4E94, 0x516D, //一〜九
371: 0x4E03, 0x516B, 0x4E5D, 0xFF0E, 0xFF0D }; //.−
372:
373: //左から1文字ずつ処理
374: wstring wdest = L"";
375: wstring wstr;
376: wchar_t* wch;
377: bool flag;
378: for (int pos = 0; pos < (int)wsour.length(); pos++) {
379: flag = FALSE;
380: wstr = wsour.substr(pos, 1);
381: wch = (wchar_t*)wstr.c_str();
382: for (int k = 0; k < (int)(sizeof(kantbl1) / sizeof(kantbl1[0])); k++) {
383: if (*wch == kantbl1[k]) {
384: wdest += (wstring){kantbl2[k]};
385: flag = TRUE;
386: break;
387: }
388: }
389: if (! flag) {
390: wdest += *wch;
391: }
392: }
393: return wdest;
394: }
左から右へ向かって、算用数字にマッチする文字があれば漢数字に置換する。
解説:半角数字を位取り記法に変換
pahooNormalizeText.cpp
297: /**
298: * 半角数字を位取り記法に変換する
299: * @param wstring instr 半角数字(小数,負数,指数表記は未対応)
300: * @return wstring 位取り記法
301: */
302: wstring pahooNormalizeText::num2scale(wstring instr) {
303: static wchar_t kantbl[] = { 0x0000, 0x4E07, 0x5104, 0x5146, 0x4EAC }; //万億兆京
304: //余計な'0'を除く
305: wregex re(_SW("0+([1-9]+)|0+([1-9]+)"));
306:
307: //桁あふれ
308: if (instr.length() > 20) {
309: return instr;
310: }
311:
312: //右から1文字ずつ処理
313: wstring outstr = L"";
314: wstring ws = L"";
315: int i = 0;
316: bool flag = FALSE;
317: for (int pos = instr.length() - 1; pos >= 0; pos--) {
318: if (flag) {
319: outstr = (wstring){kantbl[(int)(i / 4)]} + outstr;
320: flag = FALSE;
321: }
322: wstring ss = instr.substr(pos, 1);
323: ws = ss + ws;
324: i++;
325: if (i % 4 == 0) {
326: if ((ws == L"0000") || (ws == _SW("0000"))) {
327: outstr = (wstring){kantbl[(int)(i / 4)]};
328: } else {
329: outstr = regex_replace(ws, re, L"$1") + outstr;
330: flag = TRUE;
331: }
332: ws = L"";
333: }
334: }
335: outstr = ws + outstr;
336:
337: return outstr;
338: }
解説:漢数字を半角数字に変換
pahooNormalizeText.cpp
416: /**
417: * 漢数字を半角数字に変換する
418: * @param wstring kanji 漢数字
419: * @param int mode 出力書式/1=3桁カンマ区切り,2=漢字混じり, それ以外=ベタ打ち
420: * @return wstring 半角数字
421: */
422: wstring pahooNormalizeText::kan2num(wstring kanji, int mode) {
423: wstring dest = L"";
424: wsmatch mt1;
425:
426: //全角=半角対応
427: const wstring kan_num1 = _SW("0〇○1一壱2二弐3三参4四5五6六7七8八9九");
428: const wstring kan_num2 = _SW("000111222333445566778899");
429:
430: //位取り
431: const wstring kan_deci_sub = _SW("十\百千");
432: const wstring kan_deci = _SW("万億兆京");
433:
434: //半角数字が混在していたら何もしない
435: wregex re1(_SW("[0-9]+"));
436: if (regex_search(kanji, mt1, re1)) {
437: return kanji;
438: }
439:
440: //右側から解釈していく
441: size_t ll = kanji.length();
442: wstring a = L"";
443: long long int deci = 1;
444: long long int deci_sub = 1;
445: long long int m = 0;
446: long long int n = 0;
447:
448: for (int pos = ll - 1; pos >= 0; pos--) {
449: wstring c = kanji.substr(pos, 1);
450: size_t ps1 = kan_num1.find(c);
451: size_t ps2 = kan_deci_sub.find(c);
452: size_t ps3 = kan_deci.find(c);
453: if (ps1 != wstring::npos) {
454: a = kan_num2.substr(ps1, 1) + a;
455: } else if (ps2 != wstring::npos) {
456: if (a != L"") {
457: m = m + stol(a) * deci_sub;
458: } else if (deci_sub != 1) {
459: m = m + deci_sub;
460: }
461: a = L"";
462: deci_sub = pow(10, ps2 + 1);
463: } else if (ps3 != wstring::npos) {
464: if (a != L"") {
465: m = m + stol(a) * deci_sub;
466: } else if (deci_sub != 1) {
467: m = m + deci_sub;
468: }
469: n = m * (long long int)deci + n;
470: m = 0;
471: a = L"";
472: deci_sub = 1;
473: deci = (long long int)pow(10000, ps3 + 1);
474: }
475: }
476:
477: wstring ss = L"";
478: wregex re2(_SW("^(0+)"));
479: if (regex_search(a, mt1, re2)) {
480: ss = mt1[1].str();
481: }
482: if (a != L"") {
483: m = m + stol(a) * deci_sub;
484: } else if (deci_sub != 1) {
485: m = m + deci_sub;
486: }
487: n = m * deci + n;
488:
489: return to_wstring(n);
490: }
解説:日本語テキストを半角に統一
pahooNormalizeText.cpp
530: /**
531: * 日本語テキストを半角に統一
532: * @param wstring sour 変換元テキスト
533: * @param bool trim 行頭・行末の空白を除くかどうか
534: * @return string 変換後テキスト
535: */
536: wstring pahooNormalizeText::toHankaku(wstring wsour, bool trim) {
537: regex sep{"\\t|,"};
538: wsmatch mt1, mt2, mt3;
539: //数字パターン
540: wregex pat_kannum(_SW("^[^数]*[01234567890123456789○〇一二三四五六七八九十\百千万億兆京]+$"));
541: //MeCabの品詞パターン
542: wregex re1(_SW("[数幾]"));
543: //「一九」対応
544: wregex re19(_SW("一九"));
545: //月の漢数字
546: wregex re2(_SW("([一二三四五六七八九十\]+)(月)"));
547: //名詞接続の場合はそのまま
548: wregex re3(_SW("名詞接続"));
549: //行頭空白パターン
550: wregex re4(_SW("^[ \\t\\n\\r]+"));
551: //行末空白パターン
552: wregex re5(_SW("[ \\t\\n\\r]+$"));
553: //無変換パターン・その1
554: wregex re71(_SW("副詞可.+"));
555: wregex re72(_SW("接尾|格助詞"));
556: //無変換パターン・その2
557: wregex re8(_SW("^[千万億兆]+$"));
558: //無変換パターン・その3
559: wregex re9(_SW("一生"));
560:
561: //カンマ置換
562: wregex re6(_SW(","));
563: wsour = regex_replace(wsour, re6, _SW(","));
564:
565: //形態素に分解
566: string input = _WS(wsour);
567: const char *words = tagger->parse(input.c_str());
568:
569: //変換処理
570: bool flag = FALSE;
571: bool adverb = FALSE;
572: wstring dest = L"";
573: wstring numstr = L"";
574: wstring surface, pos;
575:
576: //1行ずつ読み込む
577: string ss0;
578: stringstream ss;
579: ss << words;
580: while(ss && getline(ss, ss0)) {
581: int cnt = 0;
582: for (std::cregex_token_iterator end,
583: ite{ss0.c_str(), ss0.c_str() + strlen(ss0.c_str()), sep, -1};
584: ite != end; ++ite) {
585: if (cnt == 0) surface = _SW((*ite).str().c_str());
586: else if (cnt == 2) pos = _SW((*ite).str().c_str());
587: cnt++;
588: }
589: // clog << _WS(surface) << " : " << _WS(pos) << endl;
590:
591: //最後
592: if (surface == _SW("EOS")) {
593: break;
594: //月の処理
595: } else if (regex_search(surface, mt1, re2)) {
596: dest += this->kan2num(mt1[1].str(), 2) + mt1[2].str();
597: //無変換
598: } else if (regex_search(pos, mt1, re71) || regex_search(surface, mt1, re9)) {
599: clog << _WS(surface) << endl;
600: dest += surface;
601: } else if (flag == FALSE) {
602: //副詞可能な数字
603: if (regex_search(pos, mt2, re71)) {
604: numstr = surface;
605: flag = TRUE;
606: adverb = TRUE;
607: //漢数字の1文字目
608: } else if (regex_search(surface, mt1, pat_kannum) && regex_search(pos, mt2, re1)) {
609: numstr = surface;
610: flag = TRUE;
611: adverb = FALSE;
612: //「一九」対応
613: } else if (regex_search(surface, mt2, re19)) {
614: numstr = surface;
615: flag = TRUE;
616: adverb = FALSE;
617: //数字ではない
618: } else {
619: dest += surface;
620: }
621: } else {
622: //無変換(副詞可能+接尾)
623: if (adverb && regex_search(pos, mt2, re72)) {
624: dest += (numstr + surface);
625: numstr = L"";
626: flag = FALSE;
627: adverb = FALSE;
628: //漢数字の2文字目以降
629: } else if (regex_search(surface, mt1, pat_kannum)) {
630: numstr += surface;
631: flag = TRUE;
632: //数字以外
633: } else {
634: //名詞接続の場合はそのまま
635: if (regex_search(pos, mt2, re3)) {
636: dest += (numstr + surface);
637: //無変換パターン
638: } else if (regex_search(numstr, mt1, re8)) {
639: dest += (numstr + surface);
640: //副詞可能の場合
641: } else if (adverb) {
642: dest += (this->kanword2num(numstr) + surface);
643: //ここまでの漢数字を半角数字に
644: } else {
645: dest += (this->kan2num(numstr, 2) + surface);
646: }
647: numstr = L"";
648: flag = FALSE;
649: adverb = FALSE;
650: }
651: }
652: }
653:
654: //末尾処理
655: if (flag == TRUE) {
656: if (adverb == TRUE) {
657: dest += numstr;
658: } else {
659: dest += this->kan2num(numstr, 2);
660: }
661: }
662:
663: //行頭・行末空白処理
664: if (trim) {
665: wstring wss = regex_replace(dest, re4, L"");
666: wss = regex_replace(wss, re5, L"");
667: dest = wss + L"\\n";
668: }
669:
670: //「十八番」対応
671: wregex re11(_SW("一八([^番]+)"));
672: dest = regex_replace(dest, re11, L"18$1");
673: //「・」対応
674: wregex re12(_SW("([0-9]+)・([0-9]+)"));
675: dest = regex_replace(dest, re12, L"$1.$2");
676:
677: return wconvString(dest, LCMAP_HALFWIDTH);
678: }
解説:日本語テキストを全角に変換
pahooNormalizeText.cpp
705: /**
706: * 半角→全角変換に変換
707: * @param wstring sour 変換元テキスト
708: * @param bool (*func) 該当文字判定関数
709: * @return wstring 変換後テキスト
710: */
711: wstring pahooNormalizeText::han2zen(wstring wsour, bool (*func)(wchar_t wch)) {
712: wstring wss = L"";
713: wstring wdest = L"";
714: bool flag = FALSE;
715: // clog << _WS(wsour) << endl;
716:
717: //先頭から1文字ずつ
718: for (size_t i = 0; i < wsour.length(); i++) {
719: wchar_t* wch = (wchar_t*)wsour.substr(i, 1).c_str();
720: //該当文字ならwss0へ
721: if (func(*wch)) {
722: wss += (wstring){*wch};
723: flag = TRUE;
724: //半角→全角変換
725: } else if (flag) {
726: wdest += wconvString(wss, LCMAP_FULLWIDTH);
727: wdest += wsour.substr(i, 1);
728: flag = FALSE;
729: wss = L"";
730: } else {
731: wdest += wsour.substr(i, 1);
732: }
733: }
734: //最後の1文字が該当文字
735: if (flag) {
736: wdest += wconvString(wss, LCMAP_FULLWIDTH);
737: }
738:
739: return wdest;
740: }
解説:日本語テキストを正規化する
pahooNormalizeText.cpp
742: /**
743: * 日本語テキストを正規化する
744: * @param wstring sour 漢数字混じりテキスト
745: * @param char* option 変換オプション
746: * @param bool trim 行頭・行末の空白を除くかどうか
747: * @return wstring 変換後テキスト
748: */
749: wstring pahooNormalizeText::normalizeText(const wstring wsour, const char* option, bool trim) {
750: wstring wdest = wsour;
751:
752: //フロントエンド置換
753: wdest = this->frontend_replace(wdest);
754:
755: //制御文字を削除する
756: if (strchr(option, OPTION_CONTROL_DEL) != NULL) {
757: wregex re2(_SW("([\\t\\r\\r]+)"));
758: wdest = regex_replace(wdest, re2, L"");
759: }
760:
761: //いったん半角に
762: #ifdef MECAB
763: wdest = this->toHankaku(wdest, trim);
764: #endif
765: clog << _WS(wdest) << endl;
766:
767: //全角文字と隣り合う空白文字を除く
768: wregex re11(_SW("[ \\t]+([^!-~].)"));
769: wdest = regex_replace(wdest, re11, L"$1");
770: wregex re12(_SW("([^!-~].)[ \\t]+"));
771: wdest = regex_replace(wdest, re12, L"$1");
772:
773: //英字:半角→全角
774: if (strchr(option, OPTION_ALP_ZEN) != NULL) {
775: wdest = this->han2zen(wdest, _alphabet);
776: }
777: //数字:位取り記法
778: if (strchr(option, OPTION_NUM_SCALE) != NULL) {
779: wdest = this->bignum2scale(wdest);
780: }
781: //数字:半角→全角
782: if (strchr(option, OPTION_NUM_ZEN) != NULL) {
783: wdest = this->han2zen(wdest, _decimal);
784: //数字:半角→漢数字
785: } else if (strchr(option, OPTION_NUM_KAN) != NULL) {
786: wdest = this->num2kan(wdest);
787: //数字:半角→漢数字(単純)
788: } else if (strchr(option, OPTION_NUM_KAN2) != NULL) {
789: wdest = this->num2kanSimple(wdest);
790: }
791: //記号:半角→全角
792: if (strchr(option, OPTION_YAK_ZEN) != NULL) {
793: wdest = this->han2zen(wdest, _yakumono);
794: }
795: //カタカナ:半角→全角
796: if (strchr(option, OPTION_KANA_ZEN) != NULL) {
797: wdest = this->han2zen(wdest, _katakana);
798: }
799: //小数点の全角を半角に変換
800: wdest = this->hanfloat(wdest);
801:
802: //半角文字と隣り合う全角空白は半角空白へ
803: wregex re2(_SW("[ ]+([!-~].)"));
804: wdest = regex_replace(wdest, re2, L" $1");
805:
806: //全角二重引用符の開閉
807: if (strchr(option, OPTION_DBL_QUOTE) != NULL) {
808: wregex re3(_SW("?W([^?W]*)?W"));
809: wdest = regex_replace(wdest, re3, _SW("“") + L"$1" + _SW("”"));
810: }
811:
812: return wdest;
813: }

オプション OPTION_DBL_QUOTE が指定されているとき、全角二重引用符の開閉置換を行う。
日本語テキストを半角に統一するとき、二重引用符系の記号は全て半角二重引用符 " (U+0022) に変換するのだが、記号の全角変換 OPTION_YAK_ZEN を指定しているときには、"..." を全角二重引用符の開閉“...”(U+201C…U+201D) に置換する。
解説:定数など
normalizetextwin.cpp
44: // 定数など ==================================================================
45: #define MAKER "pahoo.org" // 作成者
46: #define APPNAME "normalizetextwin" // アプリケーション名
47: #define APPNAMEJP "テキストの正規化" // アプリケーション名(日本語)
48: #define APPVERSION "1.9.4" // バージョン
49: #define APPYEAR "2020-25" // 作成年
50: #define REFERENCE "https://www.pahoo.org/e-soul/webtech/cpp01/cpp01-18-01.shtm" // 参考サイト
51:
52: // ヘルプ・ファイル
53: #define HELPFILE ".\\etc\\help.chm"
54:
55: // デフォルト保存ファイル名
56: #define SAVEFILE "normalizetextwin.txt"
57:
58: // オプション保存ファイル名:変更不可
59: #define OPTIONFILE "option.txt"
60:
61: // エラー・メッセージ格納用:変更不可
62: string ErrorMessage;
63:
64: // 現在のインターフェイス
65: HINSTANCE hInst;
66:
67: // アプリケーション・ウィンドウ
68: HWND hParent;
69:
70: // アプリケーション・ウィンドウ位置
71: unsigned hParent_X, hParent_Y;
72:
73: // pahooNormalizeTextオブジェクト
74: pahooNormalizeText* pNT;
75:
76: // char*バッファサイズ
77: #define SIZE_BUFF 5120
78:
79: // 変換元テキスト(初期値)
80: #define DEF_SOUR "『千と千尋の神隠し』(せんとちひろのかみかくし)は、スタジオジブリ制作の長編アニメーション映画。監督は宮崎駿。二〇〇一年七月二十\日に日本公開。興行収入は三百億円を超え、日本歴代興行収入第一位を達成した。英語のタイトルは『Spirited Away』。\n千尋という名の十\歳の少女が、引っ越し先へ向かう途中に立ち入ったトンネルから、神々の世界へ迷い込んでしまう物語。"
とくに注意記載が無い限り、定数は自由に変更できる。
解説:正規化オプション取得・設定
normalizetextwin.cpp
511: /**
512: * 正規化オプションを設定する
513: * @param HWND hDlg ウィンドウ・ハンドラ
514: * @param string opt 正規化オプション
515: * @return なし
516: */
517: void setOption(HWND hDlg, string opt) {
518: for (int i = 0; i < (int)opt.length(); i++) {
519: char* ch = (char*)opt.substr(i, 1).c_str();
520: switch (*ch) {
521: case OPTION_ALP_HAN:
522: SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_HAN),
523: BM_SETCHECK, BST_CHECKED, 0);
524: SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_ZEN),
525: BM_SETCHECK, BST_UNCHECKED, 0);
526: break;
527: case OPTION_ALP_ZEN:
528: SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_HAN),
529: BM_SETCHECK, BST_UNCHECKED, 0);
530: SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_ZEN),
531: BM_SETCHECK, BST_CHECKED, 0);
532: break;
533: case OPTION_NUM_HAN:
534: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_HAN),
535: BM_SETCHECK, BST_CHECKED, 0);
536: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_ZEN),
537: BM_SETCHECK, BST_UNCHECKED, 0);
538: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN),
539: BM_SETCHECK, BST_UNCHECKED, 0);
540: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN2),
541: BM_SETCHECK, BST_UNCHECKED, 0);
542: break;
543: case OPTION_NUM_ZEN:
544: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_HAN),
545: BM_SETCHECK, BST_UNCHECKED, 0);
546: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_ZEN),
547: BM_SETCHECK, BST_CHECKED, 0);
548: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN),
549: BM_SETCHECK, BST_UNCHECKED, 0);
550: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN2),
551: BM_SETCHECK, BST_UNCHECKED, 0);
552: break;
553: case OPTION_NUM_KAN:
554: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_HAN),
555: BM_SETCHECK, BST_UNCHECKED, 0);
556: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_ZEN),
557: BM_SETCHECK, BST_UNCHECKED, 0);
558: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN),
559: BM_SETCHECK, BST_CHECKED, 0);
560: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN2),
561: BM_SETCHECK, BST_UNCHECKED, 0);
562: break;
563: case OPTION_NUM_KAN2:
564: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_HAN),
565: BM_SETCHECK, BST_UNCHECKED, 0);
566: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_ZEN),
567: BM_SETCHECK, BST_UNCHECKED, 0);
568: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN),
569: BM_SETCHECK, BST_UNCHECKED, 0);
570: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN2),
571: BM_SETCHECK, BST_CHECKED, 0);
572: break;
573: case OPTION_NUM_SCALE:
574: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_SCALE),
575: BM_SETCHECK, BST_CHECKED, 0);
576: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_NOSCALE),
577: BM_SETCHECK, BST_UNCHECKED, 0);
578: break;
579: case OPTION_NUM_NOSCALE:
580: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_SCALE),
581: BM_SETCHECK, BST_UNCHECKED, 0);
582: SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_NOSCALE),
583: BM_SETCHECK, BST_CHECKED, 0);
584: break;
585: case OPTION_YAK_HAN:
586: SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_HAN),
587: BM_SETCHECK, BST_CHECKED, 0);
588: SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_ZEN),
589: BM_SETCHECK, BST_UNCHECKED, 0);
590: break;
591: case OPTION_YAK_ZEN:
592: SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_HAN),
593: BM_SETCHECK, BST_UNCHECKED, 0);
594: SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_ZEN),
595: BM_SETCHECK, BST_CHECKED, 0);
596: break;
597: case OPTION_KANA_HAN:
598: SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_HAN),
599: BM_SETCHECK, BST_CHECKED, 0);
600: SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_ZEN),
601: BM_SETCHECK, BST_UNCHECKED, 0);
602: break;
603: case OPTION_KANA_ZEN:
604: SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_HAN),
605: BM_SETCHECK, BST_UNCHECKED, 0);
606: SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_ZEN),
607: BM_SETCHECK, BST_CHECKED, 0);
608: break;
609: case OPTION_SPEC_HAN:
610: SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_HAN),
611: BM_SETCHECK, BST_CHECKED, 0);
612: SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_ZEN),
613: BM_SETCHECK, BST_UNCHECKED, 0);
614: break;
615: case OPTION_SPEC_ZEN:
616: SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_HAN),
617: BM_SETCHECK, BST_UNCHECKED, 0);
618: SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_ZEN),
619: BM_SETCHECK, BST_CHECKED, 0);
620: break;
621: case OPTION_CONTROL_DEL:
622: SendMessage(GetDlgItem(hDlg, IDC_CHECK_CONTROL_DEL),
623: BM_SETCHECK, BST_CHECKED, 0);
624: break;
625: case OPTION_DBL_QUOTE:
626: SendMessage(GetDlgItem(hDlg, IDC_CHECK_DBL_QUOTE),
627: BM_SETCHECK, BST_CHECKED, 0);
628: break;
629: default:
630: break;
631: }
632: }
633: }
normalizetextwin.cpp
635: /**
636: * 正規化オプションを取得する
637: * @param HWND hDlg ウィンドウ・ハンドラ
638: * @return string 正規化オプション
639: */
640: string getOption(HWND hDlg) {
641: string opt = "";
642: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_HAN), BM_GETCHECK, 0, 0)) {
643: opt += OPTION_ALP_HAN;
644: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_ALP_ZEN), BM_GETCHECK, 0, 0)) {
645: opt += OPTION_ALP_ZEN;
646: }
647: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_HAN), BM_GETCHECK, 0, 0)) {
648: opt += OPTION_NUM_HAN;
649: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_ZEN), BM_GETCHECK, 0, 0)) {
650: opt += OPTION_NUM_ZEN;
651: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN), BM_GETCHECK, 0, 0)) {
652: opt += OPTION_NUM_KAN;
653: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_KAN2), BM_GETCHECK, 0, 0)) {
654: opt += OPTION_NUM_KAN2;
655: }
656: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_SCALE), BM_GETCHECK, 0, 0)) {
657: opt += OPTION_NUM_SCALE;
658: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_NUM_NOSCALE), BM_GETCHECK, 0, 0)) {
659: opt += OPTION_NUM_NOSCALE;
660: }
661: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_HAN), BM_GETCHECK, 0, 0)) {
662: opt += OPTION_YAK_HAN;
663: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_YAK_ZEN), BM_GETCHECK, 0, 0)) {
664: opt += OPTION_YAK_ZEN;
665: }
666: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_HAN), BM_GETCHECK, 0, 0)) {
667: opt += OPTION_KANA_HAN;
668: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_KANA_ZEN), BM_GETCHECK, 0, 0)) {
669: opt += OPTION_KANA_ZEN;
670: }
671: if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_HAN), BM_GETCHECK, 0, 0)) {
672: opt += OPTION_SPEC_HAN;
673: } else if (SendMessage(GetDlgItem(hDlg, IDC_RADIO_SPEC_ZEN), BM_GETCHECK, 0, 0)) {
674: opt += OPTION_SPEC_ZEN;
675: }
676: if (SendMessage(GetDlgItem(hDlg, IDC_CHECK_CONTROL_DEL), BM_GETCHECK, 0, 0)) {
677: opt += OPTION_CONTROL_DEL;
678: }
679: if (SendMessage(GetDlgItem(hDlg, IDC_CHECK_DBL_QUOTE), BM_GETCHECK, 0, 0)) {
680: opt += OPTION_DBL_QUOTE;
681: }
682:
683: return opt;
684: }
解説:正規化オプション読込・保存
normalizetextwin.cpp
325: /**
326: * AppDataのパスを取得
327: * @param char* appname アプリケーション名
328: * @return string パス
329: */
330: string getMyPath(const char* appname) {
331: static TCHAR myPath[MAX_PATH] = "";
332:
333: if (strlen(myPath) == 0) {
334: if (SHGetSpecialFolderPath(NULL, myPath, CSIDL_APPDATA, 0)) {
335: TCHAR *ptmp = _tcsrchr(myPath, _T('\\'));
336: if (ptmp != NULL) {
337: ptmp = _tcsinc(ptmp);
338: *ptmp = _T('\0');
339: }
340: strcat(myPath, _T("Roaming"));
341: CreateDirectory((LPCTSTR)myPath, NULL);
342: strcat(myPath, _T("\\pahoo.org"));
343: CreateDirectory((LPCTSTR)myPath, NULL);
344: strcat(myPath, _T("\\"));
345: strcat(myPath, _T(appname));
346: CreateDirectory((LPCTSTR)myPath, NULL);
347: strcat(myPath, _T("\\"));
348: } else {
349: }
350: }
351: return (string)myPath;
352: }
normalizetextwin.cpp
366: /**
367: * オプションの読み込み
368: * @param なし
369: * @return string オプション
370: */
371: string loadOption(void) {
372: ptree pt;
373:
374: // 初期値設定
375: string option = initOption();
376:
377: // XMLファイル読み込み
378: try {
379: xml_parser::read_xml(getMyPath(APPNAME) + APPNAME + ".xml", pt);
380:
381: // XML解釈
382: try {
383: // 形式チェック
384: if (optional<string>str = pt.get_optional<string>("parameter")) {
385: } else {
386: return OPTION_INIT;
387: }
388: // パラメータ読み込み
389: for (auto it : pt.get_child("parameter")) {
390: string type= it.second.get_optional<string>("<xmlattr>.type").value();
391: if (type == "option") {
392: option =(string)it.second.data();
393: } else if (type == "wx") {
394: hParent_X = (unsigned)stoi(it.second.data());
395: } else if (type == "wy") {
396: hParent_Y = (unsigned)stoi(it.second.data());
397: }
398: }
399: // 解釈失敗したら初期値設定
400: } catch (xml_parser_error& e) {
401: return initOption();
402: }
403: // 読み込み失敗したら初期値設定
404: } catch (xml_parser_error& e) {
405: return initOption();
406: }
407:
408: // アプリケーション・ウィンドウの位置(デスクトップ範囲外なら原点移動)
409: HWND hDesktop = GetDesktopWindow();
410: WINDOWINFO windowInfo;
411: windowInfo.cbSize = sizeof(WINDOWINFO);
412: GetWindowInfo(hDesktop, &windowInfo);
413: if (hParent_X >= (unsigned)windowInfo.rcWindow.right) {
414: hParent_X = 0;
415: }
416: if (hParent_Y >= (unsigned)windowInfo.rcWindow.bottom) {
417: hParent_Y = 0;
418: }
419:
420: return option;
421: }
normalizetextwin.cpp
423: /**
424: * オプションの保存
425: * @param string option オプション
426: * @return なし
427: */
428: void saveOption(string option) {
429: #ifndef CMDAPP
430: // アプリケーション・ウィンドウの位置取得
431: WINDOWINFO windowInfo;
432: windowInfo.cbSize = sizeof(WINDOWINFO);
433: GetWindowInfo(hParent, &windowInfo);
434: hParent_X = (unsigned)windowInfo.rcWindow.left;
435: hParent_Y = (unsigned)windowInfo.rcWindow.top;
436: if (hParent_X >= (unsigned)windowInfo.rcWindow.right) {
437: hParent_X = 0;
438: }
439: if (hParent_Y >= (unsigned)windowInfo.rcWindow.bottom) {
440: hParent_Y = 0;
441: }
442: #endif
443:
444: // XMLファイルへ書き込む
445: ptree pt;
446: ptree& child1 = pt.add("parameter.param", option);
447: child1.add("<xmlattr>.type", "option");
448: ptree& child2 = pt.add("parameter.param", (string)to_string(hParent_X));
449: child2.add("<xmlattr>.type", "wx");
450: ptree& child3 = pt.add("parameter.param", (string)to_string(hParent_Y));
451: child3.add("<xmlattr>.type", "wy");
452:
453: // clog << "option=" << option << endl;
454:
455: const int indent = 4;
456: write_xml(getMyPath(APPNAME) + APPNAME + ".xml", pt, std::locale(),
457: xml_writer_make_settings<std::string>(' ', indent));
458: }
保存場所は、getMyPath 関数によって、ユーザーのAppDataの下にアプリケーションフォルダを作って、XMLファイルとして保存する。
この処理は、GUI/CUI共通だ。
解説:フロントエンド置換
pahooNormalizeText.cpp
195: /**
196: * フロントエンド置換:入力直後に文字列置換を行う
197: * @param string wsour 入力テキスト
198: * @return string 変換後文字列
199: */
200: wstring pahooNormalizeText::frontend_replace(wstring wsour) {
201: wstring tbl[2];
202:
203: //文字列置換定義ファイルを読み込む
204: ifstream ifs(FRONT_REPLACE_CSV);
205: //文字列置換定義ファイルが無い
206: if (! ifs) {
207: return wsour;
208: }
209:
210: //1行ずつ変換
211: string ss;
212: string delim = "\t";
213: list<string> list_string;
214: wstring wstr = L"";
215: while (getline(ifs, ss)) {
216: int n = 0;
217: boost::split(list_string, ss, boost::is_any_of(delim));
218: BOOST_FOREACH(string s, list_string) {
219: tbl[n] = _SW(s);
220: n++;
221: if (n > 2) break;
222: }
223: wregex re(tbl[0]);
224: wsour = regex_replace(wsour, re, tbl[1]);
225: }
226:
227: return wsour;
228: }
OCRソフト等を利用して取得したテキストについて、特定のパターンが正しく読み取れない場合がある。そこで、誤認識パターンを正しいテキストに置換するのがフロントエンド置換機能である。
GUI版、CUI版ともに、すべての正規化処理の前に、定数 FRONT_REPLACE_CSV に定義された置換定義ファイルに従って、文字列の置換を行う。
FRONT_REPLACE_CSV には複数のパターンを置換することが可能で、このCSV形式ファイルにはシフトJISで次のように記述する。
置換前文字列1 (TAB) 置換後文字列1Excelなどを使って、タブ区切りでCSV形式ファイルに保存するといいだろう。
置換前文字列2 (TAB) 置換後文字列2
‥‥
何も記述しない(空ファイル)と、フロントエンド置換機能は働かない。
CUI用メインプログラム
normalizetextwin.cpp
878: /**
879: * CUI用メインプログラム
880: * @param int argc
881: * @paramm char* argv[]
882: * @return int リターンコード
883: */
884: int main(int argc, char* argv[]) {
885: wstring wsour = L"";
886: wstring wdest = L"";
887: string sour = "";
888:
889: // 正規化オプションの初期値
890: string lopt = OPTION_INIT;
891:
892: // pahooNormalizeTextオブジェクト
893: pNT = new pahooNormalizeText();
894:
895: // MeCab動作チェック
896: #ifdef MECAB
897: if (pNT->isError()) {
898: ErrorMessage = "エラー:" + _WS(pNT->getError());
899: cerr << ErrorMessage << endl;
900: return 1;
901: }
902: #endif
903:
904: // コマンドライン・オプションの定義
905: options_description options("コマンドライン・オプション");
906: options.add_options()
907: ("option,o", value<std::string>()->default_value(lopt), "正規化オプション")
908: ("sour,s", value<std::string>(), "テキストファイルから入力")
909: ("clip,c", "クリップボードから入力")
910: ("dest,d", value<std::string>(), "テキストファイルへ出力")
911: ("paste,p", "クリップボードへ出力")
912: ("help,h", "ヘルプ")
913: ("version,v", "バージョン情報")
914: ;
915: // コマンドライン・オプションの取得
916: variables_map vm;
917: try {
918: store(parse_command_line(argc, argv, options), vm);
919: } catch(const boost::program_options::error_with_option_name& e) {
920: ErrorMessage = e.what();
921: cerr << ErrorMessage << endl;
922: return 1;
923: }
924: notify(vm);
925:
926: // 正規化オプション
927: auto opt = vm["option"].as<string>();
928:
929: // ヘルプ情報
930: if (vm.count("help")) {
931: wdest = _SW(Help);
932: // バージョン情報
933: } else if (vm.count("version")) {
934: wdest = _SW(Version);
935:
936: // 正規化実行
937: } else {
938: // 入力ファイル
939: wsour = _SW(DEF_SOUR);
940: if (vm.count("sour")) {
941: auto infile = vm["sour"].as<string>();
942: ifstream ifs(infile.c_str());
943: if (ifs.fail()) {
944: ErrorMessage = infile + " が見つかりません";
945: cerr << ErrorMessage << endl;
946: return 1;
947: }
948: string ss;
949: while (getline(ifs, ss)) {
950: sour += ss + "\r";
951: }
952: wsour = _SW(sour);
953: // クリップボードから
954: } else if (vm.count("clip")) {
955: char *ss = getClipboardData();
956: sour = ss;
957: wsour = _SW(sour);
958: // 標準入力から
959: } else {
960: cin >> sour;
961: if (sour.length() > 0) {
962: wsour = _SW(sour);
963: }
964: }
965: wdest = pNT->normalizeText(wsour, opt.c_str(), FALSE);
966: }
967:
968: // 出力ファイル
969: if (vm.count("dest")) {
970: // 改行コード置換
971: wregex re(_SW("\r"));
972: wdest = regex_replace(wdest, re, _SW("\n"));
973: auto outfile = vm["dest"].as<string>();
974: ofstream ofs(outfile.c_str());
975: ofs << _WS(wdest);
976: if (ofs.bad()) {
977: ErrorMessage = outfile + " への書き込みに失敗しました";
978: cerr << ErrorMessage << endl;
979: return 1;
980: }
981: ofs.close();
982: // クリップボードへ
983: } else if (vm.count("paste")) {
984: // 改行コード置換
985: wregex re(_SW("\r"));
986: wdest = regex_replace(wdest, re, _SW("\n"));
987: setClipboardData(_WS(wdest));
988: // 標準出力へ
989: } else {
990: // 改行コード置換
991: wregex re(_SW("\r"));
992: wdest = regex_replace(wdest, re, _SW("\n"));
993: clog << _WS(wdest);
994: }
995:
996: // オブジェクト解放
997: delete pNT;
998:
999: return 0;
1000: }
GUI版の WinMain 関数はマルチスレッド対応で、すべてのスレッドが終わる前にコマンドラインに戻ってきてしまう。また、標準入出力のパイプ処理への対応も面倒であるため、CUI版は実行ファイルを分けることにした。

コマンドラインオプションの解釈は、Boost C++ライブラリ の options を利用した。
参考サイト
- PHPで日本語テキストを正規化:ぱふぅ家のホームページ
- MeCab
- PHPで MeCabのユーザー辞書を作成する:ぱふぅ家のホームページ
- C++ でテキスト中の和暦・西暦年号を統一する:ぱふぅ家のホームページ
- WiX によるWindowsインストーラー作成:ぱふぅ家のホームページ
- C++ 開発環境の準備:ぱふぅ家のホームページ
また、ソースを共通化してコマンドライン版アプリケーションを作り、バッチや他のプログラムから流し込んだテキストを正規化することができるようにする。
「PHPで日本語テキストを正規化」で作ったPHPプログラムをC++に移植したものである。
(2025年3月29日)使用ライブラリ更新,辞書更新
(2024年12月15日)使用ライブラリ更新,辞書更新
(2024年8月24日)使用ライブラリ更新,辞書更新
(2024年4月7日)使用ライブラリ更新,辞書更新