diff --git a/examples/fiware/kgcp/rml/brick/fiware_hotel_rml.ttl b/examples/fiware/kgcp/rml/brick/fiware_hotel_rml.ttl index 0070fd0..da1cd42 100644 --- a/examples/fiware/kgcp/rml/brick/fiware_hotel_rml.ttl +++ b/examples/fiware/kgcp/rml/brick/fiware_hotel_rml.ttl @@ -2,10 +2,6 @@ @prefix rml: . @prefix ql: . @prefix ex: . -@prefix xml: . -@prefix rdf: . -@prefix rdfs: . -@prefix xsd: . @prefix bacnet: . @prefix brick: . @prefix bsh: . @@ -13,6 +9,8 @@ @prefix owl: . @prefix qudt: . @prefix qudtqk: . +@prefix rdf: . +@prefix rdfs: . @prefix rec: . @prefix ref: . @prefix s223: . @@ -23,39 +21,26 @@ @prefix tag: . @prefix unit: . @prefix vcard: . +@prefix xsd: . -# Mapping for Hotel -ex:MappingHotel - a rr:TriplesMap ; - rml:logicalSource [ - rml:source "placeholder.json" ; - rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="Hotel")]' ; - ] ; - rr:subjectMap [ - rr:template "http://example.com/Hotel/{id}" ; - rr:class rec:Building ; - ] ; - . - -# Mapping for AmbientTemperatureSensor -ex:MappingAmbientTemperatureSensor +# Mapping for airFlowSetpoint_FreshAirVentilation +ex:MappingairFlowSetpoint_FreshAirVentilation a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="AmbientTemperatureSensor")]' ; + rml:iterator '$[?(@.type=="FreshAirVentilation" && @..airFlowSetpoint)]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/AmbientTemperatureSensor/{id}" ; - rr:class brick:Outside_Air_Temperature_Sensor ; + rr:template "http://example.com/airFlowSetpoint_FreshAirVentilation/{id}" ; + rr:class brick:Air_Flow_Setpoint ; ] ; rr:predicateObjectMap [ rr:predicate brick:isPointOf ; rr:objectMap [ - rr:parentTriplesMap ex:MappingHotel ; + rr:parentTriplesMap ex:MappingFreshAirVentilation ; rr:joinCondition [ - rr:child "hasLocation.value" ; + rr:child "id" ; rr:parent "id" ; ] ; ] ; @@ -63,25 +48,25 @@ ex:MappingAmbientTemperatureSensor rr:predicateObjectMap [ rr:predicate rdf:value ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/temperatureAmb/value" ; + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/airFlowSetpoint/value" ; ] ; ] ; . -# Mapping for HotelRoom -ex:MappingHotelRoom +# Mapping for AmbientTemperatureSensor +ex:MappingAmbientTemperatureSensor a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="HotelRoom")]' ; + rml:iterator '$[?(@.type=="AmbientTemperatureSensor")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/HotelRoom/{id}" ; - rr:class rec:Room ; + rr:template "http://example.com/AmbientTemperatureSensor/{id}" ; + rr:class brick:Outside_Air_Temperature_Sensor ; ] ; rr:predicateObjectMap [ - rr:predicate brick:hasLocation ; + rr:predicate brick:isPointOf ; rr:objectMap [ rr:parentTriplesMap ex:MappingHotel ; rr:joinCondition [ @@ -90,19 +75,25 @@ ex:MappingHotelRoom ] ; ] ; ] ; + rr:predicateObjectMap [ + rr:predicate rdf:value ; + rr:objectMap [ + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/temperatureAmb/value" ; + ] ; + ] ; . -# Mapping for TemperatureSensor -ex:MappingTemperatureSensor +# Mapping for CO2Sensor +ex:MappingCO2Sensor a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="TemperatureSensor")]' ; + rml:iterator '$[?(@.type=="CO2Sensor")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/TemperatureSensor/{id}" ; - rr:class brick:Air_Temperature_Sensor ; + rr:template "http://example.com/CO2Sensor/{id}" ; + rr:class brick:CO2_Sensor ; ] ; rr:predicateObjectMap [ rr:predicate brick:isPointOf ; @@ -117,25 +108,25 @@ ex:MappingTemperatureSensor rr:predicateObjectMap [ rr:predicate rdf:value ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/temperature/value" ; + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/co2/value" ; ] ; ] ; . -# Mapping for CO2Sensor -ex:MappingCO2Sensor +# Mapping for CoolingCoil +ex:MappingCoolingCoil a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="CO2Sensor")]' ; + rml:iterator '$[?(@.type=="CoolingCoil")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/CO2Sensor/{id}" ; - rr:class brick:CO2_Sensor ; + rr:template "http://example.com/CoolingCoil/{id}" ; + rr:class brick:Cooling_Coil ; ] ; rr:predicateObjectMap [ - rr:predicate brick:isPointOf ; + rr:predicate brick:hasLocation ; rr:objectMap [ rr:parentTriplesMap ex:MappingHotelRoom ; rr:joinCondition [ @@ -145,31 +136,35 @@ ex:MappingCO2Sensor ] ; ] ; rr:predicateObjectMap [ - rr:predicate rdf:value ; + rr:predicate brick:hasPoint ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/co2/value" ; + rr:parentTriplesMap ex:MappingfanSpeed_CoolingCoil ; + rr:joinCondition [ + rr:child "id" ; + rr:parent "id" ; + ] ; ] ; ] ; . -# Mapping for PresenceSensor -ex:MappingPresenceSensor +# Mapping for fanSpeed_CoolingCoil +ex:MappingfanSpeed_CoolingCoil a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="PresenceSensor")]' ; + rml:iterator '$[?(@.type=="CoolingCoil" && @..fanSpeed)]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/PresenceSensor/{id}" ; - rr:class brick:Occupancy_Count_Sensor ; + rr:template "http://example.com/fanSpeed_CoolingCoil/{id}" ; + rr:class brick:Fan_Speed_Command ; ] ; rr:predicateObjectMap [ rr:predicate brick:isPointOf ; rr:objectMap [ - rr:parentTriplesMap ex:MappingHotelRoom ; + rr:parentTriplesMap ex:MappingCoolingCoil ; rr:joinCondition [ - rr:child "hasLocation.value" ; + rr:child "id" ; rr:parent "id" ; ] ; ] ; @@ -177,7 +172,7 @@ ex:MappingPresenceSensor rr:predicateObjectMap [ rr:predicate rdf:value ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/pir/value" ; + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/fanSpeed/value" ; ] ; ] ; . @@ -204,24 +199,48 @@ ex:MappingFreshAirVentilation ] ; ] ; ] ; + rr:predicateObjectMap [ + rr:predicate brick:hasPoint ; + rr:objectMap [ + rr:parentTriplesMap ex:MappingairFlowSetpoint_FreshAirVentilation ; + rr:joinCondition [ + rr:child "id" ; + rr:parent "id" ; + ] ; + ] ; + ] ; . -# Mapping for RadiatorThermostat -ex:MappingRadiatorThermostat +# Mapping for Hotel +ex:MappingHotel a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="RadiatorThermostat")]' ; + rml:iterator '$[?(@.type=="Hotel")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/RadiatorThermostat/{id}" ; - rr:class brick:Thermostat ; + rr:template "http://example.com/Hotel/{id}" ; + rr:class rec:Building ; + ] ; + . + +# Mapping for HotelRoom +ex:MappingHotelRoom + a rr:TriplesMap ; + rml:logicalSource [ + rml:source "placeholder.json" ; + rml:referenceFormulation ql:JSONPath ; + rml:iterator '$[?(@.type=="HotelRoom")]' ; + ] ; + rr:subjectMap [ + rr:template "http://example.com/HotelRoom/{id}" ; + rr:class rec:Room ; ] ; rr:predicateObjectMap [ rr:predicate brick:hasLocation ; rr:objectMap [ - rr:parentTriplesMap ex:MappingHotelRoom ; + rr:parentTriplesMap ex:MappingHotel ; rr:joinCondition [ rr:child "hasLocation.value" ; rr:parent "id" ; @@ -230,20 +249,20 @@ ex:MappingRadiatorThermostat ] ; . -# Mapping for CoolingCoil -ex:MappingCoolingCoil +# Mapping for PresenceSensor +ex:MappingPresenceSensor a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="CoolingCoil")]' ; + rml:iterator '$[?(@.type=="PresenceSensor")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/CoolingCoil/{id}" ; - rr:class brick:Cooling_Coil ; + rr:template "http://example.com/PresenceSensor/{id}" ; + rr:class brick:Occupancy_Count_Sensor ; ] ; rr:predicateObjectMap [ - rr:predicate brick:hasLocation ; + rr:predicate brick:isPointOf ; rr:objectMap [ rr:parentTriplesMap ex:MappingHotelRoom ; rr:joinCondition [ @@ -252,56 +271,66 @@ ex:MappingCoolingCoil ] ; ] ; ] ; + rr:predicateObjectMap [ + rr:predicate rdf:value ; + rr:objectMap [ + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/pir/value" ; + ] ; + ] ; . -# Mapping for fanSpeed_CoolingCoil -ex:MappingfanSpeed_CoolingCoil +# Mapping for RadiatorThermostat +ex:MappingRadiatorThermostat a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="CoolingCoil")]' ; + rml:iterator '$[?(@.type=="RadiatorThermostat")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/fanSpeed_CoolingCoil/{id}" ; - rr:class brick:Fan_Speed_Command ; + rr:template "http://example.com/RadiatorThermostat/{id}" ; + rr:class brick:Thermostat ; ] ; rr:predicateObjectMap [ - rr:predicate brick:isPointOf ; + rr:predicate brick:hasLocation ; rr:objectMap [ - rr:parentTriplesMap ex:MappingCoolingCoil ; + rr:parentTriplesMap ex:MappingHotelRoom ; rr:joinCondition [ - rr:child "id" ; + rr:child "hasLocation.value" ; rr:parent "id" ; ] ; ] ; ] ; rr:predicateObjectMap [ - rr:predicate rdf:value ; + rr:predicate brick:hasPoint ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/fanSpeed/value" ; + rr:parentTriplesMap ex:MappingtemperatureSetpoint_RadiatorThermostat ; + rr:joinCondition [ + rr:child "id" ; + rr:parent "id" ; + ] ; ] ; ] ; . -# Mapping for airFlowSetpoint_FreshAirVentilation -ex:MappingairFlowSetpoint_FreshAirVentilation +# Mapping for TemperatureSensor +ex:MappingTemperatureSensor a rr:TriplesMap ; rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="FreshAirVentilation")]' ; + rml:iterator '$[?(@.type=="TemperatureSensor")]' ; ] ; rr:subjectMap [ - rr:template "http://example.com/airFlowSetpoint_FreshAirVentilation/{id}" ; - rr:class brick:Air_Flow_Setpoint ; + rr:template "http://example.com/TemperatureSensor/{id}" ; + rr:class brick:Air_Temperature_Sensor ; ] ; rr:predicateObjectMap [ rr:predicate brick:isPointOf ; rr:objectMap [ - rr:parentTriplesMap ex:MappingFreshAirVentilation ; + rr:parentTriplesMap ex:MappingHotelRoom ; rr:joinCondition [ - rr:child "id" ; + rr:child "hasLocation.value" ; rr:parent "id" ; ] ; ] ; @@ -309,7 +338,7 @@ ex:MappingairFlowSetpoint_FreshAirVentilation rr:predicateObjectMap [ rr:predicate rdf:value ; rr:objectMap [ - rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/airFlowSetpoint/value" ; + rr:template "https://fiware.eonerc.rwth-aachen.de/v2/entities/{id}/attrs/temperature/value" ; ] ; ] ; . @@ -320,7 +349,7 @@ ex:MappingtemperatureSetpoint_RadiatorThermostat rml:logicalSource [ rml:source "placeholder.json" ; rml:referenceFormulation ql:JSONPath ; - rml:iterator '$[?(@.type=="RadiatorThermostat")]' ; + rml:iterator '$[?(@.type=="RadiatorThermostat" && @..temperatureSetpoint)]' ; ] ; rr:subjectMap [ rr:template "http://example.com/temperatureSetpoint_RadiatorThermostat/{id}" ; diff --git a/examples/fiware/kgcp/rml/brick/intermediate_report_validated_brick.json b/examples/fiware/kgcp/rml/brick/intermediate_report_validated_brick.json index ce374da..02f358b 100644 --- a/examples/fiware/kgcp/rml/brick/intermediate_report_validated_brick.json +++ b/examples/fiware/kgcp/rml/brick/intermediate_report_validated_brick.json @@ -24,7 +24,7 @@ "@data": [ { "nodetype": "airFlowSetpoint_FreshAirVentilation", - "iterator": "$[?(@.type=='FreshAirVentilation')]", + "iterator": "$[?(@.type=='FreshAirVentilation' && @..airFlowSetpoint)]", "class": "brick:Air_Flow_Setpoint", "hasRelationship": [ { @@ -81,7 +81,7 @@ }, { "nodetype": "fanSpeed_CoolingCoil", - "iterator": "$[?(@.type=='CoolingCoil')]", + "iterator": "$[?(@.type=='CoolingCoil' && @..fanSpeed)]", "class": "brick:Fan_Speed_Command", "hasRelationship": [ { @@ -176,7 +176,7 @@ }, { "nodetype": "temperatureSetpoint_RadiatorThermostat", - "iterator": "$[?(@.type=='RadiatorThermostat')]", + "iterator": "$[?(@.type=='RadiatorThermostat' && @..temperatureSetpoint)]", "class": "brick:Temperature_Setpoint", "hasRelationship": [ { diff --git a/semantic_iot/RML_preprocess.py b/semantic_iot/RML_preprocess.py index 5d25eec..edc674d 100644 --- a/semantic_iot/RML_preprocess.py +++ b/semantic_iot/RML_preprocess.py @@ -17,7 +17,7 @@ def __init__(self, intermediate_report_file_path: str = None, platform_config: str = None, similarity_mode: str = "string", # ["string", "semantic"] - patterns_splitting: list = None, + patterns_splitting: list[str] = None, threshold_property: int = None ): """ @@ -612,7 +612,7 @@ def append_extra_entities(self, report_list: List[dict]): extra_items.append( { "nodetype": extra_type, - "iterator": f"$[?(@.type=='{entity['type']}')]", + "iterator": f"$[?(@.type=='{entity['type']}' && @{pattern.removeprefix('$')})]", "class": None, "hasRelationship": [ {