rdflib subclass problem

duncan smith duncan at invalid.invalid
Wed Mar 2 11:27:41 EST 2016


On 02/03/16 08:16, dieter wrote:
> duncan smith <duncan at invalid.invalid> writes:
> 
>>       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.
> 
> What you observe would be consistent with "RDFS.subClassOf" working
> in the other direction than the one you expect; i.e. that
> 
>    URIRef('Professor'), RDFS.subClassOf, FOAF.Person
> 
> means that "Person" is a subclass of "Professor" (not what
> you expect, that "Professor" is a subclass of "Person").
> 
> Carefully check whether "A rel B" means that "B" is in relation "rel" to "A"
> (I think that is the case) or that "A" is in relation "rel" to "B".
> 

According to https://www.w3.org/TR/rdf-schema/#ch_class -

A triple of the form:

    C1 rdfs:subClassOf C2

states that C1 is an instance of rdfs:Class, C2 is an instance of
rdfs:Class and C1 is a subclass of C2.


I might report it as a bug, but I'm not yet 100% convinced I haven't got
something wrong. Cheers.

Duncan





More information about the Python-list mailing list