Walking through resource

12 views
Skip to first unread message

TI_Eugene

unread,
Mar 6, 2012, 2:18:24 AM3/6/12
to surfrdf
I'm novice in semaweb and trying to use surfrdf for handling data
(contacts, tasks etc) in my django (?) project (against RDBS).
Testing data - TimBL card (http://www.w3.org/People/Berners-Lee/
card#i), via rdflib (rdflib_example.py).
Questions are:
1. Can I list all defined (in this card) FOAF attributes - or I have
to try to get _each_ available in FOAF?
2. Can't get office address. person.contact_office.first returns BNode
- and that's all.

TI_Eugene

unread,
Mar 6, 2012, 4:11:51 AM3/6/12
to surfrdf
I'm novice in SemaWeb and try to use surfrdf as data handling backend
for django project.
Using examples/rdflib_example.py :
1. How I can list all defined FOAF attributes (predicates) in given
card (TimBL)? Or I have to try to get all available (for FOAF)
attributes?
2. How I can get office address? Now person.contact_office returns
BNode.

Cosmin Basca

unread,
Mar 6, 2012, 5:14:37 AM3/6/12
to sur...@googlegroups.com
Hi Eugene,

On Tuesday, March 6, 2012 8:18:24 AM UTC+1, TI_Eugene wrote:
I'm novice in semaweb and trying to use surfrdf for handling data
(contacts, tasks etc) in my django (?) project (against RDBS).
Testing data - TimBL card (http://www.w3.org/People/Berners-Lee/
card#i
), via rdflib (rdflib_example.py).
Questions are:
1. Can I list all defined (in this card) FOAF attributes - or I have
to try to get _each_ available in FOAF?
yes you can, there are several ways to do that
1) use the python dir function, end enumerate over all properties checking the ones that are in the foaf namespace
2) use the rdf_direct and rdf_inverse members where these properties are stored
3) export the graph() of the resource and find all FOAF properties 
 
I think 2) is the way to go, but depends on your scenario

2. Can't get office address. person.contact_office.first returns BNode
- and that's all.

In Semantic Web, one can have nodes (objects or subjects) that do not have a public identifier (like a URL) those are called blank nodes (BNode in surf). A BNode has properties of it's own, so if you are looking to get the address, try to see what properties the BNode itself has.

Hope this helps,
Cheers,
Cosmin 

Eugene A. Pivnev

unread,
Mar 6, 2012, 11:05:56 AM3/6/12
to sur...@googlegroups.com
I attached test script for illustartion.


On 06.03.2012 14:14, Cosmin Basca wrote:
Hi Eugene,

On Tuesday, March 6, 2012 8:18:24 AM UTC+1, TI_Eugene wrote:
I'm novice in semaweb and trying to use surfrdf for handling data
(contacts, tasks etc) in my django (?) project (against RDBS).
Testing data - TimBL card (http://www.w3.org/People/Berners-Lee/
card#i
), via rdflib (rdflib_example.py).
Questions are:
1. Can I list all defined (in this card) FOAF attributes - or I have
to try to get _each_ available in FOAF?
yes you can, there are several ways to do that
1) use the python dir function, end enumerate over all properties checking the ones that are in the foaf namespace
Nothing interesting - just API attributes/methods.


2) use the rdf_direct and rdf_inverse members where these properties are stored
rdfdirect returns same values (as dict values) as rdf_type.
rdf_reverse returns nothing (sorry - empty dict)


3) export the graph() of the resource and find all FOAF properties

Maybe - this way?..


 
I think 2) is the way to go, but depends on your scenario

2. Can't get office address. person.contact_office.first returns BNode
- and that's all.

In Semantic Web, one can have nodes (objects or subjects) that do not have a public identifier (like a URL) those are called blank nodes (BNode in surf). A BNode has properties of it's own, so if you are looking to get the address, try to see what properties the BNode itself has.
I tried (last line in script). Nothin :-(
test_timbl.py

Pēteris Caune

unread,
Mar 6, 2012, 11:52:07 AM3/6/12
to surfrdf
Hi Eugene,

attributes are loaded lazily. If you want to enumerate them, you can
do resource.load() to load the explicitly.

Try this:

#!/usr/bin/env python
# encoding: utf-8

import rdflib, surf
from surf.util import rdf2attr

store = surf.Store(reader = "rdflib", writer = "rdflib",
rdflib_store = "IOMemory")
session = surf.Session(store)
store.load_triples(source = "http://www.w3.org/People/Berners-Lee/
card.rdf")
Person = session.get_class(surf.ns.FOAF.Person)
all_persons = Person.all()
for person in all_persons:
print person.foaf_name.first
person.load()
for key in person.rdf_direct:
print rdf2attr(key, True)



On Mar 6, 6:05 pm, "Eugene A. Pivnev" <ti.eug...@gmail.com> wrote:
> I attached test script for illustartion.
>
> On 06.03.2012 14:14, Cosmin Basca wrote:
>
>
>
>
>
>
>
> > Hi Eugene,
>
> > On Tuesday, March 6, 2012 8:18:24 AM UTC+1, TI_Eugene wrote:
>
> >     I'm novice in semaweb and trying to use surfrdf for handling data
> >     (contacts, tasks etc) in my django (?) project (against RDBS).
> >     Testing data - TimBL card (http://www.w3.org/People/Berners-Lee/
> >     card#i <http://www.w3.org/People/Berners-Lee/card#i>), via rdflib
> >     (rdflib_example.py).
> >     Questions are:
> >     1. Can I list all defined (in this card) FOAF attributes - or I have
> >     to try to get _each_ available in FOAF?
>
> > yes you can, there are several ways to do that
> > 1) use the python *dir* function, end enumerate over all properties
> > checking the ones that are in the foaf namespace
>
> Nothing interesting - just API attributes/methods.
>
> > 2) use the *rdf_direct* and *rdf_inverse* members where these
> > properties are stored
>
> rdfdirect returns same values (as dict values) as rdf_type.
> rdf_reverse returns nothing (sorry - empty dict)
>
> > 3) export the *graph()* of the resource and find all *FOAF* properties
>
> Maybe - this way?..
>
> > I think 2) is the way to go, but depends on your scenario
>
> >     2. Can't get office address. person.contact_office.first returns
> >     BNode
> >     - and that's all.
>
> > In Semantic Web, one can have nodes (objects or subjects) that do not
> > have a public identifier (like a URL) those are called blank nodes
> > (BNode in surf). A BNode has properties of it's own, so if you are
> > looking to get the address, try to see what properties the BNode
> > itself has.
>
> I tried (last line in script). Nothin :-(
>
>  test_timbl.py
> < 1KViewDownload

Cosmin Basca

unread,
Mar 6, 2012, 12:52:08 PM3/6/12
to sur...@googlegroups.com
Hi Peteris, 

Thanks for clarifying the resource loading, I forgot to mention about it. 
@Eugene: If you want to always load everything every-time, set the session.auto_load property to True. Note: however that this may slow down your code depending on rdfstore / network conditions / data size and distribution. 

Cheers,
Cosmin

p.s.: the BNode address value needs to be loaded too, to access it's properties (unless auto_load is set)  

TI_Eugene

unread,
Mar 6, 2012, 1:48:26 PM3/6/12
to surfrdf
Great!
Very nice, thank you! :-)

