HermiT reasoner 为数据类型抛出“UnsupportedDatatypeException”

HermiT reasoner thows “UnsupportedDatatypeException” for datatype

我想从 ontology 文件 dbpedia_2016-10.owl 中提取 DBPedia ontology 类 hiearchy(从 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 正在抱怨它无法识别的数据类型,但是如何在不修改 ontology 的情况下解决这个问题?

我不确定它是否有帮助,但这些是我项目的依赖项:

        <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>

提前感谢您的指导!

为了对此进行测试,我将 DBPedia ontology 加载到 Protege 5.5 中并使用 HermiT 1.4.3.517 对其进行推理。这没有问题。因此,我认为您应该查看 OWL API 和 HermiT maven 依赖项。

<dependency>
    <groupId>net.sourceforge.owlapi</groupId>
    <artifactId>owlapi-distribution</artifactId>
    <version>5.1.12</version>
</dependency>   
<dependency>
    <groupId>net.sourceforge.owlapi</groupId>
    <artifactId>org.semanticweb.hermit</artifactId>
    <version>1.4.3.517</version>
</dependency>

更新

您似乎也错误地启动了推理器。这里有一些使用上述 Maven 依赖项的工作代码。

import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.io.File;

public class LoadDBPedia {

    private static Logger logger = LoggerFactory.getLogger(LoadDBPedia.class);
    // Why This Failure marker
    private static final Marker WTF_MARKER = MarkerFactory.getMarker("WTF");

    private static String ONTOLOGY_FILE = "/path_to_ontology/dbpedia_2016-10.owl";

    public static void main(String[] args) {
        try {
            File file = new File(ONTOLOGY_FILE);
            if (file.exists()) {
                OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
                OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);

                OWLReasonerFactory reasonerFactory = new ReasonerFactory();
                OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
                if (!reasoner.isConsistent()) {
                    logger.debug("Ontology is inconsistent");
                    throw new Exception("Ontology is inconsistent");
                } else {
                    logger.debug("Ontology is consistent");
                }
              }

            } catch (Throwable t) {
            logger.error(WTF_MARKER, t.getMessage(), t);
        }
    }
 }

您的代码可能有什么问题?

(1) 这一行 Reasoner reasoner=new Reasoner(ontology); 是可疑的,因为 (a) 不清楚你从哪里得到 Reasoner class 和 (b) 似乎不是来自 HermiT因为 HermiT 中 Reasoner 的构造函数具有不同的签名。

(2) 您对 owlexplanation 而不是 owlapi-distribution 的依赖是可疑的。