protegeproject / swrlapi

Java API for working with the SWRL rule and SQWRL query languages
Other
99 stars 40 forks source link

owl-api issue using swrl api and openllet #47

Closed SamanthaBandini closed 6 years ago

SamanthaBandini commented 6 years ago

I'm trying to use owl-api (v5), swrl-api and openllet in the same project, using NetBeans as IDE. There's no way to make them work together, importing one causes the other to stop "working". I think there is a problem with dependencies but I can't figure it out.

I have tried in different ways, such as:

  1. using Gradle: (see build.gradle.txt [Note: I added the .txt to attach it here])
  1. using Maven: (see pom.xml.txt [Note: I added the .txt to attach it here])
    • set dependencies
    • when there were problems in resolving dependencies I manually installed it from jar using 'Manually install artifacts' from Netbeans

Both method works, as I can see all classes of each package, the problem is that in both ways I get stuck with exceptions like those listed below.

Running this code:

      try {
           /* PART 1 - OWL API - Retrieve information from ontology */
            ontology = manager.loadOntologyFromOntologyDocument(filein);
            IRI iri = ontology.getOntologyID().getOntologyIRI().get();
            IRI remoteIRI = IRI.create(Constants.ONTOLOGY_IRI);
            manager.getIRIMappers().add(new SimpleIRIMapper(remoteIRI, iri));
            //Retrieve all organizations and put in in manufacturers model
            reasoner = openllet.owlapi.OpenlletReasonerFactory.getInstance().createReasoner(ontology);
            factory = manager.getOWLDataFactory();
            final OWLClass Organization = factory.getOWLClass(IRI.create(ORGANIZATION_IRI));
            for (OWLNamedIndividual ind : reasoner.getInstances(Organization, false).getFlattened()){
                this.manufacturers.add(new PairItem(ind.getIRI(),ind.getIRI().getShortForm()));
            };
            //Init DONE, manufacturers retrieved

        /* PART 2 - RULE WITH SWRL */
        //Trying to instanciate the rule engine
            SWRLRuleEngine ruleEngine;
            ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
            System.out.println("Loaded classes");
            //SWRLAPIRule rule = ruleEngine.createSWRLRule("MY_RULE");
            //ruleEngine.infer();

        } catch (OWLOntologyCreationException ex) {
            Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
        }

Trying the test with Maven:

Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: java.lang.NoSuchMethodError. Message: org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom.getProperty()Lorg/semanticweb/owlapi/model/OWLPropertyExpression;
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:71)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:41)
    at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:38)
    at model.Model.init(Model.java:70)
    at Main.main(Main.java:22)
Caused by: java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom.getProperty()Lorg/semanticweb/owlapi/model/OWLPropertyExpression;
    at org.swrlapi.drools.converters.oo.DroolsOWLAxiom2AConverter.convert(DroolsOWLAxiom2AConverter.java:414)
    at org.swrlapi.drools.converters.oo.DroolsOWLAxiom2AConverter.visit(DroolsOWLAxiom2AConverter.java:626)
    at org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom.accept(OWLDataPropertyDomainAxiom.java:46)
    at org.swrlapi.drools.converters.oo.DroolsOWLAxiom2AConverter.convert(DroolsOWLAxiom2AConverter.java:571)
    at org.swrlapi.drools.core.DroolsSWRLRuleEngine.defineOWLAxiom(DroolsSWRLRuleEngine.java:229)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.exportOWLAxioms2TargetRuleEngine(DefaultSWRLRuleAndQueryEngine.java:416)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngine.importAssertedOWLAxioms(DefaultSWRLRuleAndQueryEngine.java:67)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:64)
    ... 4 more

Trying the test with Gradle: With all jars listed above:

Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntology.importsClosure()Ljava/util/stream/Stream;
    at openllet.owlapi.PelletReasoner.refresh(PelletReasoner.java:1167)
    at openllet.owlapi.PelletReasoner.<init>(PelletReasoner.java:397)
    at openllet.owlapi.PelletReasoner.<init>(PelletReasoner.java:364)
    at openllet.owlapi.OpenlletReasonerFactory.createReasoner(OpenlletReasonerFactory.java:62)
    at model.Model.init(Model.java:57)
    at Main.main(Main.java:22)

Without swrltab-2.0.5-jar-with-dependencies.jar:

Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: java.lang.NoSuchMethodError. Message: org.semanticweb.owlapi.model.OWLDocumentFormat.isPrefixOWLOntologyFormat()Z
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:71)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:41)
    at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:38)
    at model.Model.init(Model.java:68)
    at Main.main(Main.java:22)
Caused by: java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLDocumentFormat.isPrefixOWLOntologyFormat()Z
    at org.swrlapi.factory.DefaultIRIResolver.updatePrefixes(DefaultIRIResolver.java:165)
    at org.swrlapi.factory.DefaultSWRLAPIOWLOntology.<init>(DefaultSWRLAPIOWLOntology.java:163)
    at org.swrlapi.factory.SWRLAPIInternalFactory.createSWRLAPIOntology(SWRLAPIInternalFactory.java:266)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:53)
    ... 4 more

I tried 'PART 1' and 'PART 2' separately in different projects and both worked.

Thanks in advance.

cedaradmin commented 6 years ago

I'm guessing that they are using a different version of the OWLAPI.

Try the following:

mvn dependency:tree -Dverbose
SamanthaBandini commented 6 years ago

Thanks for the reply. As you said, the're using different owlapi versions; protégé components use owlapi 4 and openllet uses owlapi 5. I solved this using the release of Pellet reasoner compatible with owlapi 4 (https://github.com/ignazio1977/pellet).