Skip to content

Commit

Permalink
Fixed removal of linked blank nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed Jan 22, 2025
1 parent 53ca1d8 commit 4b9f5e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -572,7 +572,7 @@ private static void addStatementPatterns(List<Statement> 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);
Expand All @@ -591,6 +591,17 @@ private static void addStatementPatterns(List<Statement> stmts,
}
}

private static boolean isLinked(Statement stmt, List<Statement> 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) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -34,7 +35,8 @@ public class JFactTBoxReasonerTest {
" \r\n" +
" rdfs:subClassOf [ rdf:type owl:Class ;\r\n" +
" owl:intersectionOf ( <http://vivo.mydomain.edu/individual/class_a>\r\n" +
" <http://vivo.mydomain.edu/individual/class_b>\r\n" +
" <http://vivo.mydomain.edu/individual/class_b>\r\n" +
" <http://vivo.mydomain.edu/individual/class_c>\r\n" +
" )\r\n" +
" ] .\r\n" +
"\r\n" +
Expand Down Expand Up @@ -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.)
Expand Down

0 comments on commit 4b9f5e9

Please sign in to comment.