From 01ee0c3ce888b0720a666ebe9202dc3c15853689 Mon Sep 17 00:00:00 2001 From: stellamit Date: Tue, 8 Nov 2011 21:12:11 +0000 Subject: [PATCH] fix for NIHVIVO-3292 --- .../vitro/webapp/reasoner/SimpleReasoner.java | 117 ++++-------------- 1 file changed, 26 insertions(+), 91 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java index 6561e9a94..0ead5c18b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java @@ -1038,7 +1038,7 @@ public class SimpleReasoner extends StatementListener { inferenceRebuildModel.removeAll(); int numStmts = 0; - ArrayList individuals = this.getIndividualURIs(); + ArrayList individuals = this.getAllIndividualURIs(); for (String individualURI : individuals) { @@ -1246,21 +1246,27 @@ public class SimpleReasoner extends StatementListener { log.info("ABox inference model updated"); } - /* - * Special for version 1.3 - */ + public synchronized void computeMostSpecificType() { + recomputing = true; + try { + doComputeMostSpecificType(); + } finally { + recomputing = false; + } + } + + /* + * Special for version 1.4 + */ + public synchronized void doComputeMostSpecificType() { log.info("Computing mostSpecificType annotations."); HashSet unknownTypes = new HashSet(); - - // recompute the inferences - inferenceRebuildModel.enterCriticalSection(Lock.WRITE); - - try { - inferenceRebuildModel.removeAll(); - ArrayList individuals = this.getIndividualURIs(); + try { + String queryString = "select distinct ?subject where {?subject }"; + ArrayList individuals = this.getIndividualURIs(queryString); int numStmts = 0; for (String individualURI : individuals ) { @@ -1268,7 +1274,7 @@ public class SimpleReasoner extends StatementListener { Resource individual = ResourceFactory.createResource(individualURI); try { - setMostSpecificTypes(individual, inferenceRebuildModel, unknownTypes); + setMostSpecificTypes(individual, inferenceModel, unknownTypes); } catch (NullPointerException npe) { log.error("a NullPointerException was received while computing mostSpecificType annotations. Halting inference computation."); return; @@ -1294,83 +1300,10 @@ public class SimpleReasoner extends StatementListener { } } catch (Exception e) { log.error("Exception while computing mostSpecificType annotations", e); - inferenceRebuildModel.removeAll(); // don't do this in the finally, it's needed in the case - // where there isn't an exception return; - } finally { - inferenceRebuildModel.leaveCriticalSection(); - } + } log.info("Finished computing mostSpecificType annotations"); - - // reflect the recomputed inferences into the application inference - // model. - log.info("Updating ABox inference model with mostSpecificType annotations"); - - StmtIterator iter = null; - - inferenceRebuildModel.enterCriticalSection(Lock.WRITE); - scratchpadModel.enterCriticalSection(Lock.WRITE); - try { - // Add everything from the recomputed inference model that is not already - // in the current inference model to the current inference model. - try { - scratchpadModel.removeAll(); - iter = inferenceRebuildModel.listStatements(); - - int numStmts = 0; - - while (iter.hasNext()) { - Statement stmt = iter.next(); - - inferenceModel.enterCriticalSection(Lock.READ); - try { - if (!inferenceModel.contains(stmt)) { - scratchpadModel.add(stmt); - } - } finally { - inferenceModel.leaveCriticalSection(); - } - - numStmts++; - if ((numStmts % 10000) == 0) { - log.info("Still updating ABox inference model with mostSpecificType annotations..."); - } - - if (stopRequested) { - log.info("a stopRequested signal was received during recomputeMostSpecificType. Halting Processing."); - return; - } - } - } catch (Exception e) { - log.error("Exception while reconciling the current and recomputed ABox inference models", e); - return; - } finally { - iter.close(); - } - - iter = scratchpadModel.listStatements(); - while (iter.hasNext()) { - Statement stmt = iter.next(); - - inferenceModel.enterCriticalSection(Lock.WRITE); - try { - inferenceModel.add(stmt); - } catch (Exception e) { - log.error("Exception while reconciling the current and recomputed ABox inference models", e); - return; - } finally { - inferenceModel.leaveCriticalSection(); - } - } - } finally { - inferenceRebuildModel.removeAll(); - scratchpadModel.removeAll(); - inferenceRebuildModel.leaveCriticalSection(); - scratchpadModel.leaveCriticalSection(); - } - - log.info("ABox inference model updated with mostSpecificType annotations"); } public boolean isABoxReasoningAsynchronous() { @@ -1529,13 +1462,15 @@ public class SimpleReasoner extends StatementListener { } } } - - /** - * - */ - public ArrayList getIndividualURIs() { + + public ArrayList getAllIndividualURIs() { String queryString = "select distinct ?subject where {?subject ?type}"; + return getIndividualURIs(queryString); + } + + public ArrayList getIndividualURIs(String queryString) { + ArrayList individuals = new ArrayList(); aboxModel.enterCriticalSection(Lock.READ);