【问题标题】:Redland RDF libraries: why does parsing model from Turtle without base URI cause error?Redland RDF 库:为什么在没有基本 URI 的情况下从 Turtle 解析模型会导致错误?
【发布时间】:2013-12-28 20:19:13
【问题描述】:

为什么下面的测试会产生错误? Redland 的海龟解析器是否坚持使用基本 URI,即使所有实际 URI 都是绝对的? (Apache Jena 显然没有。)我怎样才能找到更多关于实际问题的信息(即,什么 API 调用会返回错误描述或类似内容)?

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);

【问题讨论】:

  • Jena 将使用内部选择的默认基本 URI(如果所有其他方法都失败,则基于当前目录),如果没有提供。
  • 您是否尝试过使用librdf_parser_set_error() 添加错误处理程序并查看错误消息的内容?
  • 文档(链接到的地方)说:Deprecated: Does nothing
  • @AndyS thx,这有帮助。您是否知道某些规范是否坚持使用基本 URI(即使所有实际 URI 都是绝对的,例如在引用的示例中)?

标签: c rdf jena turtle-rdf redland


【解决方案1】:

需要基本 URI,因为 parser says so using RAPTOR_SYNTAX_NEED_BASE_URI flag。它甚至在查看raptor_parser_parse_start() 中的内容之前就产生了错误。

如果您知道不需要真正的基本 URI,则可以提供一个虚拟 URI,例如 .

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

要启用更好的错误报告,您应该使用librdf_world_set_logger() 注册一个记录器 - 默认记录器只是向stderr 发送。从 logger 函数返回非 0 以表示您自己处理消息。示例:

#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);

}

运行这将导致

mad custom logger: Missing base URI for turtle parser

(对于真正的程序,添加一些清理等)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多