[英]Loading owl file with Jena
I load several OWL files (RDF/XML serialization) with Jena as OntModel
.我使用 Jena 作为OntModel
加载了几个 OWL 文件(RDF/XML 序列化)。 For some files I get an error when reading them with ontoModel.read()
:对于某些文件,我在使用ontoModel.read()
读取它们时出现错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpMessage
. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpMessage
。
I have org.apache.httpcore-sources.jar
in the classpath.我在类路径中有org.apache.httpcore-sources.jar
。
The file which currently poses problem is: ontologydesignpatterns.org/cp/owl/timeindexedpersonrole.owl当前存在问题的文件是: ontologydesignpatterns.org/cp/owl/timeindexedpersonrole.owl
I saved it with Protege as RDF/XML, trying with both extensions .owl
and .rdf
.我用 Protege 将它保存为 RDF/XML,同时尝试使用扩展.owl
和.rdf
。
The code:编码:
public static OntModel getOntologyModel(String ontoFile)
{
OntModel ontoModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
try
{
InputStream in = FileManager.get().open(ontoFile);
try
{
ontoModel.read(in, null);
}
catch (Exception e)
{
e.printStackTrace();
}
LOGGER.info("Ontology " + ontoFile + " loaded.");
}
catch (JenaException je)
{
System.err.println("ERROR" + je.getMessage());
je.printStackTrace();
System.exit(0);
}
return ontoModel;
}
Many thanks for your help.非常感谢您的帮助。
If you are using the binary download, put all the jars in the lib/ directory on the classpath.如果您使用的是二进制下载,请将所有 jar 放在类路径上的 lib/ 目录中。 org.apache.httpcore-sources.jar isn't the right jar.. You seem to be missing at least httpclient-4.2.6.jar and httpcore-4.2.5.jar. org.apache.httpcore-sources.jar 不是正确的 jar .. 您似乎至少缺少 httpclient-4.2.6.jar 和 httpcore-4.2.5.jar。
If you use maven, use the artifact:如果您使用 maven,请使用工件:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>X.Y.Z</version>
</dependency>
to get the same set, but managed by maven, or whatever builer you are using.获得相同的集合,但由 maven 或您正在使用的任何构建器管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.