3

I am trying to add a SWRL rule to my Ontology using SWRLAPI and OWLAPI. I am trying to use OWLAPI's version which is compatible with SWRLAPI. However, I still get errors when creating a rule. It seems to be a problem with the dependency management. I am using gradle as a dependency manager so this should have solved the issue.

The Exception is:

Error creating rule engine Drools. Exception: java.lang.NoClassDefFoundError. Message: org/drools/runtime/rule/AgendaFilter"

My build.gradle dependency file:

dependencies {
    compile group: 'net.sourceforge.owlapi', name: 'owlapi-distribution', version: '4.1.3'
    compile group: 'net.sourceforge.owlapi', name: 'org.semanticweb.hermit', version: '1.4.1.513'
    compile 'edu.stanford.swrl:swrlapi:2.0.5'
    compile 'edu.stanford.swrl:swrlapi-drools-engine:2.0.5'
}

The exception happens when executing createSWRLRuleEngine method:

public void addNewSWRLRule(SWRLRuleModel rule) throws SWRLBuiltInException, SWRLParseException {    
    SWRLRuleEngine swrlRuleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
    swrlRuleEngine.infer();
    swrlRuleEngine.createSWRLRule(rule.getName(), rule.getRule(), rule.getComment(), true);
}

Is there a dependency that must be added manually to solve this issue?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Bruno Pessanha
  • 2,874
  • 4
  • 24
  • 35

2 Answers2

0

You're using HermiT 1.4.1.513. That's compatible with owlapi 5, not 4 (the patch number matches the owlapi version). Use HermiT 1.3.8.413.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
0

The problem was that there were 2 maven dependencies from Drools Engine (edu.stanford.swrl:swrlapi-drools-engine:2.0.5) not resolved by gradle.

The missing dependencies were:

  • org.drools:knowledge-api:6.5.0.Final
  • org.drools:drools-osgi-integration:6.5.0.Final

I am not sure what is causing these not to be solved by gradle, but I managed to fix the issue in IntelliJ by converting the two missing dependencies to a Repository Library and searching for these in maven following these steps:

  1. File > Project Structure > Libraries
  2. Right button click on the missing library
  3. Convert to Repository Library
  4. Type the dependency name and search in maven repository
  5. Replace
Bruno Pessanha
  • 2,874
  • 4
  • 24
  • 35
  • Not clear what's happening, the two dependencies are in dependencyManagement in the parent pom file; that's a simple and common enough pattern, which I'd think Gradle understands and supports. Might be worth looking for Gradle bugs and checking the version you're using, in case it's a known and fixed issues. – Ignazio Sep 12 '18 at 22:53
  • Sure. It does seem like a bug in Gradle. I even checked my local maven repository and only the pom files were downloaded from these dependencies, but not the jar. Drools pom file seems to be correct. – Bruno Pessanha Sep 13 '18 at 13:16
  • That rings a bell, I've had before cases where a dependency was only partially downloaded - this might be due to all sorts of causes, network issues as well as a corrupt file due to a disk problem. Many times I've succeeded by deleting the folder containing the partial download and rebuilding - that forced Maven to download a fresh copy. The same should happen with Gradle, however in Gradle's case the files might not be copied to the maven repository but to Gradle's own repository. It's worth a try as it's a very simple attempt to make. – Ignazio Sep 13 '18 at 18:37