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


Groups > comp.lang.python > #103844

Re: rdflib subclass problem

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: rdflib subclass problem
Date Wed, 02 Mar 2016 09:16:14 +0100
Lines 70
Message-ID <mailman.96.1456906584.20602.python-list@python.org> (permalink)
References <hyrBy.57148$6O4.21031@fx33.iad>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de 3E8w3cKaTcizi/Q9dQMqEwOPEjLq9kaaCaQL4+9c3tTw==
Cancel-Lock sha1:f/bYFezDPdSqsmLl53auakMIrak=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"a"': 0.09; 'here?': 0.09; 'imports': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subclass': 0.09; '"%s': 0.16; '"b"': 0.16; 'distinct': 0.16; 'expect,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'row': 0.16; 'thanks.': 0.18; '(not': 0.20; 'subject:problem': 0.22; 'consistent': 0.23; 'specified': 0.23; "haven't": 0.24; "i've": 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'figure': 0.27; 'skip:u 20': 0.28; "i'm": 0.30; 'print': 0.30; 'probably': 0.31; 'anyone': 0.32; "can't": 0.32; 'getting': 0.33; 'direction': 0.35; 'i.e.': 0.35; 'something': 0.35; 'according': 0.36; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'received:org': 0.37; 'thought': 0.37; 'charset:us- ascii': 0.37; 'wrong': 0.38; 'means': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'received:de': 0.40; 'spot': 0.63; 'information': 0.63; 'person,': 0.66; "they're": 0.66; 'person.': 0.70; 'carefully': 0.72; 'smith': 0.76; 'professor,': 0.91; 'natalie': 0.95
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57b39451.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103844

Show key headers only | View raw


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".

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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