我正在使用 OWL API 来读取本体文件。我的代码如下:
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI iri = IRI.create(new File("src\\main\\webapp\\resources\\inputfile\\20171218 ontology test v0.6.owl"));
System.out.println(iri);
//I am getting error in below line
OWLOntology moduleOWL = manager.loadOntologyFromOntologyDocument(iri);
我收到以下异常。我已经尝试了各种方法来解决问题,但没有成功。
file:/D:/Company/Workspace/My%20Data/MyDATA/src/main/webapp/resources/inputfile/20171218%20ontology%20test%20v0.6.owl
Exception in thread "main" java.lang.NoSuchFieldError: UTF_32BE
at org.semanticweb.owlapi.io.DocumentSources.wrap(DocumentSources.java:248)
at org.semanticweb.owlapi.io.DocumentSources.getInputStreamFromContentEncoding(DocumentSources.java:284)
at org.semanticweb.owlapi.io.DocumentSources.connectWithFiveRetries(DocumentSources.java:227)
at org.semanticweb.owlapi.io.DocumentSources.getInputStream(DocumentSources.java:150)
at org.semanticweb.owlapi.io.DocumentSources.wrapInput(DocumentSources.java:115)
at org.semanticweb.owlapi.io.DocumentSources.wrapInputAsReader(DocumentSources.java:79)
at org.semanticweb.owlapi.io.DocumentSources.wrapInputAsReader(DocumentSources.java:96)
at org.semanticweb.owlapi.io.AbstractOWLParser.getInputSource(AbstractOWLParser.java:38)
at org.semanticweb.owlapi.rdf.rdfxml.parser.RDFXMLParser.parse(RDFXMLParser.java:59)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:188)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:1072)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:1033)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:973)
at com.ifour.mydata.test.ConvertXMLtoRDF.getOwlProperty(ConvertXMLtoRDF.java:402)
at com.ifour.mydata.test.ConvertXMLtoRDF.main(ConvertXMLtoRDF.java:114)
最佳答案
出现此问题的原因是您的类路径中的 Apache Commons IO 版本与 Owl API 不兼容。
我的计算方法如下...
我读到了异常。它提到 UTF_32BE
不是一个字段,并说明问题发生在哪个类和方法中,所以我挖出了 the source code对于 Owl API 的 DocumentSources.wrap()
方法:
public static InputStream wrap(InputStream delegate) {
checkNotNull(delegate, "delegate cannot be null");
return new BOMInputStream(delegate, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE,
ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
}
它引用了 ByteOrderMark
上的各种 UTF_*
字段,并非所有字段都失败。我发现 ByteOrderMark 是从 Apache Commons IO 导入的:
import org.apache.commons.io.ByteOrderMark;
如果你看the source对于ByteOrderMark
,它的字段定义如下:
/**
* UTF-32BE BOM (Big-Endian)
* @since 2.2
*/
public static final ByteOrderMark UTF_32BE = new ByteOrderMark("UTF-32BE", 0x00, 0x00, 0xFE, 0xFF);
这表明您的类路径上有早于 2.2 版本的 Apache Commons IO。
关于java - 如何解决此错误 : java. lang.NoSuchFieldError : UTF_32BE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48299276/