首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >json中数组的数组的RML映射器

json中数组的数组的RML映射器
EN

Stack Overflow用户
提问于 2018-06-14 21:12:43
回答 1查看 289关注 0票数 1

我正在尝试将这个JSON文件映射到RDF,但是我可能不能正确地迭代以获得“​​”的值,它位于度量数组中。

JSON:

代码语言:javascript
复制
{
    "status": 0,
    "body": {
        "updatetime": 1528904042,
        "timezone": "Europe\/Rome",
        "measuregrps": [{
                "grpid": 1154218424,
                "attrib": 2,
                "date": 1528902698,
                "category": 1,
                "brand": 1,
                "modified": 1528902700,
                "deviceid": null,
                "measures": [{
                    "value": 7000,
                    "type": 11,
                    "unit": -2,
                    "algo": 0,
                    "fw": 0,
                    "fm": 131
                }]
            },
            {
                "grpid": 1154218987,
                "attrib": 2,
                "date": 1528902745,
                "category": 1,
                "brand": 1,
                "modified": 1528902747,
                "deviceid": null,
                "measures": [{
                    "value": 7200,
                    "type": 11,
                    "unit": -2,
                    "algo": 0,
                    "fw": 0,
                    "fm": 131
                }]
            }
        ]
    }
}

RML:

代码语言:javascript
复制
@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 xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix fo: <http://purl.org/ifo/#>.

###### Fitbit MAPPING #######


<#FitbitRestingHeartRate>

rml:logicalSource [
    rml:source "provaJson.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$.body.measuregrps";
];

rr:subjectMap [
    rr:template "http://ifo.com/{grpid}";
    rr:class fo:HeartRate;
];

rr:predicateObjectMap [
    rr:predicate fo:hasTemporalRelationshipToPhysicalActivity;
    rr:objectMap [
        rr:constant fo:AtRest;
    ];
];

rr:predicateObjectMap [
    rr:predicate fo:hasMeasure;
    rr:objectMap [ 
        rr:parentTriplesMap <#MeasureHeartRate>;
    ];
].



<#MeasureHeartRate>

rml:logicalSource [
    rml:source "provaJson.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$.body.measuregrps";
];

rr:subjectMap [
    rr:template "http://ifo.com/{grpid}"; 
    rr:class fo:Measure;
    rml:iterator "$.body.measuregrps";

];

rr:predicateObjectMap [
    rr:predicate fo:hasNumericalValue;
    rr:objectMap [
        rml:reference "@.measures.value";
        rr:datatype xsd:float;
    ];
];

rr:predicateObjectMap [
    rr:predicate fo:hasDescriptiveStatistic;
    rr:objectMap [
        rr:constant fo:average;
    ];
];

rr:predicateObjectMap [
    rr:predicate fo:hasUnit;
    rr:objectMap [
        rr:constant fo:bpm;
    ];
].

谢谢你的帮助,Chiara

EN

回答 1

Stack Overflow用户

发布于 2020-05-12 14:17:06

采用JSON路径表达式的

  1. 允许retrieve检索心率值。对于这两个TriplesMaps,我将它们更改为$.body.measuregrps.[*],这将遍历每个measuregrps条目。
  2. 我为每个TriplesMap添加了a rr:TriplesMap,以确保RML处理器知道RDF描述了一个TriplesMap:

代码语言:javascript
复制
<#MeasureHeartRate>
    a rr:TriplesMap;

  1. 与每个测量值匹配的所有心率值。我添加了一个rr:joinCondition,当grpid值相等时,它只将心率值与正确的测量值连接起来:

代码语言:javascript
复制
rr:predicateObjectMap [
    rr:predicate fo:hasMeasure;
    rr:objectMap [ 
        rr:parentTriplesMap <#MeasureHeartRate>;
        rr:joinCondition [
            rr:child "grpid";
            rr:parent "grpid";
        ];
    ];
].

  1. I更改了心率测量映射的IRI,因为IRI不是唯一的,这导致了一个循环:

