how do i delete node

18 views
Skip to first unread message

chetan...@gmail.com

unread,
Feb 19, 2020, 10:02:33 AM2/19/20
to rdflib-dev
I want to delete the node created either through BNode or URIRef. How should I do that? Any help will be highly appreciated.
When I remove the triple, it only removes the class instantiation not the instance itself.

Nicholas Car

unread,
Feb 24, 2020, 3:28:17 AM2/24/20
to rdfli...@googlegroups.com
If you know the URI, do this:

# if you know what uri_x is
for s, p, o in g.triples((URIRef(uri_x), None, None)):
    g.remove((s, p, o))

This will iterate through every triple with uri_x as its subject and remove it from the graph.

Of you don’t know the URI, e.g. for a Blank Node, find it then delete:

for s, p, o in g.triples((URIRef(some_object_uri)URIRef(some_property_uri), None)):
    # o is now the Blank Node URI for the triple <some_object_uri> <some_property_uri> <o>
    # loop through all triples with o as subject and remove them
    for s2, p2, o2 in g.triples((o, None, None)):
        g.remove((s2, p2, o2))

You could also use a SPARQL DELETE query put to the graph via:

g.update((your_delete_query))

Nick


On 20 Feb 2020, at 1:02 am, chetan...@gmail.com wrote:

I want to delete the node created either through BNode or URIRef. How should I do that? Any help will be highly appreciated.
When I remove the triple, it only removes the class instantiation not the instance itself.

--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/0dc564d8-e14c-440a-b421-85cfebb36ba8%40googlegroups.com.

______________________________________________________________________________________
 
Dr Nicholas Car
Data Systems Architect
SURROUND Australia Pty Ltd
Address P.O. Box 86, Mawson, Canberra ACT 2607
Phone  +61 477 560 177
Email  nichol...@surroundaustralia.com
Website  https://surroundaustralia.com

Enhancing Intelligence Within Organisations
delivering evidence that connects decisions to outcomes






Reply all
Reply to author
Forward
0 new messages