Reputation: 60
I know there is an update statement in SPARQL, but I am not really sure how to use it in RDFLIB. For instance, I have an ontology that contains Alice and Julius as individuals and I want to run a SPARQL update to change their properties. This includes things like updating their ages, likes, hobbies, etc.
I also want to be able to add individuals and their properties if they do not exist in the ontology. Example, adding John, his age, likes, hobbies, etc.
Upvotes: 0
Views: 389
Reputation: 11
As pointed out in Nicholas Car's answer, you can use g.update(<SPARQL Update Statement>)
to update the graph using SPARQL.
You can also use g.set((<Subject>, <Predicate>, <Object>))
to update the graph using triplets. This will replace the existing triplets with the new triplet.
Lastly, if the goal is simply to add a new triplet, g.add((<Subject>, <Predicate>, <Object>))
allows you to add a new entry from a triplet. Note, however, that this does not replace existing values.
Upvotes: 0
Reputation: 1251
I'm just adding UninformedUser's comment here in a response so this can be accepted.
You do just use g.update(queryString)
, see the documentation here:
https://rdflib.readthedocs.io/en/latest/intro_to_sparql.html#update-queries
Upvotes: 1