Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103881

Re: rdflib subclass problem

Subject Re: rdflib subclass problem
Newsgroups comp.lang.python
References <hyrBy.57148$6O4.21031@fx33.iad> <mailman.96.1456906584.20602.python-list@python.org>
From duncan smith <duncan@invalid.invalid>
Message-ID <4wEBy.1373$X_.923@fx04.iad> (permalink)
Organization blocknews - www.blocknews.net
Date 2016-03-02 16:27 +0000

Show all headers | View raw


On 02/03/16 08:16, dieter wrote:
> duncan smith <duncan@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

rdflib subclass problem duncan smith <duncan@invalid.invalid> - 2016-03-02 01:42 +0000
  Re: rdflib subclass problem dieter <dieter@handshake.de> - 2016-03-02 09:16 +0100
    Re: rdflib subclass problem duncan smith <duncan@invalid.invalid> - 2016-03-02 16:27 +0000

csiph-web