简体   繁体   中英

HermiT reasoner thows “UnsupportedDatatypeException” for datatype

I want to exctract DBPedia ontology classes hiearchy from an ontology file dbpedia_2016-10.owl (downloaded from https://wiki.dbpedia.org/downloads-2016-10 , and I built this method by refering to some other codes as I am beginner in this area:

        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.");
                        }
                    }
                }
            }
        
    }

When I declare and instanciate the HermiT reasoner, I get this exception:

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.

Now, I undestand that HermiT is complaining about a datatype that it does not recognize, but how to solve this without modifyng the ontology?

I am not sure if it would help, but these are the depencies of my project:

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

Thanks in advance for any guidance!

To test this, I loaded the DBPedia ontology into Protege 5.5 and used HermiT 1.4.3.517 to reason over it. This works without problem. I therefore think you should look at your OWL API and HermiT maven dependencies.

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

Update

You also seem to be starting the reasoner incorrectly. Here some working code using the Maven dependencies above.

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);
        }
    }
 }

What could be wrong with your code?

(1) This line Reasoner reasoner=new Reasoner(ontology); is suspicious because (a) it not clear where you got the Reasoner class from and (b) does not seem to come from HermiT as the constructors for Reasoner in HermiT have different signatures.

(2) The fact that you have a dependency on owlexplanation rather than owlapi-distribution is suspicious.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM