[redland-dev] retrieve arc/target/source question
Dave Beckett
dave.beckett at bristol.ac.uk
Tue Oct 19 10:25:43 BST 2004
On Tue, 19 Oct 2004 14:57:20 +1300, Rodney Tamblyn <rodney at stonebow.otago.ac.nz> wrote:
> Hello everyone,
>
> If I want to retrieve all source statements for a given arc in a model,
> can I call:
> librdf_model_get_source()
> ... passing arc and an empty target?
>
> I.e. is it acceptable to only define one of the two params for
> model_get_arcs/model_get_sources etc
>
> If not, suggestions on best way to do this would be appreciated.
If I understand what you are saying, you want to retrieve statements
(RDF triples) with some property arc.
Since you want statement results, you should be using
librdf_model_find_statements to find matching statements (the
get_source/get_arc etc. methods return nodes or lists of nodes not
statements).
Pass in a statement to match with the property of the statement set
to the URI you are looking for.
Like this (not tested) search for dc:creator
partial_statement=librdf_new_statement(world);
librdf_statement_set_predicate(partial_statement, librdf_new_node_from_uri_string(world, (const unsigned char*)"http://purl.org/dc/elements/1.1/creator"));
/* search for the statements matching ?->dc:creator-> */
stream=librdf_model_find_statements(model, partial_statement)
while(!librdf_stream_end(stream)) {
librdf_statement *statement=librdf_stream_get_object(stream);
/* do something with the result */
librdf_stream_next(stream);
}
librdf_free_stream(stream);
This is mostly taken from the example1.c C source in the example dir
of redland's release.
Dave
More information about the redland-dev
mailing list