diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java index e28e616b8f..c3180910b2 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java @@ -492,7 +492,7 @@ private static String makeDescribe(Resource s) { * @param toRemove containing statements to be removed * @param removeFrom from which statements should be removed */ - public static void removeUsingSparqlConstruct(Model toRemove, Model removeFrom) { + private static void removeUsingSparqlConstruct(Model toRemove, Model removeFrom) { if(toRemove.isEmpty()) { return; } @@ -572,7 +572,7 @@ private static void addStatementPatterns(List stmts, for(Statement stmt : stmts) { Triple t = stmt.asTriple(); String lineWithoutVars = getLine(t, false); - if (lines.contains(lineWithoutVars)) { + if (lines.contains(lineWithoutVars) && !isLinked(stmt, stmts)) { continue; } else { lines.add(lineWithoutVars); @@ -591,6 +591,17 @@ private static void addStatementPatterns(List stmts, } } + private static boolean isLinked(Statement stmt, List stmts) { + RDFNode s = stmt.getSubject(); + RDFNode o = stmt.getObject(); + for (Statement st : stmts) { + if (st.getSubject().equals(o) || st.getObject().equals(s)) { + return true; + } + } + return false; + } + private static String getLine(Triple t, boolean createBlankNodeVariables) { if (createBlankNodeVariables) { return sparqlNodeDelete(t.getSubject(), null) + diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtilsTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtilsTest.java index 3679e8eee9..ae1eb21342 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtilsTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtilsTest.java @@ -17,7 +17,7 @@ public class JenaModelUtilsTest { public void removeUsingSparqlConstructTest() { Model removeFrom = getModel(); Model toRemove = getModel(); - JenaModelUtils.removeUsingSparqlConstruct(toRemove, removeFrom); + JenaModelUtils.removeWithBlankNodesAsVariables(toRemove, removeFrom); assertTrue(removeFrom.isEmpty()); } diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/tboxreasoner/impl/jfact/JFactTBoxReasonerTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/tboxreasoner/impl/jfact/JFactTBoxReasonerTest.java index d718119836..4fdbc25a88 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/tboxreasoner/impl/jfact/JFactTBoxReasonerTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/tboxreasoner/impl/jfact/JFactTBoxReasonerTest.java @@ -1,5 +1,8 @@ package edu.cornell.mannlib.vitro.webapp.tboxreasoner.impl.jfact; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.StringReader; import org.apache.jena.ontology.OntModel; @@ -16,8 +19,6 @@ import org.semanticweb.owlapi.util.SAXParsers; import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; -import edu.cornell.mannlib.vitro.webapp.migration.auth.AnnotationMigrator; -import edu.cornell.mannlib.vitro.webapp.migration.auth.ArmMigrator; import edu.cornell.mannlib.vitro.webapp.tboxreasoner.ReasonerConfiguration; import edu.cornell.mannlib.vitro.webapp.tboxreasoner.impl.BasicTBoxReasonerDriver; @@ -34,7 +35,8 @@ public class JFactTBoxReasonerTest { " \r\n" + " rdfs:subClassOf [ rdf:type owl:Class ;\r\n" + " owl:intersectionOf ( \r\n" + - " \r\n" + + " \r\n" + + " \r\n" + " )\r\n" + " ] .\r\n" + "\r\n" + @@ -89,9 +91,11 @@ public void testRemoveAxiomsWithBlankNodes() { waitForTBoxReasoning(driver); // Confirm that union model now contains inferred triples Assert.assertTrue(tboxUnion.size() > additions.size()); + assertFalse(tboxAssertions.isEmpty()); JenaModelUtils.removeWithBlankNodesAsVariables(subtractions, tboxAssertions.getBaseModel()); tboxAssertions.getBaseModel().notifyEvent(new EditEvent(null, false)); waitForTBoxReasoning(driver); + assertTrue(tboxAssertions.isEmpty()); // Confirm that no statements related to classes a, b or c remain in the // TBox union model. (The inference model may not be completely empty, because // the reasoner may supply unrelated triples related to OWL and RDFS vocabulary.)