2

Why does the following test produce an error? Does Redland's turtle parser insist on a base URI even if all actual URIs are absolute? (Apache Jena apparently does not.) And how could I find out more about what actually went wrong (i.e. what API call would return an error description, or similar)?

librdf_world *world = librdf_new_world();
librdf_world_open(world);

librdf_storage *storage = librdf_new_storage(world, "memory", NULL, NULL);
librdf_model   *model   = librdf_new_model(world, storage, NULL);

librdf_parser* parser = librdf_new_parser(world, NULL, "text/turtle", NULL);

librdf_uri *baseUri = NULL;

const char *turtle = "<http://example.com/SomeSubject> <http://example.com/SomePredicate> <http://example.com/SomeObject> .";

int error = librdf_parser_parse_string_into_model(parser, (const unsigned char *)turtle, baseUri, model);
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Drux
  • 11,992
  • 13
  • 66
  • 116
  • 1
    Jena will use a default base URI, internally chosen (based on the current directory if all else fails), if none is supplied. – AndyS Dec 29 '13 at 12:59
  • 1
    Have you tried adding an error handler with [librdf_parser_set_error()](http://librdf.org/docs/api/redland-parser.html#librdf-parser-set-error) and seeing what the error message says? – RobV Dec 29 '13 at 21:32
  • Documentation (where you link to) says: `Deprecated: Does nothing`. – Drux Dec 30 '13 at 08:20
  • @AndyS thx, that helps. Do you know if some specification insists on a base URI (even if all actual URIs are absolute such as in the cited example)? – Drux Dec 30 '13 at 08:28

1 Answers1

1

A base URI is required because the parser says so using RAPTOR_SYNTAX_NEED_BASE_URI flag. It produces the error before even looking at the content in raptor_parser_parse_start().

If you know a real base URI is not needed, you can supply a dummy URI such as . instead:

librdf_uri *baseUri = librdf_new_uri(world, (const unsigned char *)".");

To enable better error reports, you should register a logger with librdf_world_set_logger() - the default logger just spits to stderr. Return non-0 from the logger function to signal you handler the message yourself. Example:

#include <librdf.h>

int customlogger(void *user_data, librdf_log_message *message) {
  fputs("mad custom logger: ", stderr);
  fputs(message->message, stderr);
  fputs("\n", stderr);
  return 1;
}

int main() {

  librdf_world *world = librdf_new_world();
  librdf_world_set_logger(world, /*user_data=*/ 0, customlogger);
  librdf_world_open(world);

  librdf_storage *storage = librdf_new_storage(world, "memory", NULL, NULL);
  librdf_model   *model   = librdf_new_model(world, storage, NULL);

  librdf_parser* parser = librdf_new_parser(world, NULL, "text/turtle", NULL);

  librdf_uri *baseUri = NULL;

  const char *turtle = "<http://example.com/SomeSubject> <http://example.com/SomePredicate> <http://example.com/SomeObject> .";

  int error = librdf_parser_parse_string_into_model(parser, (const unsigned char *)turtle, baseUri, model);

}

Running this will result in

mad custom logger: Missing base URI for turtle parser

(For a real program, add some cleanup etc.)

laalto
  • 150,114
  • 66
  • 286
  • 303