5

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

user3781976
  • 119
  • 1
  • 11
  • 1
    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 Apr 01 '17 at 21:08

2 Answers2

7

You are very near to 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

Galigator
  • 8,957
  • 2
  • 25
  • 39
  • IRI.create((new File("/home/galigator/myLocalDir/aura.owl")).toURI()) can also be use. – Galigator Apr 01 '17 at 13:06
  • Greeting Galigator, thanks for your answer. But `final OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("/home/../../aura.owl"));` This is giving me the same error: java.lang.NoSuchMethodError: org.semanticweb.owlapi.util.SAXParsers.initParserWithOWLAPIStandards(Lorg/xml/sax/ext/DeclHandler;)Ljavax/xml/parsers/SAXParser; – user3781976 Apr 01 '17 at 13:15
  • Do you use 'maven' for your build ? – Galigator Apr 01 '17 at 13:27
  • Yes ofcourse, i have attached a small test java project, link: [link]https://www.dropbox.com/s/3787a3gsk2bwc26/test.tar.gz?dl=0 Kindly what am i doing wrong, i m sure that this code was working in the past. The project in the link is a simple test project which has an ontology for testing – user3781976 Apr 01 '17 at 13:47
  • I think i found out why, very strange :( i was using: Hermit previous maven version 1.3.8.500: net.sourceforge.owlapi org.semanticweb.hermit 1.3.8.500 and OWL-API previous version 5.0.5: net.sourceforge.owlapi owlapi-api 5.0.5 it was working perfectly, now it does not, so i switched to the newer version of Hermit 1.3.8.510 and the newer version of OWL-API 5.1.0 and the code works again, i hope this will not affect my whole project since it was built using the previously mentioned older versions. – user3781976 Apr 01 '17 at 14:02
  • Thankfully nothing else has been affected. Thanks very much Galigator. I will write that in a separate answer, in case someone else is using the previous version. – user3781976 Apr 01 '17 at 14:32
  • 1
    When accessing a local file, always use new File rather than IRI. The reason is that an IRIDocumentSource, used for the IRI access, is slower than a file based document source. – Ignazio Apr 01 '17 at 21:12
1

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.

user3781976
  • 119
  • 1
  • 11
  • More in general, such runtime errors point at changes in classpath between compile and runtime - often as a consequence of conflicting libraries. – Ignazio Apr 01 '17 at 21:09