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


Groups > comp.lang.python > #103828 > unrolled thread

rdflib subclass problem

Started byduncan smith <duncan@invalid.invalid>
First post2016-03-02 01:42 +0000
Last post2016-03-02 16:27 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#103828 — rdflib subclass problem

Fromduncan smith <duncan@invalid.invalid>
Date2016-03-02 01:42 +0000
Subjectrdflib subclass problem
Message-ID<hyrBy.57148$6O4.21031@fx33.iad>
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

[toc] | [next] | [standalone]


#103844

Fromdieter <dieter@handshake.de>
Date2016-03-02 09:16 +0100
Message-ID<mailman.96.1456906584.20602.python-list@python.org>
In reply to#103828
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".

[toc] | [prev] | [next] | [standalone]


#103881

Fromduncan smith <duncan@invalid.invalid>
Date2016-03-02 16:27 +0000
Message-ID<4wEBy.1373$X_.923@fx04.iad>
In reply to#103844
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web