On May 31, 2006, at 6:16 AM, Miles Waller wrote:

> Hi,
>
> I'm hoping someone can help with me with this question about rdflib.
> Apologies in advance as i'm new to rdflib
> (and to rdf a bit too) and this might be a newbie question.
>
> I have some code which I am using to construct an rdf sequence.  I  
> call
> 'addItemToSequence' several times
> to build up the sequence, having set up the graph elsewhere.
>
> ns_client_site1_url = "http://example.com/ns/client-site1#";
> ns_client_site1 = Namespace(ns_client_site1_url)
> site = ns_client_site1
>
> def addItemToSequence(source_id, target_id)
>     g.add( (site[source_uid], RDF.Seq, URIRef('children_of_%s' %
> source_uid) ) )
>     s = Seq( g, URIRef('children_of_%s' % source_uid) )
>     g.add( (URIRef('children_of_%s' % source_uid), RDF.li,
> site[target_uid]) )
>
> I get the following rdf out of it:
>
> <rdf:RDF
>   xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
>   <rdf:Description rdf:about="http://example.com/ns/client-site1#124";>
>     <rdf:Seq>
>       <rdf:Description rdf:about="children_of_124">
>         <rdf:li rdf:resource="http://example.com/ns/client- 
> site1#157"/>
>         <rdf:li rdf:resource="http://example.com/ns/client- 
> site1#151"/>
>
>       </rdf:Description>
>     </rdf:Seq>
>   </rdf:Description>
> </rdf:RDF>
>
> The intent is to produce the rdf required to describe a simple,
> hierarchical site map as used by a website,
> which i can then query.  In the example, the resources and
> target_uid/source_uid represent the unique ids
> of the pages that are related.
>
> Now, my questions are:
>
> - have i created a sequence correctly here?  i.e. am i _always_  
> going to
> get the items back in the same order, or
> do i just get them back in this order because of a quirk of
> python/rdflib.  i'm not sure how i can test
> that my sequence is preserving its order.  the main reason for doing
> this is to make sure i'm adding it properly.
> i was expecting the items in the sequence to have tags of rdf:_1,  
> rdf:_2
> etc.
>
> - when i add the sequence, it seems i have to give it a name
> (children_of_whatever).  yet i think i ought to
> be able to specify this as an empty/abstract node (sorry, not quite  
> sure
> of the terminology here) so I don't need to
> give it am rdf:description at all.  is this possible?  or am i
> misguided?!  if it's possible, how do i do it with
> rdflib.
>
> - finally, if i want to change the order of items in the sequence, how
> should this be done?  delete all the items
> and add them again in the right order?  do sequences provide any  
> help to
> 'promote' items at all?  should they?

In case it helps, off in one of my applications I've got the  
following bit of code for creating RDF Collections from a list of  
strings. If anyone wants to generalize the code and submit it in the  
form of a patch that'd be great. Else I'll look to do that this  
weekend. Think the only change needed is changing it to directly add  
the items from source (and not create a Literal from them). And a  
corresponding test case would be ideal.

def make_collection(source, type, context):
     items = list()
     for item in source:
         b = BNode()
         context.add((b, RDFS.label, Literal(item)))
         context.add((b, RDF.type, type))
         items.append(b)
     items.reverse()
     rest = RDF.nil
     for item in items:
         l = BNode()
         context.add((l, RDF.first, item))
         context.add((l, RDF.rest, rest))
         rest = l
     return l

There's an existing method Graph.items that yields the items in an  
RDF Collection.

> I hope the examples and questions are clear.  I've googled quite a lot
> and whilst rdf examples are easy to find,
> rdflib examples are not.  To that end, I'm happy to contribute a  
> test /
> example based on the outcome of this
> (or even some code!)

That'd be great. Especially in the area of examples and documentation.

> I am using rdflib 2.2.3, as i required python 2.3.5 compatibility.   
> I am
> using the rdflib.Graph.Graph class and not
> the sparql graph, if that is any help.

rdflib 2.3.x only has one maybe two small dependencies on Python 2.4  
and they should be easy to rewrite. IIRC, one of them is in  
rdflib.store.Sleepycat where it uses a generator expression. We  
should look to do this soon and perhaps lay down a new stable version  
of rdflib -- it's been a fairly long time since we've made any fixes  
to 2.2.x.

> rdflib looks really good.  is there any chance of getting the rdf and
> code for the recipe examples in too?  happy
> to hack about with it to get it into shape if it's useful.

I've actually just recently started hacking on some of the recipes  
related code again. If you like I can send you a pointer if you want  
to turn some of the bits into examples.

> thanks for your help,

Thank you and welcome.

Daniel

> miles
>
>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://rdflib.net/mailman/listinfo/dev

Daniel Krech, http://eikeon.com/



_______________________________________________
Dev mailing list
[email protected]
http://rdflib.net/mailman/listinfo/dev

Reply via email to