[redland-dev] Problems traversing arcs with the same URI

Richard Newman r.newman at reading.ac.uk
Wed Jan 19 10:17:13 PST 2005


Rather than reply to a later message, I'll reply to this!

I've been doing a similar thing; the answer for me was to add each arc 
to a set (I'm using Cocoa, so I added my node class to an 
NSMutableSet), then iterate over that set calling get_targets.

Adding to a set ensures that each property only occurs once; I can then 
get all the targets for a property. This has the useful property of 
grouping that you require, though the ordering of the properties isn't 
actually guaranteed (though you could roll your own ordered set).

Essentially, I'm emulating a kind of 'get_unique_arcs' function by 
caching the results in a set.

-R

On Jan 17, 2005, at 13:52, Simon Cross wrote:

> Hi,
>
>> I am not sure if this is a limitation of the API, a
>> bug, or just a newbie mistake on my part.  I am trying
>> to traverse the model I have built, which contains
>> nodes that have multiple arcs leaving them with the
>> same uri.  Here are the steps I currently do:
>>
>> 1.  librdf_model_get_arcs_out(model, subject): Create
>> a librdf_iterator that will give me all the arcs
>> leaving this resource/node identified by 'subject.'
>>
>> 2.  arc = librdf_iterator_get_object(itereator):
>> Returns each indiviual arc from the iterator.  If the
>> node has 4 arcs leaving, all with the same uri, then
>> this function seems to return all 4 of them uniquely
>> (using calls to librdf_iterator_next() in between).
>>
>> 3.  target = librdf_model_get_target(model, subject,
>> arc): I use the arc returned above to try to get the
>> individual targets of the 4 arcs. *This is where I
>> have the problem*  For some reason, this function
>> returns THE SAME TARGET node all 4 times I call it.
>
> My guess is that arc is a simple URI.  Thus librdf_model_get_target has
> no way of identifying which of the four arcs you are referring to 
> (since
> it sees only the subject and arc URIs).
>
> librdf_model_get_targets would presumably list all of the target URIs
> (in an iterator) but then you'd have to worry about duplicating targets
> if you ran through all the results from librdf_model_get_arcs_out.
>
> Maybe you can use librdf_model_find_statements_with_options to select
> all the statements which have a particular subject?  Or perhaps an RDQL
> or SPARQL query would suit your needs better?
>
> Schiavo
> Simon
>
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.gnomehack.com/mailman/listinfo/redland-dev
>



More information about the redland-dev mailing list