Yen removes triple with anonymous node

I am trying to remove a triple from a model using Jena without success. Things work well when the subject, predicate and object are URIs or literals, but for anonymous nodes it doesn't seem to work. For example, consider this three in a model:

_:A68d23cacX3aX13f793fa898X3aXX2dX7ffd <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "class" . 

I would like to remove it using:

 Node nodeSubject = Node.createAnon(); //or Node.ANY Node nodePredicate = Node.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#value"); Node nodeObject = Node.createLiteral("class"); Triple triple = Triple.create(nodeSubject, nodePredicate, nodeObject); inMemModel.getGraph().delete(triple); 

I cannot remove the triple, whether I createAnon or Node.ANY . I would not want to use AnonId simply because I am running my code on another machine. I doubt the same anonymous identifier will be created.

+4
source share
1 answer

Simple answer:

 inMemModel.removeAll(null, RDF.value, ResourceFactory.createPlainLiteral("class")); 

This will delete all triples where the predicate is rdf:value and the object is "class" .

Inside - at the SPI level you tried - you could use inMemModel.remove(Node.ANY, nodePredicate, nodeObject) , which finds and removes (using delete ) the corresponding triples. delete takes the main triple and therefore does not find find.

createAnon() does not work simply because it is a different object, so do not delete anything.

+5
source

Source: https://habr.com/ru/post/1487987/


All Articles