我目前正在做一些测试,并在ICU基于字典的中断迭代器中添加了一个新的测试。 我有代码,允许我在文本文档上测试分词,但是当文本文档太大时,会给出错误:bash:./a.out:参数列表太长帮助编辑代码修复“参数列表太长”错误
我不确定如何编辑代码以在参数列表过长时分解参数列表,以便可以通过代码运行任何大小的文件。原来的代码作者很忙,有人愿意帮忙吗?
我试图消除的正在研究什么,看是否能帮助印刷,但是我还是对大文件的错误(打印什么是被检查是没有必要的 - 我只是需要的结果)。
如果代码可以被修改,以逐行读取源文本文件行,并通过线将结果导出行另一个文本文件(结束了,当它完成了所有行),这将是完美的。
的代码如下:
/*
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
嗯,是的,这是有帮助的。不,它不是看shell如何处理断词 - 它只是为了生成的文件 - 你能帮助改变代码逐行阅读文本吗? – Nathan
我不小心删除了我的评论:-)要从C++中读取文件,请参阅http://www.cplusplus.com/doc/tutorial/files/发布您的代码,我很乐意帮助您... –
我想知道它到底在哪里:)需要修改以逐行阅读的代码在问题中。我个人不了解C++ - 原始代码是由某人帮助我提交ICU提交的,但他很忙,所以我想我会在其他地方看看。谢谢你的帮助! – Nathan