現在、ICUディクショナリベースのブレークイテレータに新たに追加していくつかのテストを行っています。 テキスト文書で単語の区切りをテストできるコードがありますが、テキスト文書が大きすぎるとエラーになります:bash:./a.out:引数リストが長すぎますヘルプ "コードリストを長すぎます"エラーを修正するエラー
わかりませんコードを編集して引数リストを分割して長すぎると、どのサイズのファイルでもコードを実行することができます。元のコード作成者はかなり忙しいですが、助けてくれる人がいますか?
大切なファイルにはエラーが表示されます(検査するものは必要ありません - 結果が必要です)。
ソーステキストファイルを1行ずつ読み込み、結果を1行ずつ別のテキストファイルに書き出すようにコードを修正することができれば(完了したらすべての行で終わる)、それは完璧です。次のように
コードは次のとおりです。
/*
Written by George Rhoten to test how word segmentation works.
Code inspired by the break ICU sample.
Here is an example to run this code under Cygwin.
PATH=$PATH:icu-test/source/lib ./a.exe "`cat input.txt`" > output.txt
Encode input.txt as UTF-8.
The output text is UTF-8.
*/
#include <stdio.h>
#include <unicode/brkiter.h>
#include <unicode/ucnv.h>
#define ZW_SPACE "\xE2\x80\x8B"
void printUnicodeString(const UnicodeString &s) {
int32_t len = s.length() * U8_MAX_LENGTH + 1;
char *charBuf = new char[len];
len = s.extract(0, s.length(), charBuf, len, NULL);
charBuf[len] = 0;
printf("%s", charBuf);
delete charBuf;
}
/* Creating and using text boundaries */
int main(int argc, char **argv)
{
ucnv_setDefaultName("UTF-8");
UnicodeString stringToExamine("Aaa bbb ccc. Ddd eee fff.");
printf("Examining: ");
if (argc > 1) {
// Override the default charset.
stringToExamine = UnicodeString(argv[1]);
if (stringToExamine.charAt(0) == 0xFEFF) {
// Remove the BOM
stringToExamine = UnicodeString(stringToExamine, 1);
}
}
printUnicodeString(stringToExamine);
puts("");
//print each sentence in forward and reverse order
UErrorCode status = U_ZERO_ERROR;
BreakIterator* boundary = BreakIterator::createWordInstance(NULL, status);
if (U_FAILURE(status)) {
printf("Failed to create sentence break iterator. status = %s",
u_errorName(status));
exit(1);
}
printf("Result: ");
//print each word in order
boundary->setText(stringToExamine);
int32_t start = boundary->first();
int32_t end = boundary->next();
while (end != BreakIterator::DONE) {
if (start != 0) {
printf(ZW_SPACE);
}
printUnicodeString(UnicodeString(stringToExamine, start, end-start));
start = end;
end = boundary->next();
}
delete boundary;
return 0;
}
本当にありがとうございました! -Nathan
ああ、そうです。いいえ、シェルが単語の区切りをどのように処理するのかを知ることではありません。結果ファイルの場合だけです。行ごとにテキストを読み取るコードを変更するのに役立つでしょうか? – Nathan
誤って私のコメントを削除しました:-) C++のファイルを読むには、http://www.cplusplus.com/doc/tutorial/files/を参照してコードを投稿してください。 –
私はそれがどこに行ったのだろうかと思っていた:)ラインで行を読むために変更を必要とするコードが問題にある。私は個人的にC++を知っていません。元のコードはICUの提出を手伝ってくれた誰かによって作成されましたが、彼はかなり忙しいので、私は別のところで見ると思いました。ご協力いただきありがとうございます! – Nathan