4
votes

in the current documentation example at the link: https://github.com/owlcs/owlapi/blob/version5/contract/src/test/java/org/semanticweb/owlapi/examples/Examples.java There is no example of how to load an ontology from a local file. There is only a way to load it from a string.

In the past when i used owl-api version 3 the following code worked perfectly:

    OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
    File file = new File (path);
    OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create(file));

however, in this version, the last line of the previous code:

manager.loadOntologyFromOntologyDocument(IRI.create(file));

returns this error:

    Exception in thread "main" java.lang.NoSuchMethodError: 
    org.semanticweb.owlapi.util.SAXParsers.initParserWithOWLAPIStandards(Lorg/xml/sax/ext/DeclHandler;)Ljavax/xml/parsers/SAXParser; 
        at 
org.semanticweb.owlapi.rdf.rdfxml.parser.RDFParser.parse(RDFParser.java:148)
    at org.semanticweb.owlapi.rdf.rdfxml.parser.RDFXMLParser.parse(RDFXMLParser.java:62)
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:173)
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:954)
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:918)
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:859)
    at glass.main.ontology_Test_main2.readOntology(ontology_Test_main2.java:49)
    at glass.main.ontology_Test_main2.main(ontology_Test_main2.java:38)

Kindly note the attachment, a small test java project, link:

dropbox.com/s/3787a3gsk2bwc26/test.tar.gz?dl=0

Kindly what am i doing wrong, i m sure that this code

Kindly would you please provide the correct way to do it, and add it to the tutorial example in the link https://github.com/owlcs/owlapi/blob/version5/contract/src/test/java/org/semanticweb/owlapi/examples/Examples.java

Thanks very much for your time. Sincere regards

2
The root of your problem is conflicting versions of the library. Check your classpath - very likely there will be more than one OWLAPI version mentioned in it.Ignazio

2 Answers

6
votes

You are very near from the solution:

final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("/home/galigator/myLocalDir/aura.owl"));

Just use new File instead of IRI.create

1
votes

The reason of the problem was:

The previous versions that i was using: I was using Hermit version 1.3.8.500 and OWL-API previous version 5.0.5 got modified it seems.

Solution: use the newer versions Hermit 1.3.8.510 and OWL-API 5.1.0.

I posted this answer in case someone else is using the previous version and got affected. Sincere regards.