I'm trying to map this JSON file to RDF, but I probably can not iterate correctly to get the values of "value", which are inside the measures array.
JSON:
{
"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:
@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;
];
].
Thanks for your help, Chiara
Adapting the JSON Path expression allows RML processors to retrieve the heart rate values. For both TriplesMaps I changed them to
$.body.measuregrps.[*]
which iterate over eachmeasuregrps
entry.I added
a rr:TriplesMap
for each TriplesMap to make sure that an RML processor knows that the RDF describes a TriplesMap:rr:joinCondition
which only joins the heart rate value with the right measurement whengrpid
values are equal:The new IRI format also supports other types of measurements besides the heart rate.
Mapping rules:
Output:
Note: I contribute to RML and its technologies.