owlcs / owlapi

OWL API main repository
822 stars 315 forks source link

NoSuchMethodError: Exception when using AddAxioms() #1009

Closed marwa811 closed 2 years ago

marwa811 commented 3 years ago

Hi, I am using OWL API 4.5 and I need to add axioms to an ontology and save the changes in a file.. My Code is: Set allAxioms=new HashSet(); //get direct subclass for (OWLClass subclass : targetreasoner.getSubClasses(owlclass, true).getFlattened()) { OWLSubClassOfAxiom axiom=factory.getOWLSubClassOfAxiom(subclass, sourceOwlclass); allAxioms.add(axiom);
} manager.addAxioms(sourceOntology, allAxioms); //manager.applyChange(manager.addAxioms(sourceOntology, allAxioms)); manager.saveOntology(sourceOntology);

And I got Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyManager.addAxioms(Lorg/semanticweb/owlapi/model/OWLOntology;Ljava/util/Set;)Lorg/semanticweb/owlapi/model/parameters/ChangeApplied;

In my POM file I add the OWL API 4.5 only as I read that could be caused if I added more than 1 OWL API version. What coud be the reason for this exception?

ignazio1977 commented 3 years ago

You may have added only one OWLAPI version explicitly but some other dependencies might have pulled in other versions. You can check all the libraries actually on the classpath in multiple ways - Eclipse can show you the full list, in one of the tabs when you open a pom file. There are other options but I've not used them and wouldn't know how to explain them.

If all else fails, print out the value of the system property java.class.path as first instruction in your code and post here the result, that usually has clues.

ignazio1977 commented 3 years ago

If you add your pom file here, that can also help.

marwa811 commented 3 years ago

Sorry for the late reply: this is the pom file

junit junit 3.8.1 test edu.stanford.protege bioportal-services-lib 1.0.1 com.fasterxml.jackson.core jackson-databind 2.12.3 log4j log4j 1.2.17 net.sourceforge.owlapi owlapi-distribution 4.5.18

marwa811 commented 3 years ago

I tried to follow steps on how to edit the classpath variables for an eclipse project. I opened it from the Window tab (I cant add a screenshot here) but nothing related to OWL API appeared.

ignazio1977 commented 3 years ago

The problem is in a dependency of the bioportal-services-lib:

net.sourceforge.owlapi owlapi-distribution 3.4.3

This needs to be excluded from transitive dependencies as it will clash with the OWLAPI version you want to use.

<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>bioportal-services-lib</artifactId>
<version>1.0.1</version>
<exclusions>
    <exclusion>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
    </exclusion>
</exclusions>
</dependency>

Hope this helps, I don't have the means to run a build to check at the moment.

marwa811 commented 3 years ago

Unfortunately, I added the exclusions tags to the pom file but still got the same exception. can you help me with other solutions to try it!! I have to solve this issue because it is very important in my project as I have to update an ontology with classes and properties.

marwa811 commented 3 years ago

Also, Maybe I used other versions of OWLAPI in previous projects (not this one) can this be a reason for such an exception?

ignazio1977 commented 3 years ago

Using other versions in other projects shouldn't affect you here, all that's relevant should be the dependencies in the pom file. Eclipse will show the full hierarchy in the dependency hierarchy tab when you open a pom.xml file in it.

re printing the classpath variable, I was referring to Java code: add this line as first line in your code and report here the output.

System.out.println(System.getProperties("java.class.path"));

this will print out the list of all jars actually in the classpath of your application, and will help diagnose which jars are causing the issue, it's a lot simpler to figure out what dependency is introducing the problem then.

marwa811 commented 3 years ago

Ok I did and this is the output:

