为什么下面的测试会产生错误?即使所有实际URI都是绝对的,雷德兰的海龟解析器也坚持使用基URI吗?(阿帕奇·耶娜显然不是这样),我如何才能更多地了解到底出了什么问题(例如,哪个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);发布于 2014-01-08 12:55:31
需要一个基URI,因为标志。它甚至在查看raptor_parser_parse_start()中的内容之前就会产生错误。
如果您知道不需要真正的基本URI,则可以提供一个虚拟URI,例如.:
librdf_uri *baseUri = librdf_new_uri(world, (const unsigned char *)".");要启用更好的错误报告,您应该向librdf_world_set_logger()注册一个记录器--默认的记录器只需吐到stderr。从记录器函数中返回non-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(对于一个真正的程序,添加一些清理等等)
https://stackoverflow.com/questions/20818965
复制相似问题