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

Brian Holdsworth holdswob33 at yahoo.com
Mon Jan 17 06:55:39 PST 2005


Thanks for the advice.  Using some form of the
librdf_model_find_statements() would seem like a
reasonable thing to try.  However, one effect of this
is that I cannot control the order in which the
statements will be returned to me.  If I do this:

partial_statement=librdf_new_statement(world);
librdf_statement_set_subject(partial_statement,
subject);
librdf_model_find_statements(model,
partial_statement);

I am going to get a stream of triples, but they will
not be grouped together based on having the same uri
for their predicate.  Since my application is
attempting to group resources with their properties
(predicates), this is rather inconvenient.

The idea of doing "nested iterators" using
librdf_model_get_arcs_out() and
librdf_model_get_targets() also sounds like it would
work, but is also inconvenient from a coding
perspective.

I guess I am still hoping to find a simple way to do
this.  What is it about the arcs returned from
librdf_model_get_arcs_out() that prevents them from
being uniquely applied in librdf_model_get_target()? 
Is it just that arcs that have the same uri are
treated as the same arc, even though they clearly are
not?  What is it that makes nodes with the same uri
unique, but gets ignored (I think) when I pass the
node as the arc to librdf_model_get_target()?

Thanks,
Brian


--- Simon Cross <simon at sanbi.ac.za> 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
> 
> 



More information about the redland-dev mailing list