Skip to content

Commit

Permalink
Merge pull request #391 from edmcouncil/hermit_reasoner_addon
Browse files Browse the repository at this point in the history
Hermit reasoner addon
  • Loading branch information
mereolog authored Jun 21, 2024
2 parents 84dcb63 + fe98acb commit 08ad4f6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
6 changes: 6 additions & 0 deletions onto-viewer-toolkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<version>${openllet.version}</version>
</dependency>

<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.4.5.519</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
public class OntoViewerToolkitApplication {

public static void main(String[] args) {
SpringApplication.run(OntoViewerToolkitApplication.class, args);
try {
SpringApplication.run(OntoViewerToolkitApplication.class, args);
System.exit(0);
}
catch (Exception exception) {
System.out.println(exception.getStackTrace());
System.exit(1);}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,83 @@
package org.edmcouncil.spec.ontoviewer.toolkit.handlers;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import openllet.owlapi.OpenlletReasonerFactory;
import org.edmcouncil.spec.ontoviewer.core.ontology.DetailsManager;
import org.edmcouncil.spec.ontoviewer.toolkit.OntoViewerToolkitCommandLine;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class OntologyConsistencyChecker {
private static final Logger LOGGER = LoggerFactory.getLogger(OntoViewerToolkitCommandLine.class);

private final DetailsManager detailsManager;
private final DetailsManager detailsManager;

public OntologyConsistencyChecker(DetailsManager detailsManager) {
this.detailsManager = detailsManager;
}

public boolean checkOntologyConsistency() {
var ontology = detailsManager.getOntology();
var reasoner = OpenlletReasonerFactory.getInstance().createReasoner(ontology);
return reasoner.isConsistent();
boolean reasoner1IsReady = false;
boolean reasoner2IsReady = false;
OWLReasoner reasoner1 = null;
OWLReasoner reasoner2 = null;
try {
reasoner1 = OpenlletReasonerFactory.getInstance().createReasoner(ontology);
reasoner1IsReady = true;
}
catch (Exception ex) {
}
try {
reasoner2 = new Reasoner(new Configuration(), ontology);
reasoner2IsReady = true;
}
catch (Exception exception) {
StackTraceElement[] exceptionElements = exception.getStackTrace();
LOGGER.error("Exception occurred while checking ontology consistency check: {}", exceptionElements[0]);
}

if (reasoner1IsReady & reasoner2IsReady) {
ExecutorService executor = Executors.newFixedThreadPool(2);
CompletableFuture<Boolean> future1 = CompletableFuture.supplyAsync(reasoner1::isConsistent, executor);
CompletableFuture<Boolean> future2 = CompletableFuture.supplyAsync(reasoner2::isConsistent, executor);
CompletableFuture<Object> firstCompleted = CompletableFuture.anyOf(future1, future2);

try {
Boolean result = (Boolean) firstCompleted.get();
future1.complete(true);
future2.complete(true);
executor.shutdownNow();
return result;
} catch (InterruptedException | ExecutionException exception) {
StackTraceElement[] exceptionElements = exception.getStackTrace();
LOGGER.error("Exception occurred while checking ontology consistency check: {}", exceptionElements[0]);
return false;
} finally {
executor.shutdown();
}
}

if (reasoner1IsReady) {
return reasoner1.isConsistent();
}

if (reasoner2IsReady) {
return reasoner2.isConsistent();
}

return false;
}
}

0 comments on commit 08ad4f6

Please sign in to comment.