我想从一个本体文件中提取 DBPedia 本体类层次结构dbpedia_2016-10.owl
(从https://wiki.dbpedia.org/downloads-2016-10下载,我通过参考其他一些代码来构建这个方法,因为我是这个领域的初学者:
public static void importOntology(String ontologyFile) throws Exception {
File file = new File(ontologyFile);
if (file.exists()) {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);
Reasoner reasoner=new Reasoner(ontology);
if (!reasoner.isConsistent()) {
throw new Exception("Ontology is inconsistent");
}
for (OWLClass c :ontology.getClassesInSignature(true)) {
String classString = c.toString();
System.out.println(classString);
if (classString.contains("#")) {
classString = classString.substring(classString.indexOf("#")+1,classString.lastIndexOf(">"));
}
Set<OWLClassExpression> superclasses = c.getSuperClasses(ontology);
if (superclasses.isEmpty()) {
System.out.println(classString + " is owl#Thing.");
} else {
for (OWLClassExpression superc:superclasses) {
System.out.println(superc + " is a parent.");
}
}
}
}
}
当我声明并实例化 HermiT 推理器时,我得到了这个异常:
org.semanticweb.HermiT.datatypes.UnsupportedDatatypeException: HermiT supports all and only the datatypes of the OWL 2 datatype map, see
http://www.w3.org/TR/owl2-syntax/#Datatype_Maps.
The datatype 'http://dbpedia.org/datatype/hour' is not part of the OWL 2 datatype map and
no custom datatype definition is given;
therefore, HermiT cannot handle this datatype.
现在,我不明白 HermiT 正在抱怨它无法识别的数据类型,但是如何在不修改本体的情况下解决这个问题呢?
我不确定它是否会有所帮助,但这些是我项目的依赖:
<dependencies>
<dependency>
<groupId>com.hermit-reasoner</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.3.8.4</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlexplanation</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
提前感谢您的任何指导!