首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redland库:为什么没有基本URI的Turtle解析模型会导致错误?

Redland库:为什么没有基本URI的Turtle解析模型会导致错误?
EN

Stack Overflow用户
提问于 2013-12-28 20:19:13
回答 1查看 320关注 0票数 2

为什么下面的测试会产生错误?即使所有实际URI都是绝对的,雷德兰的海龟解析器也坚持使用基URI吗?(阿帕奇·耶娜显然不是这样),我如何才能更多地了解到底出了什么问题(例如,哪个API调用会返回错误描述,或者类似的)?

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-08 12:55:31

需要一个基URI,因为标志。它甚至在查看raptor_parser_parse_start()中的内容之前就会产生错误。

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

代码语言:javascript
复制
librdf_uri *baseUri = librdf_new_uri(world, (const unsigned char *)".");

要启用更好的错误报告,您应该向librdf_world_set_logger()注册一个记录器--默认的记录器只需吐到stderr。从记录器函数中返回non-0,以指示您自己处理消息。示例:

代码语言:javascript
复制
#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);

}

运行这将导致

代码语言:javascript
复制
mad custom logger: Missing base URI for turtle parser

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20818965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档