From a4f90721f3d4721007e3e590f115d15a952cfb08 Mon Sep 17 00:00:00 2001 From: stellamit Date: Thu, 14 Jul 2011 14:49:58 +0000 Subject: [PATCH] NIHVIVO-2900, NIHVIVO-2891 --- .../vitro/webapp/reasoner/SimpleReasoner.java | 67 +++++++++++++------ .../servlet/setup/SimpleReasonerSetup.java | 4 +- 2 files changed, 49 insertions(+), 22 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 3004e7ace..d5990e7e1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java @@ -7,8 +7,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import javax.servlet.ServletContext; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -951,17 +949,26 @@ public class SimpleReasoner extends StatementListener { aboxModel.enterCriticalSection(Lock.WRITE); tboxModel.enterCriticalSection(Lock.READ); + StmtIterator iter = null; + try { log.info("Computing class-based ABox inferences."); inferenceRebuildModel.removeAll(); - StmtIterator iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null); + iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null); int numStmts = 0; - while (iter.hasNext()) { + while (iter.hasNext()) { Statement stmt = iter.next(); - addedABoxTypeAssertion(stmt, inferenceRebuildModel, unknownTypes); - setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes); + try { + addedABoxTypeAssertion(stmt, inferenceRebuildModel, unknownTypes); + setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes); + } catch (NullPointerException npe) { + log.error("a NullPointerException was received while recomputing the ABox inferences. Halting inference computation."); + return; + } catch (Exception e) { + log.error("Exception while recomputing ABox inference model", e); + } numStmts++; if ((numStmts % 8000) == 0) { @@ -1023,6 +1030,7 @@ public class SimpleReasoner extends StatementListener { // where there isn't an exception return; } finally { + iter.close(); aboxModel.leaveCriticalSection(); tboxModel.leaveCriticalSection(); inferenceRebuildModel.leaveCriticalSection(); @@ -1043,7 +1051,7 @@ public class SimpleReasoner extends StatementListener { try { scratchpadModel.removeAll(); - StmtIterator iter = inferenceModel.listStatements(); + iter = inferenceModel.listStatements(); while (iter.hasNext()) { Statement stmt = iter.next(); @@ -1064,6 +1072,7 @@ public class SimpleReasoner extends StatementListener { } catch (Exception e) { log.error("Exception while reconciling the current and recomputed ABox inference models", e); } finally { + iter.close(); inferenceModel.leaveCriticalSection(); } @@ -1072,6 +1081,7 @@ public class SimpleReasoner extends StatementListener { inferenceModel.remove(scratchpadModel); } catch (Exception e){ log.error("Exception while reconciling the current and recomputed ABox inference models", e); + return; } finally { inferenceModel.leaveCriticalSection(); } @@ -1082,7 +1092,7 @@ public class SimpleReasoner extends StatementListener { try { scratchpadModel.removeAll(); - StmtIterator iter = inferenceRebuildModel.listStatements(); + iter = inferenceRebuildModel.listStatements(); while (iter.hasNext()) { Statement stmt = iter.next(); @@ -1102,7 +1112,9 @@ public class SimpleReasoner extends StatementListener { } } catch (Exception e) { log.error("Exception while reconciling the current and recomputed ABox inference models", e); + return; } finally { + iter.close(); inferenceModel.leaveCriticalSection(); } @@ -1111,6 +1123,7 @@ public class SimpleReasoner extends StatementListener { inferenceModel.add(scratchpadModel); } catch (Exception e){ log.error("Exception while reconciling the current and recomputed ABox inference models", e); + return; } finally { inferenceModel.leaveCriticalSection(); } @@ -1127,7 +1140,7 @@ public class SimpleReasoner extends StatementListener { /* * Special for version 1.3 */ - public synchronized void recomputeMostSpecificType() { + public synchronized void computeMostSpecificType() { HashSet unknownTypes = new HashSet(); @@ -1136,16 +1149,26 @@ public class SimpleReasoner extends StatementListener { aboxModel.enterCriticalSection(Lock.WRITE); tboxModel.enterCriticalSection(Lock.READ); + StmtIterator iter = null; + try { inferenceRebuildModel.removeAll(); - StmtIterator iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null); + iter = aboxModel.listStatements((Resource) null, RDF.type, (RDFNode) null); log.info("Computing mostSpecificType annotations."); int numStmts = 0; while (iter.hasNext()) { Statement stmt = iter.next(); - setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes); + + try { + setMostSpecificTypes(stmt.getSubject(), inferenceRebuildModel, unknownTypes); + } catch (NullPointerException npe) { + log.error("a NullPointerException was received while computing mostSpecificType annotations. Halting inference computation."); + return; + } catch (Exception e) { + log.error("Exception while computing mostSpecificType annotations", e); + } numStmts++; if ((numStmts % 8000) == 0) { @@ -1153,7 +1176,7 @@ public class SimpleReasoner extends StatementListener { } if (stopRequested) { - log.info("a stopRequested signal was received during recomputeMostSpecificType. Halting Processing."); + log.info("a stopRequested signal was received during computeMostSpecificType. Halting Processing."); return; } } @@ -1163,6 +1186,7 @@ public class SimpleReasoner extends StatementListener { // where there isn't an exception return; } finally { + iter.close(); aboxModel.leaveCriticalSection(); tboxModel.leaveCriticalSection(); inferenceRebuildModel.leaveCriticalSection(); @@ -1183,7 +1207,7 @@ public class SimpleReasoner extends StatementListener { try { scratchpadModel.removeAll(); - StmtIterator iter = inferenceRebuildModel.listStatements(); + iter = inferenceRebuildModel.listStatements(); int numStmts = 0; @@ -1205,7 +1229,9 @@ public class SimpleReasoner extends StatementListener { } } catch (Exception e) { log.error("Exception while reconciling the current and recomputed ABox inference models", e); + return; } finally { + iter.close(); inferenceModel.leaveCriticalSection(); } @@ -1214,6 +1240,7 @@ public class SimpleReasoner extends StatementListener { inferenceModel.add(scratchpadModel); } catch (Exception e){ log.error("Exception while reconciling the current and recomputed ABox inference models", e); + return; } finally { inferenceModel.leaveCriticalSection(); } @@ -1311,17 +1338,17 @@ public class SimpleReasoner extends StatementListener { retractions.removeAll(); retractions.leaveCriticalSection(); } - - if (abort) { - log.info("a NullPointerException was received while computing inferences in batch " + qualifier + " mode. Halting inference computation."); - return; - } - + if (stopRequested) { log.info("a stopRequested signal was received during DeltaComputer.run. Halting Processing."); return; } - + + if (abort) { + log.error("a NullPointerException was received while computing inferences in batch " + qualifier + " mode. Halting inference computation."); + return; + } + log.info("finished computing inferences for batch " + qualifier + " update"); if (batchMode1 && (aBoxDeltaModeler2.getRetractions().size() > 0)) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java index ee62b3492..c29e09034 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java @@ -110,7 +110,7 @@ public class SimpleReasonerSetup implements ServletContextListener { sleeps++; } - new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecompuer").start(); + new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecomputer").start(); } else if ( isMSTComputeRequired(sce.getServletContext()) ) { log.info("mostSpecificType computation required. It will be done in a separate thread."); @@ -200,7 +200,7 @@ public class SimpleReasonerSetup implements ServletContextListener { } public void run() { - simpleReasoner.recomputeMostSpecificType(); + simpleReasoner.computeMostSpecificType(); } } }