I am trying to write SPARQL queries using rdflib in python and here below is my code. I want the queries just to return the values of the class or the entities without the URI or the namespace. I don't want to parse the results using regex. I am looking for any built in function in rdflib.
from rdflib import Graph
g = Graph()
g.parse("/Users/SUV/Desktop/AlfredOWL2.owl")
qres = g.query("""PREFIX ex:<http://www.semanticweb.org/suv/ontologies/2015/3/alfredowl/> SELECT ?Mood ?Action WHERE {
?Mood rdf:type ex:Mood .
?Mood ex:possible ?Action}""")
for row in qres:
print row.Mood, row.Action