aas-standard-parser 0.1.9__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import json
4
4
  import logging
5
- from dataclasses import dataclass, field
5
+ from dataclasses import field
6
6
 
7
7
  import basyx.aas.adapter.json
8
8
  from basyx.aas import model
@@ -12,21 +12,27 @@ import aas_standard_parser.collection_helpers as ch
12
12
  logger = logging.getLogger(__name__)
13
13
 
14
14
 
15
+ class ReferenceProperties:
16
+ """Class representing properties of a reference in the mapping configuration."""
17
+
18
+ reference: model.ExternalReference = field(metadata={"description": "Reference to the property in the submodel."})
19
+ submodel_id: str = field(metadata={"description": "Identifier of the submodel used by the reference."})
20
+ property_name: str = field(metadata={"description": "Name of the mapped property."})
21
+ parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the reference."})
22
+
23
+
15
24
  class SourceSinkRelation:
16
25
  """Class representing a source-sink relation in the mapping configuration."""
17
26
 
18
- aid_submodel_id: str = field(metadata={"description": "Identifier of the AID submodel used by the source reference."})
19
- source: model.ExternalReference = field(metadata={"description": "Reference to the source property in the AID submodel."})
20
- sink: model.ExternalReference = field(metadata={"description": "Reference to the sink property in the target submodel."})
21
- property_name: str = field(metadata={"description": "Name of the mapped property."})
22
- source_parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the reference."})
27
+ source_properties: ReferenceProperties = field(metadata={"description": "Properties of the source reference."})
28
+ sink_properties: ReferenceProperties = field(metadata={"description": "Properties of the sink reference."})
23
29
 
24
30
  def source_as_dict(self) -> dict:
25
31
  """Convert the source reference to a dictionary.
26
32
 
27
33
  :return: The source reference as a dictionary.
28
34
  """
29
- dict_string = json.dumps(self.source, cls=basyx.aas.adapter.json.AASToJsonEncoder)
35
+ dict_string = json.dumps(self.source_properties.reference, cls=basyx.aas.adapter.json.AASToJsonEncoder)
30
36
  dict_string = dict_string.replace("GlobalReference", "Submodel").replace("FragmentReference", "SubmodelElementCollection")
31
37
  return json.loads(dict_string)
32
38
 
@@ -35,14 +41,7 @@ class SourceSinkRelation:
35
41
 
36
42
  :return: The sink reference as a dictionary.
