首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HermiT推理者为数据类型编写了“UnsupportedDatatypeException”

HermiT推理者为数据类型编写了“UnsupportedDatatypeException”
EN

Stack Overflow用户
提问于 2019-12-09 16:50:03
回答 1查看 176关注 0票数 0

我想从本体文件dbpedia_2016-10.owl (从https://wiki.dbpedia.org/downloads-2016-10下载)中删除file本体类,我通过引用其他代码构建了这个方法,因为我是这个领域的初学者:

代码语言:javascript
运行
复制
        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推理器时,我会得到以下异常:

代码语言:javascript
运行
复制
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在抱怨它不认识的数据类型,但是如何在不修改本体的情况下解决这个问题呢?

我不确定这是否有帮助,但这是我的项目的重点:

代码语言:javascript
运行
复制
        <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>

谢谢您的指导!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-09 17:35:18

为了测试这一点,我将DBPedia本体加载到Protege5.5中,并使用HermiT 1.4.3.517对其进行推理。这是没有问题的。因此,我认为您应该查看OWL和HermiT maven依赖项。

代码语言:javascript
运行
复制
<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依赖项的一些工作代码。

代码语言:javascript
运行
复制
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这一事实是可疑的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59253289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档