- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 Raptor RDF Parser Toolkit 编写 C/C++ 程序生成以下输出(使用 RDF Validator 检查):
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person xml:lang="en">
<foaf:name>Jimmy Wales</foaf:name>
<foaf:mbox rdf:resource="mailto:jwales@bomis.com"/>
<foaf:nick>Jimbo</foaf:nick>
<!-- photo -->
<foaf:depiction
rdf:resource="http://upload.wikimedia.org/wikipedia/commons/1/19/Jimbo_Wales_in_France_cropped.jpg" />
</foaf:Person>
</rdf:RDF>
数据模型的三元组如下所示:
Number Subject Predicate Object
1 genid:A4486 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://xmlns.com/foaf/0.1/Person
2 genid:A4486 http://xmlns.com/foaf/0.1/name "Jimmy Wales"@en
3 genid:A4486 http://xmlns.com/foaf/0.1/mbox mailto:jwales@bomis.com
4 genid:A4486 http://xmlns.com/foaf/0.1/nick "Jimbo"@en
5 genid:A4486 http://xmlns.com/foaf/0.1/depiction http://upload.wikimedia.org/wikipedia/commons/1/19/Jimbo_Wales_in_France_cropped.jpg
仅作记录,我使用的是 Visual Studio 2017 x64 .我想出了以下代码:
#include "raptor2/raptor2.h"
int main(int argc, char* argv[]) {
FILE* outfile = fopen("myTestfile.rdf", "w");
raptor_world* world = raptor_new_world();
rdf_serializer = raptor_new_serializer(world, "rdfxml" /* "turtle" */);
raptor_serializer_start_to_file_handle(rdf_serializer, nullptr, outfile);
const unsigned char* prefix = (const unsigned char*)"foaf";
raptor_uri* uri = raptor_new_uri(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/");
raptor_serializer_set_namespace(rdf_serializer, uri, prefix);
{
raptor_statement* triple = nullptr;
triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_uri_string(world, (const unsigned char*)"genid:A4486");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
triple->object = raptor_new_term_from_literal(world, (unsigned char*)"http://xmlns.com/foaf/0.1/Person", nullptr, nullptr);
raptor_serializer_serialize_statement(rdf_serializer, triple);
raptor_free_statement(triple);
}
{
raptor_statement* triple = nullptr;
triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/Person");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/name");
triple->object = raptor_new_term_from_literal(world, (unsigned char*)"Jimmy Wales", nullptr, nullptr);
raptor_serializer_serialize_statement(rdf_serializer, triple);
raptor_free_statement(triple);
}
{
raptor_statement* triple = nullptr;
triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/Person");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/mbox");
triple->object = raptor_new_term_from_literal(world, (unsigned char*)"mailto:jwales@bomis.com", nullptr, nullptr);
raptor_serializer_serialize_statement(rdf_serializer, triple);
raptor_free_statement(triple);
}
raptor_serializer_serialize_end(rdf_serializer);
raptor_free_serializer(rdf_serializer);
raptor_free_world(world);
fclose(outfile);
}
生成的文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="genid:A4486">
<rdf:type>http://xmlns.com/foaf/0.1/Person</rdf:type>
</rdf:Description>
<rdf:Description rdf:about="http://xmlns.com/foaf/0.1/Person">
<foaf:name>Jimmy Wales</foaf:name>
</rdf:Description>
<rdf:Description rdf:about="http://xmlns.com/foaf/0.1/Person">
<foaf:mbox>mailto:jwales@bomis.com</foaf:mbox>
</rdf:Description>
</rdf:RDF>
我在这里做错了什么?我想产生与上图相同的结果。而不是 <foaf:Person>
标记一个 <rdf:Description>
标记已创建。
Turtle 输出 ( raptor_new_serializer(world, "turtle")
) 如下所示:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<genid:A4486>
a "http://xmlns.com/foaf/0.1/Person" .
foaf:Person
foaf:mbox "mailto:jwales@bomis.com" ;
foaf:name "Jimmy Wales" .
最佳答案
您的代码中存在三个问题。
你混淆了不同种类的 RDF terms :
为了输出typed nodes ,您应该使用 rdfxml-abbrev
序列化(第 7 行)。
您混淆了哪些事物以何种方式相连(第 29、40 行):
此代码运行良好:
#include <stdio.h>
#include <raptor/raptor2.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
raptor_world *world = NULL;
raptor_serializer* rdf_serializer = NULL;
unsigned char *uri_string;
raptor_uri *base_uri;
raptor_statement* triple;
world = raptor_new_world();
uri_string = raptor_uri_filename_to_uri_string(argv[1]);
base_uri = raptor_new_uri(world, uri_string);
rdf_serializer = raptor_new_serializer(world, "rdfxml-abbrev");
raptor_serializer_start_to_file_handle(rdf_serializer, base_uri, stdout);
const unsigned char* foaf_prefix = (const unsigned char*)"foaf";
raptor_uri* foaf_uri = raptor_new_uri(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/");
raptor_serializer_set_namespace(rdf_serializer, foaf_uri, foaf_prefix);
const unsigned char* rdf_prefix = (const unsigned char*)"rdf";
raptor_uri* rdf_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
raptor_serializer_set_namespace(rdf_serializer, rdf_uri, rdf_prefix);
{
raptor_statement* triple = NULL; triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_blank(world, (const unsigned char*)"b1");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/name");
triple->object = raptor_new_term_from_literal(world, (unsigned char*)"Jimmy Wales", NULL, NULL);
raptor_serializer_serialize_statement(rdf_serializer, triple); raptor_free_statement(triple);
}
{
raptor_statement* triple = NULL; triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_blank(world, (const unsigned char*)"b1");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://xmlns.com/foaf/0.1/mbox");
triple->object = raptor_new_term_from_uri_string(world, (unsigned char*)"mailto:jwales@bomis.com");
raptor_serializer_serialize_statement(rdf_serializer, triple); raptor_free_statement(triple);
}
{
raptor_statement* triple = NULL; triple = raptor_new_statement(world);
triple->subject = raptor_new_term_from_blank (world, (const unsigned char*)"b1");
triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
triple->object = raptor_new_term_from_uri_string(world, (unsigned char*)"http://xmlns.com/foaf/0.1/Person");
raptor_serializer_serialize_statement(rdf_serializer, triple); raptor_free_statement(triple);
}
raptor_serializer_serialize_end(rdf_serializer);
raptor_free_serializer(rdf_serializer);
raptor_free_uri(base_uri);
raptor_free_memory(uri_string);
raptor_free_world(world);
return 0;
}
输出是:
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<foaf:Person>
<foaf:mbox rdf:resource="mailto:jwales@bomis.com"/>
<foaf:name>Jimmy Wales</foaf:name>
</foaf:Person>
</rdf:RDF>
关于c++ - 使用 Raptor RDF Parser Toolkit 生成 FOAF rdfxml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48387060/
我编写了一个 Java 程序,它从 .csv 中获取数据,并将这些数据转换为 RDFXML。我用过sesame's编写此程序时的框架,并且该程序成功地完成了其编写的任务。 但是,我正在尝试使用 jUn
我一直在尝试使用 raptor2 C 库解析一些 RDF/XML 文件。此示例代码将读取 NTriples 文件并打印它,但不会读取 RDF/XML。 来自 the raptor tutorial :
所以我有一个如下所示的 Notation3 文件: @prefix wn: . @prefix lemon: . @prefix lexinfo: . :lexicon a lemon:Lexi
我想使用 Raptor RDF Parser Toolkit 编写 C/C++ 程序生成以下输出(使用 RDF Validator 检查): Jimmy Wales
我是 RDF 的新手,但以下内容似乎很简单;我只是没有得到我期望的结果。我有一个 RDF/XML 文件如下(它在 W3C 验证器中验证):
我正在尝试读取 rdf/xml 文件并可能以 JSON 或 JavaScript 对象或任何其他格式解析它。我尝试搜索很多 Node 库,但找不到任何好的示例。所有这些都提供了一些没有适当文档的API
我是一名优秀的程序员,十分优秀!