您也可以使用RML从现有数据源构建知识图
。RML 代表 RDF 映射语言,允许您将异构数据源转换为 RDF 并扩展R2RML。我创建了一个使用 JSON 数据作为数据源的示例,但也可以使用其他格式,例如 CSV、XML、关系数据库等。
RML(RDF 映射语言)
将现有数据源转换为 RDF 遵循 RML:
- 编写 RML 映射规则,指示 RML 处理器如何将数据转换为 RDF。您可以在RML 文档中找到许多如何为数据源编写映射规则的示例。
RML 规则由Triples Maps组成,
它们本身又包含以下部分:
逻辑源
rml:logicalSource [
rml:source "people.json" ;
rml:referenceFormulation ql:JSONPath ;
rml:iterator "$.people.[*]" ;
] ;
people.json使用定义为的 JSONPath 表达式访问
数据源$.people.[*]。该表达式允许 RML 处理器迭代 JSON 数据。
主题图
rr:subjectMap [
rr:template "http://ex.com/Person/{firstname}_{lastname}" ;
rr:class foaf:Person ;
] ;
此 SubjectMap 创建的每个主题都将看起来像
http://ex.com/Person/{firstname}_{lastname}wherefirstname并lastname
在 RML 处理器执行期间被相应的 JSON 值替换。科目有班foaf:Person。
谓词-对象映射
rr:predicateObjectMap [
rr:predicate foaf:givenName ;
rr:objectMap [
rml:reference "firstname" ;
]
] ;
此映射生成一个谓词,对象将在映射过程中foaf:givenName接收 JSON 值。firstname
- 使用 RML 处理器执行您的映射规则。RML 处理器的一个示例是
RML Mapper或
RML Streamer。也可以使用其他 RML 处理器,只要它们符合
RML 规范。
RML 处理器将根据前面显示的映射规则从 JSON 数据生成以下三元组:
<http://ex.com/Person/John_Doe> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>.
<http://ex.com/Person/John_Doe> <http://xmlns.com/foaf/0.1/givenName> "John".
<http://ex.com/Person/John_Doe> <http://xmlns.com/foaf/0.1/familyName> "Doe".
<http://ex.com/Person/Jane_Smith> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>.
<http://ex.com/Person/Jane_Smith> <http://xmlns.com/foaf/0.1/givenName> "Jane".
<http://ex.com/Person/Jane_Smith> <http://xmlns.com/foaf/0.1/familyName> "Smith".
<http://ex.com/Person/Sarah_Bladinck> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person>.
<http://ex.com/Person/Sarah_Bladinck> <http://xmlns.com/foaf/0.1/givenName> "Sarah".
<http://ex.com/Person/Sarah_Bladinck> <http://xmlns.com/foaf/0.1/familyName> "Bladinck".
完整示例
我创建了一个小演示来创建一个带有名字和姓氏的 FOAF 人:
RML 映射规则
@base <http://example.com> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#PersonMapping>
a rr:TriplesMap ;
rml:logicalSource [
rml:source "people.json" ;
rml:referenceFormulation ql:JSONPath ;
rml:iterator "$.people.[*]" ;
] ;
rr:subjectMap [
rr:template "http://ex.com/Person/{firstname}_{lastname}" ;
rr:class foaf:Person ;
] ;
rr:predicateObjectMap [
rr:predicate foaf:givenName ;
rr:objectMap [
rml:reference "firstname" ;
]
] ;
rr:predicateObjectMap [
rr:predicate foaf:familyName ;
rr:objectMap [
rml:reference "lastname" ;
]
] .
JSON数据
{
"people": [
{
"firstname": "John",
"lastname": "Doe"
},
{
"firstname": "Jane",
"lastname": "Smith"
},
{
"firstname": "Sarah",
"lastname": "Bladinck"
}
]
}
注意:我为 RML 及其技术做出了贡献。