0

I/P 文件 : doc,docx with en-dash,em-dash

我已经通过使用 Apache Tika(元数据属性)和 Aspose wordtojava(library) 实现了字数统计功能,但它们没有给我准确的字数统计结果。

en-dash 和 em-dash 字数与 MS-Office ex 不同。2-3 4-5 结果:MS-office 给出上述示例的字数 4 APache - Tika & Aspose 库给出字数 2

如何计算与 MS-Office 相同的正确字数?

任何帮助都是非常可观的。

需要快速响应。

谢谢

4

3 回答 3

2

将文档中的所有字符串提取到一个字符串中。使用此正则表达式“[\n\t\r\f \p{Pd}]”拆分它们,并计算拆分后的字符串数组的长度。

    String allWords = "2—3 4–5";
    String[] split = allWords.split("[\n\t\r\f \\p{Pd}]");
    System.out.println(split.length);

它打印 4。希望这有帮助。

于 2015-08-27T02:18:43.137 回答
0

'BuiltInDocumentProperties.Words' 属性表示 Word 文档中字数的估计值。当您调用 'Document.updateWordCount' 方法时,Aspose.Words 会更新此属性。请看以下示例代码:

Document doc = new Document(getMyDir() + "in.docx");

// Update the word, character and paragraph count of the document.
doc.updateWordCount();

// Display the updated document properties.
System.out.println("Characters: " + doc.getBuiltInDocumentProperties().getCharacters());
System.out.println("Words: " + doc.getBuiltInDocumentProperties().getWords());
System.out.println("Paragraphs: " + doc.getBuiltInDocumentProperties().getParagraphs());

希望这可以帮助。

此外,请确保您使用的是最新版本的 Aspose.Words for Java,即 15.7.0。

我与 Aspose 一起担任开发人员宣传员。

于 2015-08-27T05:49:58.580 回答
0

你可能还想看看 https://github.com/maresja1/Word-Counter/blob/master/README.md 它使用 Apache tika 并且可以处理 doc、docx、rtf、pdf 等。我看了一下代码它实际上是一个删除重复空格的字符计数器。但它可以很容易地更改为字数计数器。

于 2019-07-29T18:11:31.953 回答