pythonsparqlrdflib

How to run a SPARQL update statement using RDFLIB in python


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.


Solution

  • 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