代码语言:javascript
复制
<http://ifo.com/1154218987> <http://purl.org/ifo/#hasMeasure> <http://ifo.com/1154218987>

除了心率之外,新的IRI格式还支持其他类型的测量。

映射规则

代码语言:javascript
复制
@base <http://example.org> .
@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 xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix fo: <http://purl.org/ifo/#> .

<#FitbitRestingHeartRate>
    a rr:TriplesMap;
    rml:logicalSource [
        rml:source "provaJson.json";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$.body.measuregrps.[*]";
    ];

    rr:subjectMap [
        rr:template "http://ifo.com/{grpid}";
        rr:class fo:HeartRate;
    ];

    rr:predicateObjectMap [
        rr:predicate fo:hasTemporalRelationshipToPhysicalActivity;
        rr:objectMap [
            rr:constant fo:AtRest;
        ];
    ];

    rr:predicateObjectMap [
        rr:predicate fo:hasMeasure;
        rr:objectMap [ 
            rr:parentTriplesMap <#MeasureHeartRate>;
            rr:joinCondition [
                rr:child "grpid";
                rr:parent "grpid";
            ];
        ];
    ].

<#MeasureHeartRate>
    a rr:TriplesMap;
    rml:logicalSource [
        rml:source "provaJson.json";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$.body.measuregrps.[*]";
    ];

    rr:subjectMap [
        rr:template "http://ifo.com/{grpid}/{date}/{measures.[*].type}"; 
        rr:class fo:Measure;
    ];

    rr:predicateObjectMap [
        rr:predicate fo:hasNumericalValue;
        rr:objectMap [
            rml:reference "measures.[*].value";
            rr:datatype xsd:float;
        ];
    ];

    rr:predicateObjectMap [
        rr:predicate fo:hasDescriptiveStatistic;
        rr:objectMap [
            rr:constant fo:average;
        ];
    ];

    rr:predicateObjectMap [
        rr:predicate fo:hasUnit;
        rr:objectMap [
            rr:constant fo:bpm;
        ];
    ].

输出

代码语言:javascript
复制
<http://ifo.com/1154218424> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ifo/#HeartRate>.
<http://ifo.com/1154218424> <http://purl.org/ifo/#hasTemporalRelationshipToPhysicalActivity> <http://purl.org/ifo/#AtRest>.
<http://ifo.com/1154218424> <http://purl.org/ifo/#hasMeasure> <http://ifo.com/1154218424/1528902698/11>.
<http://ifo.com/1154218987> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ifo/#HeartRate>.
<http://ifo.com/1154218987> <http://purl.org/ifo/#hasTemporalRelationshipToPhysicalActivity> <http://purl.org/ifo/#AtRest>.
<http://ifo.com/1154218987> <http://purl.org/ifo/#hasMeasure> <http://ifo.com/1154218987/1528902745/11>.
<http://ifo.com/1154218424/1528902698/11> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ifo/#Measure>.
<http://ifo.com/1154218424/1528902698/11> <http://purl.org/ifo/#hasNumericalValue> "7000"^^<http://www.w3.org/2001/XMLSchema#float>.
<http://ifo.com/1154218424/1528902698/11> <http://purl.org/ifo/#hasDescriptiveStatistic> <http://purl.org/ifo/#average>.
<http://ifo.com/1154218424/1528902698/11> <http://purl.org/ifo/#hasUnit> <http://purl.org/ifo/#bpm>.
<http://ifo.com/1154218987/1528902745/11> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ifo/#Measure>.
<http://ifo.com/1154218987/1528902745/11> <http://purl.org/ifo/#hasNumericalValue> "7200"^^<http://www.w3.org/2001/XMLSchema#float>.
<http://ifo.com/1154218987/1528902745/11> <http://purl.org/ifo/#hasDescriptiveStatistic> <http://purl.org/ifo/#average>.
<http://ifo.com/1154218987/1528902745/11> <http://purl.org/ifo/#hasUnit> <http://purl.org/ifo/#bpm>.

RML :我为及其技术做出了贡献。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50858420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档