From 9f39bdb4e6f5c02aeeafc736af4a672bd9a694ab Mon Sep 17 00:00:00 2001 From: stellamit Date: Mon, 12 Dec 2011 17:24:20 +0000 Subject: [PATCH] merging changes from 14 branch --- .../vitro/webapp/reasoner/SimpleReasoner.java | 81 ++++++++++--------- 1 file changed, 45 insertions(+), 36 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 ba21f65e9..d2115f61e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java @@ -132,16 +132,8 @@ public class SimpleReasoner extends StatementListener { setMostSpecificTypes(stmt.getSubject(), inferenceModel, new HashSet()); } - for (ReasonerPlugin plugin : getPluginList()) { - try { - if (plugin.isInterestedInAddedStatement(stmt)) { - plugin.addedABoxStatement( - stmt, aboxModel, inferenceModel, tboxModel); - } - } catch (Throwable t) { - log.error(t, t); - } - } + doPlugins(ModelUpdate.Operation.ADD,stmt); + } catch (Exception e) { // don't stop the edit if there's an exception log.error("Exception while computing inferences: " + e.getMessage()); @@ -158,11 +150,7 @@ public class SimpleReasoner extends StatementListener { try { - // The delta modeler could optionally record only statements relevant - // to reasoning by checking the .isInterestedInRemovedStatement() - // methods on the plugins in addition to recording rdf:type - // statements. If property reasoning were uncommented, however, - // almost all statements would be relevant. + if (!isInterestedInRemovedStatement(stmt)) return; if (batchMode1) { aBoxDeltaModeler1.removedStatement(stmt); @@ -174,16 +162,7 @@ public class SimpleReasoner extends StatementListener { setMostSpecificTypes(stmt.getSubject(), inferenceModel, new HashSet()); } - for (ReasonerPlugin plugin : getPluginList()) { - try { - if (plugin.isInterestedInRemovedStatement(stmt)) { - plugin.removedABoxStatement( - stmt, aboxModel, inferenceModel, tboxModel); - } - } catch (Throwable t) { - log.error(t, t); - } - } + doPlugins(ModelUpdate.Operation.RETRACT,stmt); } } catch (Exception e) { // don't stop the edit if there's an exception @@ -1061,18 +1040,11 @@ public class SimpleReasoner extends StatementListener { Statement stmt = iter.next(); try { - removedABoxTypeAssertion(stmt, inferenceModel); - for (ReasonerPlugin plugin : getPluginList()) { - try { - if (plugin.isInterestedInRemovedStatement(stmt)) { - plugin.removedABoxStatement( - stmt, aboxModel, inferenceModel, tboxModel); - } - } catch (Throwable t) { - log.error(t, t); - } - } + if (stmt.getPredicate().equals(RDF.type)) { + removedABoxTypeAssertion(stmt, inferenceModel); + } setMostSpecificTypes(stmt.getSubject(), inferenceModel, new HashSet()); + doPlugins(ModelUpdate.Operation.RETRACT,stmt); } catch (NullPointerException npe) { abort = true; break; @@ -1183,6 +1155,43 @@ public class SimpleReasoner extends StatementListener { return individuals; } + /** + * + */ + protected void doPlugins(ModelUpdate.Operation op, Statement stmt) { + + for (ReasonerPlugin plugin : getPluginList()) { + try { + switch (op) { + case ADD: + if (plugin.isInterestedInAddedStatement(stmt)) { + plugin.addedABoxStatement(stmt, aboxModel, inferenceModel, tboxModel); + } + break; + case RETRACT: + if (plugin.isInterestedInRemovedStatement(stmt)) { + plugin.removedABoxStatement(stmt, aboxModel, inferenceModel, tboxModel); + } + break; + } + } catch (Throwable t) { + log.error("Exception while processing " + (op == ModelUpdate.Operation.ADD ? "an added" : "a removed") + + " statement in SimpleReasoner plugin:" + plugin.getClass().getName() + " -- " + t.getMessage()); + } + } + } + + public boolean isInterestedInRemovedStatement(Statement stmt) { + + if (stmt.getPredicate().equals(RDF.type)) return true; + + for (ReasonerPlugin plugin : getPluginList()) { + if (plugin.isInterestedInRemovedStatement(stmt)) return true; + } + + return false; + } + /** * This is called when the system shuts down. */