I have a project where the goal is to add user input into a turtle file (Named Main_Triples) that contains data about countries. I am using python to create functions that takes parameters to insert using SPARQL. I have to use SPARQL. How do I write this in SPARQL, and update the file?
My rdf structure:
ex:Afghanistan a country:addressCountry ;
ex:HappyLifeYear_Index 1.24e+01 ;
ex:SCI 37 ;
ex:UHC 34 ;
ex:average_wellbeing 3.8e+00 ;
ex:avglifeexp 5.97e+01 ;
ex:gdp 691 ;
ex:hpi_rank 110 ;
ex:hpi_total_score 2.02e+01 ;
ex:inequality_of_Outcome 43 ;
ex:info_availability "high" ;
ex:inregion "MiddleEastandNorthAfrica" ;
ex:population_count 29726803 .
My basic python code (not functioning. I want to take the parameters as input, and add a predicate/object to say Afghanistan.
def addcountryfact(country, fact, data):
country = URIRef(ex + country)
fact = URIRef(ex + fact)
data = URIRef(ex + data)
addto = ("""
PREFIX ex: <http://example.org/>
INSERT ?country ?fact ?data
WHERE {
?country ?fact ?data
}
""")
addto = g.query(cd, initBindings={'fact': fact, 'country': country, 'data': data})