Notes:
* autoload is not good solution. In list/detail solution (like PIM) I
can get foaf_something in list - and load all of resource in detail.
No prob.
* Next question - to get all _available_ attributes. Imagine Contact
(person) form in PIM on creation. I have no object (and attributes) -
but I have to give user to define all available attributes. So -
question - how to get all available attributes for (e.g.) FOAF.Person
(and its type, multiplicity etc).
* yet can't solve pim_office problem. Empty BNode :-(

On 6 мар, 20:05, "Eugene A. Pivnev" <ti.eug...@gmail.com> wrote:
> I attached test script for illustartion.
>
> On 06.03.2012 14:14, Cosmin Basca wrote:
>
>
>
>
>
>
>
> > Hi Eugene,
>
> > On Tuesday, March 6, 2012 8:18:24 AM UTC+1, TI_Eugene wrote:
>
> >     I'm novice in semaweb and trying to use surfrdf for handling data
> >     (contacts, tasks etc) in my django (?) project (against RDBS).
> >     Testing data - TimBL card (http://www.w3.org/People/Berners-Lee/
> >     card#i <http://www.w3.org/People/Berners-Lee/card#i>), via rdflib
> >     (rdflib_example.py).
> >     Questions are:
> >     1. Can I list all defined (in this card) FOAF attributes - or I have
> >     to try to get _each_ available in FOAF?
>
> > yes you can, there are several ways to do that
> > 1) use the python *dir* function, end enumerate over all properties
> > checking the ones that are in the foaf namespace
>
> Nothing interesting - just API attributes/methods.
>
> > 2) use the *rdf_direct* and *rdf_inverse* members where these
> > properties are stored
>
> rdfdirect returns same values (as dict values) as rdf_type.
> rdf_reverse returns nothing (sorry - empty dict)
>
> > 3) export the *graph()* of the resource and find all *FOAF* properties
>
> Maybe - this way?..
>
> > I think 2) is the way to go, but depends on your scenario
>
> >     2. Can't get office address. person.contact_office.first returns
> >     BNode
> >     - and that's all.
>
> > In Semantic Web, one can have nodes (objects or subjects) that do not
> > have a public identifier (like a URL) those are called blank nodes
> > (BNode in surf). A BNode has properties of it's own, so if you are
> > looking to get the address, try to see what properties the BNode
> > itself has.
>
> I tried (last line in script). Nothin :-(
>
>  test_timbl.py
> < 1KбПросмотретьЗагрузить

Eugene Pivnev

unread,
Mar 6, 2012, 1:58:37 PM3/6/12
to sur...@googlegroups.com
On 06.03.2012 21:52, Cosmin Basca wrote:
> Hi Peteris,
>
> Thanks for clarifying the resource loading, I forgot to mention about it.
> @Eugene: If you want to always load everything every-time, set the
> session.auto_load property to True. Note: however that this may slow
> down your code depending on rdfstore / network conditions / data size
> and distribution.
No, I prefere to load each resource on request.

> p.s.: the BNode address value needs to be loaded too, to access it's
> properties (unless auto_load is set)
But how?

Try to run attached script

test_timbl2.py

TI_Eugene

unread,
Mar 8, 2012, 9:26:54 AM3/8/12
to sur...@googlegroups.com
If yuo look inside http://www.w3.org/People/Berners-Lee/card.rdf you
can found <con:office rdf:parseType="Resource"> element.
It is mapping to pim_office - it's ok.
But it includes <con:address rdf:parseType="Resource"> element.
And I can't find any method to discover it.
pim_office has no attribute pim_addres or somethin like this.
And can't be load()ed.

2012/3/6 Cosmin Basca <cosmin...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages