gpt4 book ai didi

c++ - librdf raptor 处理对象中的整数值

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:51:15 24 4
gpt4 key购买 nike

当 ntriple 的对象中有一个整数值时,我得到一个错误。如何直接获取整数值?而不是得到一个错误。谢谢。

详细信息:

  1. rdf 三元组

    <http://rdf.freebase.com/ns/g.124x8gtbc> <http://rdf.freebase.com/ns/measurement_unit.dated_percentage.rate> 1.27 .

  2. 代码

下面是我的代码。

void process_nt_file(string file_path, raptor_statement_handler pro_handler){
unsigned char *uri_string;
raptor_uri *uri, *base_uri;
raptor_parser *rdf_parser;

raptor_world *world = raptor_new_world();
rdf_parser = raptor_new_parser(world, "ntriples");
raptor_parser_set_statement_handler(rdf_parser, NULL, pro_handler);

uri_string = raptor_uri_filename_to_uri_string(file_path.c_str());
uri = raptor_new_uri(world, uri_string);
base_uri = raptor_uri_copy(uri);

time_t start_t, end_t;
time(&start_t);

raptor_parser_parse_file(rdf_parser, uri, base_uri);

time(&end_t);
double diff_time = difftime(end_t, start_t);
printf("Duration: %.2lf s", diff_time);

raptor_free_parser(rdf_parser);
}

最佳答案

问题是您的数据不是有效的 NTriples,所以 libraptor 拒绝它是完全正确的。您的数据片段正在使用称为纯文字的语法压缩,这在 NTriples 中无效。

这个压缩实际上来自Turtle格式(它是 NTriples 的超集),因此您需要将数据解析为 Turtle。

所以代替这一行:

rdf_parser = raptor_new_parser(world, "ntriples");

使用这一行:

rdf_parser = raptor_new_parser(world, "turtle");

请注意,Freebase 数据因包含大量无效数据而臭名昭著,因此即使进行了此更改,您仍可能会遇到错误。

关于c++ - librdf raptor 处理对象中的整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28379564/

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