C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\target\classes;C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\AgreementMakerLight.jar;C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\mysql-connector-java-5.1.44-bin.jar;C:\Users\marwa.m2\repository\edu\stanford\protege\bioportal-services-lib\1.0.1\bioportal-services-lib-1.0.1.jar;C:\Users\marwa.m2\repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;C:\Users\marwa.m2\repository\com\thoughtworks\xstream\xstream\1.4.4\xstream-1.4.4.jar;C:\Users\marwa.m2\repository\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;C:\Users\marwa.m2\repository\org\testng\testng\6.8\testng-6.8.jar;C:\Users\marwa.m2\repository\org\beanshell\bsh\2.0b4\bsh-2.0b4.jar;C:\Users\marwa.m2\repository\com\beust\jcommander\1.27\jcommander-1.27.jar;C:\Users\marwa.m2\repository\org\yaml\snakeyaml\1.6\snakeyaml-1.6.jar;C:\Users\marwa.m2\repository\com\fasterxml\jackson\core\jackson-core\2.12.3\jackson-core-2.12.3.jar;C:\Users\marwa.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.12.3\jackson-databind-2.12.3.jar;C:\Users\marwa.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.12.3\jackson-annotations-2.12.3.jar;C:\Users\marwa.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-distribution\4.5.18\owlapi-distribution-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-compatibility\4.5.18\owlapi-compatibility-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-apibinding\4.5.18\owlapi-apibinding-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-api\4.5.18\owlapi-api-4.5.18.jar;C:\Users\marwa.m2\repository\com\github\ben-manes\caffeine\caffeine\2.5.6\caffeine-2.5.6.jar;C:\Users\marwa.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-impl\4.5.18\owlapi-impl-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-parsers\4.5.18\owlapi-parsers-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-oboformat\4.5.18\owlapi-oboformat-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-tools\4.5.18\owlapi-tools-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-fixers\4.5.18\owlapi-fixers-4.5.18.jar;C:\Users\marwa.m2\repository\net\sourceforge\owlapi\owlapi-rio\4.5.18\owlapi-rio-4.5.18.jar;C:\Users\marwa.m2\repository\org\tukaani\xz\1.6\xz-1.6.jar;C:\Users\marwa.m2\repository\org\slf4j\slf4j-api\1.7.22\slf4j-api-1.7.22.jar;C:\Users\marwa.m2\repository\org\slf4j\jcl-over-slf4j\1.7.22\jcl-over-slf4j-1.7.22.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-model\2.4.2\rdf4j-model-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-api\2.4.2\rdf4j-rio-api-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-languages\2.4.2\rdf4j-rio-languages-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-datatypes\2.4.2\rdf4j-rio-datatypes-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-binary\2.4.2\rdf4j-rio-binary-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-n3\2.4.2\rdf4j-rio-n3-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-nquads\2.4.2\rdf4j-rio-nquads-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-ntriples\2.4.2\rdf4j-rio-ntriples-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-rdfjson\2.4.2\rdf4j-rio-rdfjson-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-jsonld\2.4.2\rdf4j-rio-jsonld-2.4.2.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpclient\4.5.5\httpclient-4.5.5.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpcore\4.4.9\httpcore-4.4.9.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpclient-cache\4.5.5\httpclient-cache-4.5.5.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-rdfxml\2.4.2\rdf4j-rio-rdfxml-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-trix\2.4.2\rdf4j-rio-trix-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-turtle\2.4.2\rdf4j-rio-turtle-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-rio-trig\2.4.2\rdf4j-rio-trig-2.4.2.jar;C:\Users\marwa.m2\repository\org\eclipse\rdf4j\rdf4j-util\2.4.2\rdf4j-util-2.4.2.jar;C:\Users\marwa.m2\repository\com\github\jsonld-java\jsonld-java\0.12.0\jsonld-java-0.12.0.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpclient-osgi\4.5.5\httpclient-osgi-4.5.5.jar;C:\Users\marwa.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpmime\4.5.5\httpmime-4.5.5.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\fluent-hc\4.5.5\fluent-hc-4.5.5.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpcore-osgi\4.4.9\httpcore-osgi-4.4.9.jar;C:\Users\marwa.m2\repository\org\apache\httpcomponents\httpcore-nio\4.4.9\httpcore-nio-4.4.9.jar;C:\Users\marwa.m2\repository\com\github\vsonnier\hppcrt\0.7.5\hppcrt-0.7.5.jar;C:\Users\marwa.m2\repository\com\google\guava\guava\18.0\guava-18.0.jar;C:\Users\marwa.m2\repository\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;C:\Users\marwa.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\Properties

ignazio1977 commented 3 years ago

There's no explicit conflict between the jars listed, however there are three places that I cannot check:

C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\AgreementMakerLight.jar

I cannot inspect the contents of this jar. Can you let me know what goes into it? (you can open a jar file with any application that supports zip files and check the list of files it contains; does it contain any of org.semanticweb.owlapi or uk.ac.manchester folders?)

C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\target\classes C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\Properties

I don't believe the target/classes folder has anything related to this problem in it, but best to list its contents as well. Same for the Properties folder, I wouldn't expect it to contain jars or classes but can you list its contents as well?

One last thing, this came from running your code via Eclipse, right? I don't believe running it via Maven would include the same list of jars, given that not all of them seem to be part of your dependencies, and the Properties folder specifically should not appear in there.

marwa811 commented 3 years ago
  1. For this Part: "C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\AgreementMakerLight.jar

I cannot inspect the contents of this jar. Can you let me know what goes into it? (you can open a jar file with any application that supports zip files and check the list of files it contains; does it contain any of org.semanticweb.owlapi or uk.ac.manchester folders?)"

Yes, this jar includes org.semanticweb.owlapi or uk.ac.manchester as it is a benchmark ontology matching tool. so ofcourse it includes those libraries as it loads 2 ontologies and finds the similar/ matching concepts. if this is what makes this conflict, what to do then?

  1. For "C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\target\classes" : includes the java classes (source code) for my project

    1. For "C:\Users\marwa\eclipse-workspace-photon\OntologyReuseProject\Properties" : includes only the log4j.properties file
  2. "One last thing, this came from running your code via Eclipse, right? I don't believe running it via Maven would include the same list of jars, given that not all of them seem to be part of your dependencies, and the Properties folder specifically should not appear in there." how can I run it via maven?

