Skip to content

Commit fd5ee81

Browse files
committed
added a licence and updated the README.
1 parent 497bfe6 commit fd5ee81

4 files changed

Lines changed: 76 additions & 39 deletions

File tree

LICENCE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This code is copyrighted by [Ghent University - imec](https://www.ugent.be/ea/idlab/en)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a
4+
copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation
6+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
and/or sell copies of the Software, and to permit persons to whom the
8+
Software is furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Feather RDF Mapper
2+
3+
A simple mapper to map and convert .feather data files into RDF triples in a specified ontology, specifically in the N-Triples format.
4+
5+
## Usage
6+
7+
Note: It is highly advised to use a venv with the required packages installed, as described in the [requirements][./requirements.txt] file.
8+
9+
- Specify the name of the .feather file and the .nt file in the `mapper.py` file inside the mapper folder.
10+
- Run the file as a script with,
11+
```bash
12+
python3 mapper.py
13+
```
14+
- The .nt file will be created.
15+
16+
## License
17+
18+
This code is copyrighted by [Ghent University - imec](https://www.ugent.be/ea/idlab/en) and
19+
released under the [MIT Licence](./LICENCE)
20+
21+
## Contact
22+
23+
For any questions, please contact [Kush](mailto:kushagrasingh.bisen@ugent.be).

mapper/main.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

mapper/mapper.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def map_observation(metric_id,
8484
if metric_group == "CONTEXT":
8585
return OBSERVATION_TEMPLATE_CONTEXT_DAHCC % (uuid,
8686
uuid, source_id,
87-
uuid, metric_id,
87+
uuid, uuid, metric_id,
8888
uuid, str(timestamp_utc),
8989
uuid, value
9090
)
@@ -93,10 +93,18 @@ def map_observation(metric_id,
9393
# patient_id, metric_id, uuid,
9494
# metric_id, time_str, str(timestamp_utc), value_str)
9595
elif metric_group == "WEARABLE":
96-
return OBSERVATION_TEMPLATE_WEARABLE % (source_id,
97-
patient_id, metric_id, uuid,
98-
patient_id, metric_id, uuid,
99-
metric_id, time_str, str(timestamp_utc), value_str)
96+
return OBSERVATION_TEMPLATE_CONTEXT_DAHCC % (uuid,
97+
uuid, source_id,
98+
uuid, uuid, metric_id,
99+
uuid, str(timestamp_utc),
100+
uuid, value
101+
)
102+
103+
104+
# return OBSERVATION_TEMPLATE_WEARABLE % (source_id,
105+
# patient_id, metric_id, uuid,
106+
# patient_id, metric_id, uuid,
107+
# metric_id, time_str, str(timestamp_utc), value_str)
100108

101109

102110
def map_value(value, metric_id):
@@ -135,9 +143,10 @@ def update_source_id(source_id, metric_id):
135143
OBSERVATION_TEMPLATE_CONTEXT_DAHCC = """
136144
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <http://rdfs.org/ns/void#inDataset> <https://dahcc.idlab.ugent.be/Protego/_participant1> .
137145
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <https://saref.etsi.org/core/measurementMadeBy> <https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/%s> .
146+
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <http://purl.org/dc/terms/isVersionOf> <https://saref.etsi.org/core/Measurement> .
138147
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <https://saref.etsi.org/core/relatesToProperty> <https://dahcc.idlab.ugent.be/Homelab/SensorsAndActuators/%s> .
139148
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <https://saref.etsi.org/core/hasTimestamp> "%s"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
140-
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <https://saref.etsi.org/core/hasValue> "%s"^^<http://www.w3.org/2001/XMLSchema#boolean> .
149+
<https://dahcc.idlab.ugent.be/Protego/_participant1/obs%s> <https://saref.etsi.org/core/hasValue> "%s"^^<http://www.w3.org/2001/XMLSchema#float> .
141150
142151
"""
143152

@@ -283,7 +292,7 @@ def convert_timestamp_to_string(timestamp):
283292

284293

285294
def generate_uuid(metric_id, patient_id):
286-
key = '%s.%s' % (patient_id, metric_id)
295+
key = '%s' % (patient_id)
287296
if key not in uuid_map:
288297
uuid_map[key] = 0
289298
result = uuid_map[key]
@@ -297,21 +306,27 @@ def remove_whitespace(given_str):
297306

298307
# MAIN FUNCTION FOR TESTING PURPOSES
299308

300-
file = pandas.read_feather('../data/dataset_participant1.feather')
301-
metric = 'people.presence.detected'
309+
file = pandas.read_feather('data/dataset_participant3.feather')
310+
311+
heartRateSensor = ['wearable.bvp'];
312+
accelerationSensorNames = ['wearable.acceleration.x', 'wearable.acceleration.y', 'wearable.acceleration.z']
313+
314+
numberOfObservations = 500
302315

303-
# print(file.head())
304-
dataframe = file[file['Metric'] == 'people.presence.detected']
316+
dataframe_heart_rate = file[file['Metric'] == heartRateSensor[0]].head(numberOfObservations)
317+
dataframe_acc_x = file[file['Metric'] == accelerationSensorNames[0]].head(numberOfObservations)
318+
dataframe_acc_y = file[file['Metric'] == accelerationSensorNames[1]].head(numberOfObservations)
319+
dataframe_acc_z = file[file['Metric'] == accelerationSensorNames[2]].head(numberOfObservations)
320+
321+
dataframe_heart_rate_with_x = dataframe_heart_rate.append(dataframe_acc_x)
322+
dataframe_heart_rate_with_x_y = dataframe_heart_rate_with_x.append(dataframe_acc_y)
323+
dataframe = dataframe_heart_rate_with_x_y.append(dataframe_acc_z)
305324

306325
if __name__ == '__main__':
307326
for index in dataframe.index:
308327
source = dataframe['Sensor'][index]
309328
metricId = dataframe['Metric'][index]
310329
value = dataframe['Value'][index]
311-
if value == "1":
312-
newValue = "true"
313-
else:
314-
newValue = "false"
315330
datetimeValue = dataframe['Timestamp'][index]
316331
datetimeValueString = str(datetimeValue)
317332
valueOfHour = datetimeValueString[0:2]
@@ -321,7 +336,7 @@ def remove_whitespace(given_str):
321336
if (datetimeValueString[9:12] == ''):
322337
continue
323338
else:
324-
valueOfMiliSeconds = datetimeValueString[9:15]
339+
valueOfMiliSeconds = datetimeValueString[9:13]
325340

326341
currentDate = datetime.now()
327342
year = currentDate.strftime("%Y")
@@ -330,22 +345,19 @@ def remove_whitespace(given_str):
330345

331346
try:
332347
timeValue = str(year + '-' + month + '-' + day + 'T' + valueOfHour + ':' + valueOfMinute + ':' + valueOfSeconds + '.' + valueOfMiliSeconds)
333-
# epoch = datetime(year=year, month=month, day=day, hour=valueOfHour, minute=valueOfMinute,
334-
# second=valueOfSeconds, microsecond=valueOfMiliSeconds).strftime('%s')
335-
# timeValue = epoch
336348
except Exception as e:
337349
print(e)
338350
finally:
339351
print('Done')
340352

341353
json_event = {
342354
"sourceId": source,
343-
"metricId": "people.presence.detected",
344-
"value": newValue,
355+
"metricId": metricId,
356+
"value": value,
345357
"timestamp": timeValue
346358
}
347359
_result = annotate_event(json_event)
348-
with open('/home/kush/Code/feather-RDF-mapper/data/rdfData/dataset_participant1.nt', 'a') as file:
360+
with open('/home/kush/Code/feather-RDF-mapper/data/rdfData/dataset_participant3.nt', 'a') as file:
349361
pass
350362
file.write('\n')
351363
file.write(_result)

0 commit comments

Comments
 (0)