From a98f38b75b20e3cb35f7ee3539b7de4bc9edb0ab Mon Sep 17 00:00:00 2001 From: mereolog Date: Mon, 10 Jun 2024 12:38:52 +0200 Subject: [PATCH 1/3] first attempt at running two reasoner in parallel Signed-off-by: mereolog --- onto-viewer-toolkit/pom.xml | 6 ++++ .../handlers/OntologyConsistencyChecker.java | 36 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/onto-viewer-toolkit/pom.xml b/onto-viewer-toolkit/pom.xml index f81a6b72..24d42119 100644 --- a/onto-viewer-toolkit/pom.xml +++ b/onto-viewer-toolkit/pom.xml @@ -53,6 +53,12 @@ ${openllet.version} + + net.sourceforge.owlapi + org.semanticweb.hermit + 1.4.5.519 + + org.junit.jupiter diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java index 9ab9b681..9a3978af 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java @@ -1,7 +1,17 @@ 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.semanticweb.HermiT.Configuration; +import org.semanticweb.HermiT.Reasoner; import org.springframework.stereotype.Service; @Service @@ -15,7 +25,29 @@ public OntologyConsistencyChecker(DetailsManager detailsManager) { public boolean checkOntologyConsistency() { var ontology = detailsManager.getOntology(); - var reasoner = OpenlletReasonerFactory.getInstance().createReasoner(ontology); - return reasoner.isConsistent(); + var reasoner1 = OpenlletReasonerFactory.getInstance().createReasoner(ontology); + var reasoner2 = new Reasoner(new Configuration(), ontology); + + // Create an executor service to run tasks concurrently + ExecutorService executor = Executors.newFixedThreadPool(2); + + // Create CompletableFutures for the isConsistent calls + CompletableFuture future1 = CompletableFuture.supplyAsync(reasoner1::isConsistent, executor); + CompletableFuture future2 = CompletableFuture.supplyAsync(reasoner2::isConsistent, executor); + + // Use the anyOf method to return the result of the first completed future + CompletableFuture firstCompleted = CompletableFuture.anyOf(future1, future2); + + try { + // Get the result of the first completed future + Boolean result = (Boolean) firstCompleted.get(); + return result; + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + return false; // or handle the exception as needed + } finally { + // Shutdown the executor service + executor.shutdown(); + } } } \ No newline at end of file From 538d94e26f21dc45e86f144629aac328f96aa745 Mon Sep 17 00:00:00 2001 From: mereolog Date: Mon, 10 Jun 2024 15:00:21 +0200 Subject: [PATCH 2/3] ontology toolkit exit reported Signed-off-by: mereolog --- .../toolkit/OntoViewerToolkitApplication.java | 1 + .../handlers/OntologyConsistencyChecker.java | 68 +++++++++++++------ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java index 53e49e19..a0fe47f4 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java @@ -8,5 +8,6 @@ public class OntoViewerToolkitApplication { public static void main(String[] args) { SpringApplication.run(OntoViewerToolkitApplication.class, args); + System.exit(0); } } diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java index 9a3978af..df1ba116 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java @@ -10,14 +10,19 @@ 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; @@ -25,29 +30,52 @@ public OntologyConsistencyChecker(DetailsManager detailsManager) { public boolean checkOntologyConsistency() { var ontology = detailsManager.getOntology(); - var reasoner1 = OpenlletReasonerFactory.getInstance().createReasoner(ontology); - var reasoner2 = new Reasoner(new Configuration(), ontology); + 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 ex) { + LOGGER.error("Exception occurred while checking ontology consistency check: {}", ex.getMessage(), ex); + } - // Create an executor service to run tasks concurrently - ExecutorService executor = Executors.newFixedThreadPool(2); + if (reasoner1IsReady & reasoner2IsReady) { + ExecutorService executor = Executors.newFixedThreadPool(2); + CompletableFuture future1 = CompletableFuture.supplyAsync(reasoner1::isConsistent, executor); + CompletableFuture future2 = CompletableFuture.supplyAsync(reasoner2::isConsistent, executor); + CompletableFuture firstCompleted = CompletableFuture.anyOf(future1, future2); - // Create CompletableFutures for the isConsistent calls - CompletableFuture future1 = CompletableFuture.supplyAsync(reasoner1::isConsistent, executor); - CompletableFuture future2 = CompletableFuture.supplyAsync(reasoner2::isConsistent, executor); + try { + Boolean result = (Boolean) firstCompleted.get(); + future1.complete(true); + future2.complete(true); + executor.shutdownNow(); + return result; + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + return false; + } finally { + executor.shutdown(); + } + } - // Use the anyOf method to return the result of the first completed future - CompletableFuture firstCompleted = CompletableFuture.anyOf(future1, future2); + if (reasoner1IsReady) { + return reasoner1.isConsistent(); + } - try { - // Get the result of the first completed future - Boolean result = (Boolean) firstCompleted.get(); - return result; - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - return false; // or handle the exception as needed - } finally { - // Shutdown the executor service - executor.shutdown(); + if (reasoner2IsReady) { + return reasoner2.isConsistent(); } + + return false; } } \ No newline at end of file From fe98acb64923807c80a9272693511bb18780acda Mon Sep 17 00:00:00 2001 From: mereolog Date: Thu, 13 Jun 2024 10:30:28 +0200 Subject: [PATCH 3/3] better exception handling for toolkit Signed-off-by: mereolog --- .../toolkit/OntoViewerToolkitApplication.java | 9 +++++++-- .../toolkit/handlers/OntologyConsistencyChecker.java | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java index a0fe47f4..c87c7485 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/OntoViewerToolkitApplication.java @@ -7,7 +7,12 @@ public class OntoViewerToolkitApplication { public static void main(String[] args) { - SpringApplication.run(OntoViewerToolkitApplication.class, args); - System.exit(0); + try { + SpringApplication.run(OntoViewerToolkitApplication.class, args); + System.exit(0); + } + catch (Exception exception) { + System.out.println(exception.getStackTrace()); + System.exit(1);} } } diff --git a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java index df1ba116..edb034f8 100644 --- a/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java +++ b/onto-viewer-toolkit/src/main/java/org/edmcouncil/spec/ontoviewer/toolkit/handlers/OntologyConsistencyChecker.java @@ -44,8 +44,9 @@ public boolean checkOntologyConsistency() { reasoner2 = new Reasoner(new Configuration(), ontology); reasoner2IsReady = true; } - catch (Exception ex) { - LOGGER.error("Exception occurred while checking ontology consistency check: {}", ex.getMessage(), ex); + catch (Exception exception) { + StackTraceElement[] exceptionElements = exception.getStackTrace(); + LOGGER.error("Exception occurred while checking ontology consistency check: {}", exceptionElements[0]); } if (reasoner1IsReady & reasoner2IsReady) { @@ -60,8 +61,9 @@ public boolean checkOntologyConsistency() { future2.complete(true); executor.shutdownNow(); return result; - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + } catch (InterruptedException | ExecutionException exception) { + StackTraceElement[] exceptionElements = exception.getStackTrace(); + LOGGER.error("Exception occurred while checking ontology consistency check: {}", exceptionElements[0]); return false; } finally { executor.shutdown();