Apache Tika 无法检测短句中的语言.为什么?



我试图检测短语上的语言,并惊讶于检测结果是错误的。

LanguageDetector detector = new OptimaizeLangDetector();
try {
detector.loadModels();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
throw new ExceptionInInitializerError(e);
}
LanguageResult languageResult = detector.detect("Hello, my friend!")

语言结果包含具有"中等"概率的挪威语。为什么?我认为它必须是英语。较长的短语似乎被正确检测到。这是否意味着Apache Tika不应该用于短文本?

这在短文本中不起作用。正如在文献中所说:

使用 https://github.com/optimaize/language-detector

从 https://tika.apache.org/1.13/api/org/apache/tika/langdetect/OptimaizeLangDetector.html

去审查那个github并检查他们在短文本方面遇到的一些挑战。

当要分析的输入文本是 短,或不干净。例如推文。

来自他们的 https://github.com/optimaize/language-detector 挑战部门

我可以重现该问题。 它可能不会直接回答问题,但被认为是一种解决方法......

似乎如果您知道可以预期哪些语言,您可以通过loadModels(models)方法将它们传递给检测器。此方法有助于正确检测英语:

try {
Set<String> models=new HashSet<>();
models.add("en");
models.add("ru");
models.add("de");
LanguageDetector detector = new OptimaizeLangDetector()
//            .setShortText(true)
.loadModels(models);
//            .loadModels();
LanguageResult enResult = detector.detect("Hello, my friend!");
//            LanguageResult ruResult = detector.detect("Привет, мой друг!");
//            LanguageResult deResult = detector.detect("Hallo, mein Freund!");
System.out.println(enResult.getLanguage());
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}

最新更新