37
43
  """
38
- return json.loads(json.dumps(self.sink, cls=basyx.aas.adapter.json.AASToJsonEncoder))
39
-
40
- def get_source_parent_property_group_name(self) -> str:
41
- """Get the name of the parent property group from the source. Ignore 'properties' entries from the path."""
42
- if len(self.source_parent_path) == 0:
43
- return ""
44
-
45
- return next((n for n in reversed(self.source_parent_path) if n != "properties"), "")
44
+ return json.dumps(self.sink_properties.reference, cls=basyx.aas.adapter.json.AASToJsonEncoder)
46
45
 
47
46
 
48
47
  class MappingConfiguration:
@@ -164,7 +163,7 @@ def parse_mapping_configuration_element(
164
163
  return None
165
164
 
166
165
  # check if all relations have the same AID submodel
167
- aid_submodel_ids = list({source_sink_relation.aid_submodel_id for source_sink_relation in source_sink_relations})
166
+ aid_submodel_ids = list({source_sink_relation.source_properties.submodel_id for source_sink_relation in source_sink_relations})
168
167
 
169
168
  if len(aid_submodel_ids) != 1:
170
169
  logger.error(
@@ -233,33 +232,37 @@ def _generate_source_sink_relations(mapping_configuration_element: model.Submode
233
232
  logger.warning(f"'second' reference is missing in RelationshipElement '{source_sink_relation.id_short}'")
234
233
  continue
235
234
 
236
- source_ref = source_sink_relation.first
235
+ relation = SourceSinkRelation()
236
+ relation.source_properties = _get_reference_properties(source_sink_relation.first)
237
+ relation.sink_properties = _get_reference_properties(source_sink_relation.second)
237
238
 
238
- global_ref = next((key for key in source_ref.key if key.type == model.KeyTypes.GLOBAL_REFERENCE), None)
239
+ source_sink_relations.append(relation)
239
240
 
240
- if global_ref is None:
241
- logger.warning(f"No GLOBAL_REFERENCE key found in 'first' reference of RelationshipElement '{source_sink_relation.id_short}'")
242
- continue
241
+ return source_sink_relations
243
242
 
244
- last_fragment_ref = next(
245
- (key for key in reversed(source_ref.key) if key.type == model.KeyTypes.FRAGMENT_REFERENCE),
246
- None,
247
- )
248
243
 
249
- if last_fragment_ref is None:
250
- logger.warning(f"No FRAGMENT_REFERENCE key found in 'first' reference of RelationshipElement '{source_sink_relation.id_short}'")
251
- continue
244
+ def _get_reference_properties(reference: model.ExternalReference) -> ReferenceProperties | None:
245
+ global_ref = next((key for key in reference.key if key.type == model.KeyTypes.GLOBAL_REFERENCE), None)
252
246
 
253
- relation = SourceSinkRelation()
254
- relation.source = source_sink_relation.first
255
- relation.sink = source_sink_relation.second
256
- relation.aid_submodel_id = global_ref.value
257
- relation.property_name = last_fragment_ref.value
258
- relation.source_parent_path = _get_reference_parent_path(source_ref)
247
+ if global_ref is None:
248
+ logger.warning(f"No GLOBAL_REFERENCE key found in 'first' reference of RelationshipElement '{reference}'")
249
+ return None
259
250
 
260
- source_sink_relations.append(relation)
251
+ last_fragment_ref = next((key for key in reversed(reference.key) if key.type == model.KeyTypes.FRAGMENT_REFERENCE), None)
261
252
 
262
- return source_sink_relations
253
+ if last_fragment_ref is None:
254
+ logger.warning(f"No FRAGMENT_REFERENCE key found in 'first' reference of RelationshipElement '{reference.id_short}'")
255
+ return None
256
+
257
+ parent_path = _get_reference_parent_path(reference)
258
+
259
+ ref_properties = ReferenceProperties()
260
+ ref_properties.submodel_id = global_ref.value
261
+ ref_properties.property_name = last_fragment_ref.value
262
+ ref_properties.parent_path = parent_path
263
+ ref_properties.reference = reference
264
+
265
+ return ref_properties
263
266
 
264
267
 
265
268
  def _get_reference_parent_path(reference: model.ExternalReference) -> list[str]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-standard-parser
3
- Version: 0.1.9
3
+ Version: 0.2.1
4
4
  Summary: Some auxiliary functions for parsing standard submodels
5
5
  Author-email: Daniel Klein <daniel.klein@em.ag>
6
6
  License: MIT License
@@ -1,14 +1,14 @@
1
1
  aas_standard_parser/__init__.py,sha256=3iBTUUlJ97ImkAHdss_GP970BANEU1uNeg0HlRzzois,599
2
2
  aas_standard_parser/aid_parser.py,sha256=9vp8_kJRfExTmw8tjmO32n1eHFAE5ItmfPlZ2ORLZMs,14314
3
- aas_standard_parser/aimc_parser.py,sha256=yl94hOtqoOHYFP_8cladJho8u8QZ3MNUXR0OpXl5bLU,12298
3
+ aas_standard_parser/aimc_parser.py,sha256=EdZmXL8wDTscSPCKI1ILKUIeNkZPMLHV2leTCXsqckQ,12347
4
4
  aas_standard_parser/collection_helpers.py,sha256=fTQGQiC-bGD41Qx0FDDBtWhvkeZtEe6Sh-aT93ePwro,4153
5
5
  aas_standard_parser/reference_helpers.py,sha256=UbqXaub5PTvt_W3VPntSSFcTS59PUwlTpoujny8rIRI,377
6
6
  aas_standard_parser/submodel_parser.py,sha256=XH-XTBB3a0MB1NR5nAzG9C6f9hT_qG42f-ABruN3MzE,3169
7
7
  aas_standard_parser/utils.py,sha256=5iIPpM_ob2V9MwFL_vTbXd23doYKot30xenRmTPAquo,723
8
8
  aas_standard_parser/demo/demo_process.py,sha256=Xn9uD0xLoNx0ZvB3Lk0oYkGBRHaEfUbfqv5_SpPWYck,530
9
9
  aas_standard_parser/demo/logging_handler.py,sha256=x-eX4XDU3sZTJE22rzJSiaWQ8wRMbtaFpFBAeAcbIzI,5752
10
- aas_standard_parser-0.1.9.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
11
- aas_standard_parser-0.1.9.dist-info/METADATA,sha256=PVSImI0CUdNhXwh4PHaNbCVCI5T3tLtOefVbonzzAdM,1718
12
- aas_standard_parser-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- aas_standard_parser-0.1.9.dist-info/top_level.txt,sha256=OQaK6cwYttR1-eKTz5u4M0jbwSfp4HqJ56chaf0nHnw,20
14
- aas_standard_parser-0.1.9.dist-info/RECORD,,
10
+ aas_standard_parser-0.2.1.dist-info/licenses/LICENSE,sha256=simqYMD2P9Ikm0Kh9n7VGNpaVcm2TMVVQmECYZ_xVZ8,1065
11
+ aas_standard_parser-0.2.1.dist-info/METADATA,sha256=ymMIlWi-tUVCsZya-shT7XkYyrSgCGM_KA4EoN8sITI,1718
12
+ aas_standard_parser-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ aas_standard_parser-0.2.1.dist-info/top_level.txt,sha256=OQaK6cwYttR1-eKTz5u4M0jbwSfp4HqJ56chaf0nHnw,20
14
+ aas_standard_parser-0.2.1.dist-info/RECORD,,