gpt4 book ai didi

c - Redland RDF 库 : why does parsing model from Turtle without base URI cause error?

转载 作者:太空宇宙 更新时间:2023-11-03 23:50:29 25 4
gpt4 key购买 nike

为什么下面的测试会产生错误?是否Redland即使所有实际 URI 都是绝对的,'s turtle 解析器也坚持使用基本 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);

最佳答案

需要基本 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。从记录器函数返回非 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

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

关于c - Redland RDF 库 : why does parsing model from Turtle without base URI cause error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20818965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com