Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed removal of linked blank nodes #487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading