use*_*833 5 apache apache-tika
Apache Tika能够提取中文,日文等外语吗?
我有以下代码:
Detector detector = new DefaultDetector();
Parser parser = new AutoDetectParser(detector);
InputStream stream = new ByteArrayInputStream(bytes);
OutputStream outputstream = new ByteArrayOutputStream();
ContentHandler textHandler = new BodyContentHandler(outputstream);
Metadata metadata = new Metadata();
// Set<String> langs = LanguageIdentifier.getSupportedLanguages();
// metadata.set(Metadata.CONTENT_LANGUAGE, lang);
// metadata.set(Metadata.FORMAT, hint);
ParseContext context = new ParseContext();
try {
parser.parse(stream, textHandler, metadata, context);
String extractedText = outputstream.toString();
return extractedText;
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (TikaException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
如果输入是包含中文字符的doc文件,则每个中文字符将被提取为"?".
非常感谢!
我还没有看到任何地方写到 Apache Tika不支持中文和日语等外语。但是,当查看以下Apache Tika 源文件时,我找不到这两种语言。
但是,您仍然可以按照五分钟用户指南中讨论的相同方式尝试实施,以使用您的中文文档文件进行测试
https://tika.apache.org/1.4/parser_guide.html