Having trouble with extracting data from from an rdf-file

88 views
Skip to first unread message

Benedikt Tröster

unread,
Nov 25, 2013, 12:27:05 PM11/25/13
to rdfli...@googlegroups.com
Hey!

I'm completely new to the rdf-lib and I tried my best to understand the examples. But I couldn't find a good example for my simple task of reading only surnames from an rdf-file (it's portion of the GND, to be exact).

Here is my code:

Here are the contents of the rdf-file:

This code simply returns nothing...
I don't understand how to achieve what I want... Is there a significant difference when accessing data online and from a file? (I'm a little confused by the BaseURI - What are they used for?)

Greetings and thanks for helping out a newbie :)

Gunnar Aastrand Grimnes

unread,
Nov 25, 2013, 1:43:02 PM11/25/13
to rdfli...@googlegroups.com
Hey Benedikt, 

You have two mistakes, firstly, RDF is triples of subject, predicate, object (s,p,o) - the rdflib resource object lets you tie down the subject part and more easily query the p's and o's to go with that subject. If you wanted to list everything known about a given person, you could have used "resource", but you are actually interested in all (s,o) pairs that are related the surname property. 

The other mistake is the URL for the surname property, you did: 

> gnd.resource('gnd:surname')

but RDFLib doesn't know how to expand the "gnd:" prefix shorthand to the full URL like this. Instead, you define a namespace: 


and then you can do: 

GND.surname 

to get the a URIRef object representing your property. 

This you can use in a call to graph.subject_objects() and you get your values: 

for person, name in gnd.subject_objects(GND.surname): 
   print person, name

Have fun!

- Gunnar




--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To post to this group, send email to rdfli...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/73fba093-53f8-4396-bb17-196ec1bbd3c9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
http://gromgull.net

Sergio Fernández

unread,
Nov 25, 2013, 1:49:36 PM11/25/13
to rdfli...@googlegroups.com
I've just past you a working example:

http://pastebin.com/vv9TCg8s

some links you should read:

https://rdflib.readthedocs.org/en/latest/
https://rdflib.readthedocs.org/en/latest/intro_to_parsing.html
https://rdflib.readthedocs.org/en/latest/apidocs/rdflib.html#rdflib.graph.Graph.objects

hope this helps

On 25 November 2013 18:27, Benedikt Tröster <ben...@gmail.com> wrote:
> --
> http://github.com/RDFLib
> ---
> You received this message because you are subscribed to the Google Groups
> "rdflib-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rdflib-dev+...@googlegroups.com.
> To post to this group, send email to rdfli...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rdflib-dev/73fba093-53f8-4396-bb17-196ec1bbd3c9%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--

Sergio Fernández <ser...@wikier.org>

Benedikt Tröster

unread,
Nov 26, 2013, 7:47:14 AM11/26/13
to rdfli...@googlegroups.com
Guys, thanks so much!
It's much clearer to me now!

Shaozhong Shi

unread,
Sep 7, 2017, 4:02:35 AM9/7/17
to rdflib-dev
Hi, Gunnar,

What you are talking about is interesting to me.

I have files which have some triples like the following.

Reply all
Reply to author
Forward
0 new messages