[redland-dev] Problem with 'librdf_model_get_arcs_in'
Maciej Janik
mjanik at uga.edu
Mon Mar 21 18:59:02 GMT 2005
Hi,
I try to get the whole neighborhood of a resources - all nodes
that it points to and is pointed by.
But 'librdf_model_get_arcs_in' do not return any results
(iterator is empty) and there is assertion error:
rdf_storage.c:847: (librdf_storage_node_stream_to_node_create)
assertion failed: object pointer of type librdf_node is NULL.
Call is:
iter = librdf_model_get_arcs_in(model, currNode);
where 'currNode' is a valid 'librdf_node*' that has some
incoming arcs. I use in-memory hashes model.
Am I using it incorrect or is it not supported by model or bug?
I attach short C program to illustrate the problem.
Thanks for any help.
Maciek
-------------- next part --------------
#include <stdio.h>
#include <redland.h>
#include <string.h>
int main(int argc, char *argv[])
{
if(argc < 3)
{
printf("Usage - loads RDF file to memory and prints neighborhood of given resource \n");
printf(" %s [rdf_filename] [resource_uri]\n", argv[0]);
return 0;
}
librdf_world* world;
librdf_storage *storage;
librdf_model* model;
librdf_node* arc;
librdf_node* tg;
librdf_node* currNode;
librdf_uri* uri;
librdf_parser* parser;
librdf_iterator* iter;
char* filename;
world=librdf_new_world();
librdf_world_open(world);
storage=librdf_new_storage(world, "hashes", NULL, "hash-type='memory'");
model=librdf_new_model(world, storage, NULL);
parser=librdf_new_parser(world,"rdfxml","application/rdf+xml",NULL);
int len = strlen(argv[1]);
filename = new char[len+6];
sprintf(filename, "file:%s", argv[1]);
printf("Loading RDF data from [%s] file\n", filename);
uri=librdf_new_uri(world, (const unsigned char*) filename);
librdf_parser_parse_into_model(parser,uri,uri,model);
printf("Load success!\n");
delete[] filename;
printf("Resource URI <%s>\n", argv[2]);
currNode = librdf_new_node_from_uri_string(world, (const unsigned char *) argv[2]);
/*
* OUTGOING ARCS - here works OK
*/
printf("Looking for outgoing arcs ...\n");
iter = librdf_model_get_arcs_out(model, currNode);
printf("Outgoing arcs OK\n");
while(!librdf_iterator_end(iter))
{
arc=(librdf_node*)librdf_iterator_get_object(iter);
librdf_node_print(arc, stdout);
printf(" -> ");
tg = librdf_model_get_target(model, currNode, arc);
librdf_node_print(tg, stdout);
printf("\n");
librdf_iterator_next(iter);
}
/*
* INCOMING ARCS - where the problem occurs ...
*/
printf("Looking for incoming arcs ...\n");
iter = librdf_model_get_arcs_in(model, currNode);
printf("Incoming arcs OK\n");
while(!librdf_iterator_end(iter))
{
arc=(librdf_node*)librdf_iterator_get_object(iter);
librdf_node_print(arc, stdout);
printf(" <- ");
tg = librdf_model_get_source(model, arc, currNode);
librdf_node_print(tg, stdout);
printf("\n");
librdf_iterator_next(iter);
}
return 0;
}
More information about the redland-dev
mailing list