簡體   English   中英

HermiT 推理器為數據類型顯示“UnsupportedDatatypeException”

[英]HermiT reasoner thows “UnsupportedDatatypeException” for datatype

我想從本體文件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>

在此先感謝您的指導!

為了測試這一點,我將 DBPedia 本體加載到 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類,以及 (b) 似乎不是來自 HermiT,因為 HermiT 中Reasoner的構造函數具有不同的簽名。

(2) 您依賴於owlexplanation而不是owlapi-distribution的事實是可疑的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM