-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from edmcouncil/hermit_reasoner_addon
Hermit reasoner addon
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 65 additions & 3 deletions
68
...main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |