I am executing sparql query through python rdflib like
r=sparql.prepareQuery('SELECT ?label WHERE { <%s> rdfs:label ?label . }'%i)
My aim is to get the labels for the concepts in this way. As a result I get something like this:
rdflib.term.Literal(u'primary phloem sieve cell', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#string'))
From this I want to extract the label and data type.(ie primary phloem sieve cell and string respectively for this case) I am using the
if type(o) == rdflib.term.Literal:
output.append(o.toPython())
Where
o= rdflib.term.Literal(u'primary phloem sieve cell', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#string'))
But it is not working. I am new to rdflib . Does anyone know how I can do that?
I know that I need to convert the result to string for label but what if the datatype is not string and I want to fetch the datatype