Ideally, you'd associate a rdfs:label or something with each URI resource and print the labels instead, but you can also bind a namespace and format output according to that. In your case, perhaps
```python import rdflib g = rdflib.Graph() g.parse("ex.rdf") g.bind("so", "http://stackoverflow.com/q/20474862/1281433/") qres = g.query( """ select ?i ?type where { ?i a/(rdfs:subClassOf)* ?type }""") for row in qres: i, type_ = [e.n3(g.namespace_manager) for e in row] print(f"{i} is {type_}") ``` yields ``` so:Apurva is so:Man so:Apurva is so:Mortal so:Cathy is so:Girl so:Cathy is so:Mad ``` On Sunday, June 7, 2020 at 3:44:27 PM UTC-4, Nisarg Patel wrote: > > import rdflib > > g = rdflib.Graph() > > g.parse("ExampleRdf1.rdf") #I have uploaded RDF file. > > qres = g.query( > """ > select ?i ?type where { > ?i a/(rdfs:subClassOf)* ?type > }""") > > > for row in qres: > print(" %s is %s" % row ) > > > ##output of this query: > > http://stackoverflow.com/q/20474862/1281433/Apurva is > http://stackoverflow.com/q/20474862/1281433/Man > http://stackoverflow.com/q/20474862/1281433/Apurva is > http://stackoverflow.com/q/20474862/1281433/Mortal > http://stackoverflow.com/q/20474862/1281433/Cathy is > http://stackoverflow.com/q/20474862/1281433/Girl > http://stackoverflow.com/q/20474862/1281433/Cathy is > http://stackoverflow.com/q/20474862/1281433/Mad > > > I want to remove this link(http://stackoverflow.com/q/20474862/1281433) > from result. its Prefix. > i need output like this: > > Apurva is Man > Apurva is Mortal > Cathy is Girl > Cathy is Mad. > > > Can anyone help me with this? > > > #ExampleRdf1.rdf file. > > <?xml version="1.0" encoding="utf-8" ?> > <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> > > <rdf:Description rdf:about=" > http://stackoverflow.com/q/20474862/1281433/Apurva"> > <rdf:type> > <rdf:Description rdf:about=" > http://stackoverflow.com/q/20474862/1281433/Man"> > <rdfs:subClassOf rdf:resource=" > http://stackoverflow.com/q/20474862/1281433/Mortal"/> > </rdf:Description> > </rdf:type> > > </rdf:Description> > > <rdf:Description rdf:about=" > http://stackoverflow.com/q/20474862/1281433/Cathy"> > <rdf:type> > <rdf:Description rdf:about=" > http://stackoverflow.com/q/20474862/1281433/Girl"> > <rdfs:subClassOf rdf:resource=" > http://stackoverflow.com/q/20474862/1281433/Mad"/> > </rdf:Description> > </rdf:type> > > </rdf:Description> > > </rdf:RDF> > -- http://github.com/RDFLib --- You received this message because you are subscribed to the Google Groups "rdflib-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/85c1de08-bc21-4f87-b396-d9c3446e29e1o%40googlegroups.com.