Reputation: 107
I would like to modify a property for all resources in my RDFLib graph which I generated from parsing a file. I then want to save the modified graph into a new file.
Is there an easy way to do this?
I am using RDFLib in Python
Thanks!
Daniel
Upvotes: 1
Views: 109
Reputation: 1251
from rdflib import Graph
# create an rdflib graph
g = Graph()
# fill the graph from your file
g.parse('your_rdf_file.ttl', format="turtle")
# you can then modify the contents of the graph either by accessing the graph
# object directly (see https://rdflib.readthedocs.io/en/latest/intro_to_graphs.html)
# or by using SPARQL `UPDATE` queries (see
# https://rdflib.readthedocs.io/en/latest/intro_to_sparql.html
# but there's not really enough documentation on `UPDATE`!)
# e.g
g.update("SOME SPARQL UPDATE QUERY")
# serialize the graph to a new file
g.serialize(destination="new_file.ttl", format="turtle")
Upvotes: 1