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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rdflib-dev/201d3b24-55b6-4165-9233-c514d65428a6o%40googlegroups.com.