rdflib subclass problem
duncan smith
duncan at invalid.invalid
Tue Mar 1 20:42:33 EST 2016
Hello,
I'm just getting to grips with RDF and rdflib, and I've hit
something I can't figure out.
I have a graph with information on two people. (I haven't shown the
imports below because they're scattered around my interactive session
and I might reconstruct them incorrectly. Anyone familiar with rdflib
will probably know what they are.)
>>> G = Graph()
>>> mark = BNode()
>>> nat = BNode()
>>> G.add((mark, RDF.type, FOAF.Person))
>>> G.add((mark, FOAF.firstName, Literal('mark')))
>>> G.add((nat, RDF.type, URIRef('Professor')))
>>> G.add((nat, FOAF.firstName, Literal('natalie')))
>>> G.add((URIRef('Professor'), RDFS.subClassOf, FOAF.Person))
>>>
So I have specified that mark is a Person, natalie is a Professor, and
that Professor is a subclass of Person. (I know that Professor is really
a FOAF.title, but I'm just tinkering ATM.)
>>> qres = G.query(
"""SELECT DISTINCT ?aname
WHERE {
?a rdf:type foaf:Person .
?a foaf:firstName ?aname .
}""", initNs = {"rdf": RDF,"foaf": FOAF})
>>> for row in qres:
print "%s is a person" % row
mark is a person
>>> qres = G.query(
"""SELECT DISTINCT ?aname
WHERE {
?a rdf:type ?prof .
?a foaf:firstName ?aname .
}""", initNs = {"rdf": RDF,"foaf": FOAF, "prof":
URIRef('Professor')})
>>> for row in qres:
print "%s is a Prof" % row
natalie is a Prof
mark is a Prof
>>>
But according to the above queries only mark is a Person, and each is a
Professor. I would have thought that both would be Persons and only
natalie would be a Professor. Can anyone spot where I'm going wrong
here? Thanks.
Duncan
More information about the Python-list
mailing list