ignazio1977 commented 3 years ago

Yes, this jar includes org.semanticweb.owlapi or uk.ac.manchester as it is a benchmark ontology matching tool. so of course it includes those libraries as it loads 2 ontologies and finds the similar/ matching concepts. if this is what makes this conflict, what to do then?

Can you point me at the site where you downloaded the jar? I can see two projects and a number of releases on GitHub, I'd prefer to check the correct one - from the description online, this library may be inlining the OWLAPI classes in this jar, so its contents might be the source of the problem. If you tell me the version you're using, I can check against their source and see whether it's doable to rebuild it with a newer OWLAPI or if there's another way to accomodate your usage with their binaries.

ignazio1977 commented 3 years ago

Uhm, the project has a lib folder containing an owlapi.jar from seven years back, the pom file uses ELK standalone - I'm sure the conflict is coming from the classes in this jar, but I don't see an easy fix without making big changes to this library before you can use it in your project with OWLAPI 4. This might be quite a bit of work to fix.

marwa811 commented 3 years ago

This is the page of AML project https://github.com/AgreementMakerLight/AML-Project I am using version 3.2 (latest one). I checked their pom file https://github.com/AgreementMakerLight/AML-Project/blob/master/AgreementMakerLight/pom.xml They are using OWL API 3.4.10.. If this what makes the conflict how can I fix this ?? Should I change to OWLAPI version 3 also or what? I hope we can find a solution for this problem soon as adding classes to existing ontology is very important part in my research.

ignazio1977 commented 3 years ago

You can try changing your project to use 3.4.10 in your project as well, hopefully any issue that comes up will be easy to fix.

marwa811 commented 3 years ago

Is there a big difference between version 4 and version 3?? in another way, what kind of problems may I face If I changed OWLAPI version to version3 in my project?

ignazio1977 commented 3 years ago

There are some differences; the wiki has a migration guide from version 3 to version 4, you'd have to apply it in reverse.

marwa811 commented 3 years ago

Ok will check it and I will try a toy project first before I change the real project. Thank you for your help and excuse me for asking again if another problem appeared.

marwa811 commented 3 years ago

Based on our discussion, I tried adding the AML jar file in a toy project and adding the OWLAPI ver 3.4.10 in the POM file I tried this code: public static void main( String[] args ) throws Exception { OWLOntology targetOntology=laodOntology("C:\Users\marwa\eclipse-workspace-photon\Bioportaltools\oboe-core.owl"); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = manager.getOWLDataFactory(); try { OWLClass owlclass= factory.getOWLClass(IRI.create("http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Context")); OWLClass sourceOwlclass= factory.getOWLClass(IRI.create("http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Entity")); OWLSubClassOfAxiom axiom=factory.getOWLSubClassOfAxiom(owlclass, sourceOwlclass); manager.applyChange(new AddAxiom(targetOntology, axiom)); manager.saveOntology(targetOntology); }
catch(OWLException e) { // TODO Auto-generated catch block e.printStackTrace();
} } And I got this exception: Exception in thread "main" org.semanticweb.owlapi.model.UnknownOWLOntologyException: Unknown ontology: OntologyID(OntologyIRI(http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl)) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.getOntologyDocumentIRI(OWLOntologyManagerImpl.java:879) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:937) at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:931) at OWLAPITest.MainApp.main(MainApp.java:57)

Line 57 in the MainApp.java file is manager.saveOntology(targetOntology);

What is the problem now!

ignazio1977 commented 3 years ago

manager is not the ontology manager that targetOntology belongs to (it was loaded via a different manager, in the loadOntology() method).

Use targetOntology.getOWLOntologyManager().saveOntology(targetOntology) to resolve the problem.

marwa811 commented 3 years ago

Finally it works thanks .. will try to fix the version problem in the original project hope it works without problems

marwa811 commented 2 years ago

Hello, Could you guide me to what is the equivalent function to this line in OWLAPI ver 3.4? Iterator iterator = EntitySearcher.getAnnotationObjects(c, onto.getImportsClosure()).iterator();

I checked this page : https://github-wiki-see.page/m/owlcs/owlapi/wiki/Migrate-from-version-3.4-and-3.5-to-4.0 but I can not find what is the equivalent to "EntitySearcher.getAnnotationObjects()" methods in the older version.

ignazio1977 commented 2 years ago

The relevant entry is cls.getAnnotations(ont); change to EntitySearcher.getAnnotations(cls, ont);

EntitySearcher::getAnnotations was expanded later on in scope, EntitySearcher::getAnnotationObjects is the original functionality. To work with the imports closure, you'll need to apply the same method to all ontologies:

Iterator iterator = onto.getImportsClosure().stream().flatMap(o->c.getAnnotations(o).stream()).distinct().iterator()

marwa811 commented 2 years ago

Solved. Thank you