RML Mapping问题:如何使用RML Mapper映射owl:Restriction?
RML映射生成OWL Restriction结构的实现方案
之前的两个尝试均不符合RML语法规范:
- rr:class字段仅支持传入IRI值,不允许嵌套predicateObjectMap结构,所以第一个方案会触发IRI格式错误
- 第二个方案将RDF结构作为字符串模板传入,且指定了termType为
rr:Literal,所以输出结果会被识别为字面量,不符合RDF结构要求
RML Mapper本身支持生成匿名空白节点结构,你可以通过两个TriplesMap关联的方式实现目标结构,完整映射文件示例如下:
@prefix rr: <http://www.w3.org/ns/r2rml#> . @prefix rml: <http://semweb.mmlab.be/ns/rml#> . @prefix ql: <http://semweb.mmlab.be/ns/ql#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ns: <http://example.org/> . <#RestrictionMap> rdf:type rr:TriplesMap; rml:logicalSource [ rml:source "myJSON.json"; rml:referenceFormulation ql:JSONPath; rml:iterator "$.myIterator[*]" ]; rr:subjectMap [ rr:template "http://example.org/{Id}" ; rr:class owl:NamedIndividual ]; # 关联OWL Restriction空白节点 rr:predicateObjectMap [ rr:predicate rdf:type ; rr:objectMap [ rr:parentTriplesMap <#RestrictionBNodeMap> ; rr:joinCondition [ rr:child "Id" ; rr:parent "Id" ; ] ] ] ; # 映射rdfs:label,可根据实际JSON字段调整reference值 rr:predicateObjectMap [ rr:predicate rdfs:label ; rr:objectMap [ rr:reference "label" ] ] . # 单独的TriplesMap生成OWL Restriction匿名节点 <#RestrictionBNodeMap> rdf:type rr:TriplesMap ; rml:logicalSource [ rml:source "myJSON.json"; rml:referenceFormulation ql:JSONPath; rml:iterator "$.myIterator[*]" ]; # 不指定subject的template,自动生成空白节点 rr:subjectMap [ rr:class owl:Restriction ; ] ; # 映射owl:onProperty固定值 rr:predicateObjectMap [ rr:predicate owl:onProperty ; rr:objectMap [ rr:constant ns:myProperty ; rr:termType rr:IRI ] ] ; # 映射owl:allValuesFrom,取JSON中的AnotherResource字段 rr:predicateObjectMap [ rr:predicate owl:allValuesFrom ; rr:objectMap [ rr:template "http://example.org/{AnotherResource}" ; rr:termType rr:IRI ] ] .
核心配置说明:
- 新增的
<#RestrictionBNodeMap>专门用来生成OWL Restriction结构,其subjectMap未指定固定IRI,RML Mapper会自动生成匿名空白节点,正好匹配目标结构中的[]语法 - 原映射中新增关联
<#RestrictionBNodeMap>的predicateObjectMap,通过Id字段做关联,保证每个资源实例对应专属的Restriction结构 - 固定的属性值可以用
rr:constant直接指定,比模板写法更简洁规范
内容的提问来源于stack exchange,提问作者airkangoo
相关产品推荐
相关产品推荐

