John Fieber wrote:
On May 6, 2008, at 5:23 AM, Michael Stahl wrote:

so i found another problem in librdf_stream_get_context... namely that it does not work with hashes storage.

Do you have a simple test case to illustrate this? I'm able to retrieve contexts in streams on hashes storage without trouble.

attached.
its output:
object: 298c8   context: 0

That said, I do have a different problem with iterator/stream map functions regarding contexts. The mapping function for an iterator has the signature (rdf_iterator.h):

typedef void* (*librdf_iterator_map_handler)(librdf_iterator *iterator, void *map_context, void *item);

The problem is the list of iterator methods you cannot call within the map function because they produce infinite recursion:

 librdf_iterator_have_elements
 librdf_iterator_end
 librdf_iterator_next
 librdf_iterator_get_object
 librdf_iterator_get_context
 librdf_iterator_get_key
 librdf_iterator_get_value

Clearly not all of those are necessary or even appropriate to use in a map callback since you are handed a pointer to the object, but getting the context is relevant, and the only way to get it is to violate encapsulation of the iterator. The stream methods exhibit the same behavior.

uhm, it is not legal to call librdf_stream_get_context in a stream map function?
i am doing this right now, and it seemed to work so far...
(of course, i would never expect _next to work)
but clearly it needs to be documented somewhere which ones supposedly work :)

Another bug that affects the iterator only is that the callback signature is

typedef void* (*librdf_iterator_map_handler)(librdf_iterator *iterator, void *map_context, void *item);

but it called with second two arguments swapped (rdf_iterator.c):

      /* apply the map to the element  */
      element=map->fn(iterator, element, map->context);

I'm guessing this is wrong since the argument order is consistent in three out of four cases: stream callback signature, stream callback call and iterator callback signature.

-john

ah, the famous type safety of C (or lack thereof)...

--
"A supercomputer is a device for converting a CPU-bound problem into
 an I/O bound problem." -- Ken Batcher


#include <librdf.h>

int main()
{
    librdf_world *pWorld = librdf_new_world();
    librdf_world_open(pWorld);
    librdf_storage *pStorage = librdf_new_storage(pWorld,
//        "memory", NULL, "contexts='yes'");
        "hashes", NULL, "contexts='yes',hash-type='memory'");
    librdf_model *pModel = librdf_new_model(pWorld, pStorage, NULL);
    librdf_node *pContext = librdf_new_node_from_uri_string(pWorld,
        (const unsigned char*) ("uri:context"));
    librdf_node *pFoo = librdf_new_node_from_uri_string(pWorld,
        (const unsigned char*) ("uri:foo"));
    librdf_node *pBar = librdf_new_node_from_uri_string(pWorld,
        (const unsigned char*) ("uri:bar"));
    librdf_node *pBaz = librdf_new_node_from_uri_string(pWorld,
        (const unsigned char*) ("uri:baz"));

    librdf_statement *pStatement =
        librdf_new_statement_from_nodes(pWorld, pFoo, pBar, pBaz);
    librdf_model_context_add_statement(pModel, pContext, pStatement);

    librdf_statement *pStatement2 =
        librdf_new_statement_from_nodes(pWorld, NULL, NULL, NULL);
    librdf_stream *pStream =
        librdf_model_find_statements_in_context(pModel, pStatement2, pContext);

    librdf_statement* pStmt = librdf_stream_get_object(pStream);
    librdf_node* pCtxt = librdf_stream_get_context(pStream);
    printf("object: %p\tcontext: %p\n", pStmt, pCtxt);

    return 0;
}

_______________________________________________
redland-dev mailing list
[email protected]
http://lists.librdf.org/mailman/listinfo/redland-dev

Reply via email to