Using Variables With Stored Values In RDFLIB And Python For Sparql Update Statement
I am quite new to RDFLIB and I am trying to learn how to use Delete/Insert statement to continually update data property values of individuals in my ontology from a CSV file. I am
Solution 1:
I would separate your string query building from query submission and test the query (visually) and ensure that it's correct like this:
q = """
DELETE {
?Product myontology:LifecycleData ?lifecycle
}
INSERT {
?Product myontology:LifecycleData xxx
}
WHERE {
?Product myontology:LifecycleData ?lifecycle
}
""".replace("xxx", str(df.tail(1)['Usecycle left'].values[0]))
# I like to use replace() rather than string templating
# so I don't have to escape characters like { in the query
print(q) # does it look like you expect it to at this point?
# then...
g.update(
q,
initNs={
"myontology": Namespace("http://example.com/myontology#")
}
)
Post a Comment for "Using Variables With Stored Values In RDFLIB And Python For Sparql Update Statement"