OpenNLP: documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true) ParserConfigurationE

2024-01-02

所以我尝试在 Android Studio 中使用 OpenNLP,但我的应用程序总是抛出ParserConfigurationException在 OpenNLP 在其 XmlUtil 类中使用的代码体内,我无法修改该代码:

public static DocumentBuilder createDocumentBuilder() {
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        return documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException var1) {
        throw new IllegalStateException(var1);
    }
}

documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);导致应用程序抛出ParserConfigurationException.

已经被困在这个问题上大约一周了,但没有运气,有什么建议可以解决这个错误吗?


我在使用 OpenNLP 1.9.1 版本时遇到了同样的问题,我通过使用解决了这个问题版本1.6.0反而。这是我设法开始工作的最新版本。

dependencies {
  implementation 'org.apache.opennlp:opennlp-tools:1.6.0'
}

降级是无缝的,因为模型相同并且公共 API 很大程度上相似(至少对于我的使用而言)。


完整故事:我正在制作一个原型 https://github.com/dadouf/OpenNLP-Android-Example与 OpenNLP 一起使用TokenizerME和两个NameFinderME——针对人和地点。这些是我尝试过(但失败了)的所有 OpenNLP 版本:

  • 1.9.1 和 1.9.0:失败ParserConfigurationExceptionOP中描述
  • 1.8.0 和 1.7.0:都崩溃了OutOfMemoryError当尝试加载 NameFinderME 时
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenNLP: documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true) ParserConfigurationE 的相关文章

随机推荐