aas-standard-parser 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (21) hide show
  1. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/PKG-INFO +1 -1
  2. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/aimc_parser.py +5 -69
  3. aas_standard_parser-0.2.2/aas_standard_parser/classes/aimc_parser_classes.py +52 -0
  4. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser.egg-info/PKG-INFO +1 -1
  5. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser.egg-info/SOURCES.txt +1 -0
  6. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/pyproject.toml +1 -1
  7. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/tests/test_aimc_parser.py +28 -30
  8. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/LICENSE +0 -0
  9. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/README.md +0 -0
  10. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/__init__.py +0 -0
  11. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/aid_parser.py +0 -0
  12. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/collection_helpers.py +0 -0
  13. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/demo/demo_process.py +0 -0
  14. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/demo/logging_handler.py +0 -0
  15. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/reference_helpers.py +0 -0
  16. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/submodel_parser.py +0 -0
  17. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser/utils.py +0 -0
  18. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser.egg-info/dependency_links.txt +0 -0
  19. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser.egg-info/requires.txt +0 -0
  20. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/aas_standard_parser.egg-info/top_level.txt +0 -0
  21. {aas_standard_parser-0.2.0 → aas_standard_parser-0.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-standard-parser
3
- Version: 0.2.0
3
+ Version: 0.2.2
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,69 +1,15 @@
1
1
  """Parser for Mapping Configurations in AIMC Submodel."""
2
2
 
3
- import json
4
3
  import logging
5
- from dataclasses import field
6
4
 
7
- import basyx.aas.adapter.json
8
5
  from basyx.aas import model
9
6
 
10
7
  import aas_standard_parser.collection_helpers as ch
8
+ from aas_standard_parser.classes.aimc_parser_classes import MappingConfiguration, MappingConfigurations, ReferenceProperties, SourceSinkRelation
11
9
 
12
10
  logger = logging.getLogger(__name__)
13
11
 
14
12
 
15
- class ReferenceProperties:
16
- """Class representing properties of a reference in the mapping configuration."""
17
-
18
- submodel_id: str = field(metadata={"description": "Identifier of the submodel used by the reference."})
19
- property_name: str = field(metadata={"description": "Name of the mapped property."})
20
- parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the reference."})
21
-
22
-
23
- class SourceSinkRelation:
24
- """Class representing a source-sink relation in the mapping configuration."""
25
-
26
- source_submodel_id: str = field(metadata={"description": "Identifier of the source (AID) submodel used by the source reference."})
27
- sink_submodel_id: str = field(metadata={"description": "Identifier of the target submodel used by the sink reference."})
28
- source: model.ExternalReference = field(metadata={"description": "Reference to the source property in the AID submodel."})
29
- sink: model.ExternalReference = field(metadata={"description": "Reference to the sink property in the target submodel."})
30
- source_property_name: str = field(metadata={"description": "Name of the mapped property in source."})
31
- sink_property_name: str = field(metadata={"description": "Name of the mapped property in sink."})
32
- source_parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the source reference."})
33
- sink_parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the reference."})
34
-
35
- def source_as_dict(self) -> dict:
36
- """Convert the source reference to a dictionary.
37
-
38
- :return: The source reference as a dictionary.
39
- """
40
- dict_string = json.dumps(self.source, cls=basyx.aas.adapter.json.AASToJsonEncoder)
41
- dict_string = dict_string.replace("GlobalReference", "Submodel").replace("FragmentReference", "SubmodelElementCollection")
42
- return json.loads(dict_string)
43
-
44
- def sink_as_dict(self) -> dict:
45
- """Convert the sink reference to a dictionary.
46
-
47
- :return: The sink reference as a dictionary.
48
- """
49
- return json.loads(json.dumps(self.sink, cls=basyx.aas.adapter.json.AASToJsonEncoder))
50
-
51
-
52
- class MappingConfiguration:
53
- """Class representing a mapping configuration."""
54
-
55
- interface_reference: model.ReferenceElement = field(metadata={"description": "Reference to the interface in the AID submodel."})
56
- aid_submodel_id: str = field(metadata={"description": "Identifier of the AID submodel used by the interface reference."})
57
- source_sink_relations: list[SourceSinkRelation] = field(metadata={"description": "List of source-sink relations in the mapping configuration."})
58
-
59
-
60
- class MappingConfigurations:
61
- """Class representing mapping configurations from AIMC submodel."""
62
-
63
- configurations: list[MappingConfiguration] = field(metadata={"description": "List of mapping configurations."})
64
- aid_submodel_ids: list[str] = field(metadata={"description": "List of AID submodel IDs used in the mapping configurations."})
65
-
66
-
67
13
  def get_mapping_configuration_root_element(aimc_submodel: model.Submodel) -> model.SubmodelElementCollection | None:
68
14
  """Get the mapping configuration root submodel element collection from the AIMC submodel.
69
15
 
@@ -168,7 +114,7 @@ def parse_mapping_configuration_element(
168
114
  return None
169
115
 
170
116
  # check if all relations have the same AID submodel
171
- aid_submodel_ids = list({source_sink_relation.source_submodel_id for source_sink_relation in source_sink_relations})
117
+ aid_submodel_ids = list({source_sink_relation.source_properties.submodel_id for source_sink_relation in source_sink_relations})
172
118
 
173
119
  if len(aid_submodel_ids) != 1:
174
120
  logger.error(
@@ -237,20 +183,9 @@ def _generate_source_sink_relations(mapping_configuration_element: model.Submode
237
183
  logger.warning(f"'second' reference is missing in RelationshipElement '{source_sink_relation.id_short}'")
238
184
  continue
239
185
 
240
- source_ref_properties = _get_reference_properties(source_sink_relation.first)
241
- sink_ref_properties = _get_reference_properties(source_sink_relation.second)
242
-
243
186
  relation = SourceSinkRelation()
244
-
245
- relation.source = source_sink_relation.first
246
- relation.source_submodel_id = source_ref_properties.submodel_id
247
- relation.source_property_name = source_ref_properties.property_name
248
- relation.source_parent_path = source_ref_properties.parent_path
249
-
250
- relation.sink = source_sink_relation.second
251
- relation.sink_submodel_id = sink_ref_properties.submodel_id
252
- relation.sink_property_name = sink_ref_properties.property_name
253
- relation.sink_parent_path = sink_ref_properties.parent_path
187
+ relation.source_properties = _get_reference_properties(source_sink_relation.first)
188
+ relation.sink_properties = _get_reference_properties(source_sink_relation.second)
254
189
 
255
190
  source_sink_relations.append(relation)
256
191
 
@@ -276,6 +211,7 @@ def _get_reference_properties(reference: model.ExternalReference) -> ReferencePr
276
211
  ref_properties.submodel_id = global_ref.value
277
212
  ref_properties.property_name = last_fragment_ref.value
278
213
  ref_properties.parent_path = parent_path
214
+ ref_properties.reference = reference
279
215
 
280
216
  return ref_properties
281
217
 
@@ -0,0 +1,52 @@
1
+ import json
2
+ from dataclasses import field
3
+
4
+ import basyx.aas.adapter.json
5
+ from basyx.aas import model
6
+
7
+
8
+ class ReferenceProperties:
9
+ """Class representing properties of a reference in the mapping configuration."""
10
+
11
+ reference: model.ExternalReference = field(metadata={"description": "Reference to the property in the submodel."})
12
+ submodel_id: str = field(metadata={"description": "Identifier of the submodel used by the reference."})
13
+ property_name: str = field(metadata={"description": "Name of the mapped property."})
14
+ parent_path: list[str] = field(metadata={"description": "List of idShorts representing the parent path of the reference."})
15
+
16
+
17
+ class SourceSinkRelation:
18
+ """Class representing a source-sink relation in the mapping configuration."""
19
+
20
+ source_properties: ReferenceProperties = field(metadata={"description": "Properties of the source reference."})
21
+ sink_properties: ReferenceProperties = field(metadata={"description": "Properties of the sink reference."})
22
+
23
+ def source_reference_as_dict(self) -> dict:
24
+ """Convert the source reference to a dictionary.
25
+
26
+ :return: The source reference as a dictionary.
27
+ """
28
+ dict_string = json.dumps(self.source_properties.reference, cls=basyx.aas.adapter.json.AASToJsonEncoder)
29
+ dict_string = dict_string.replace("GlobalReference", "Submodel").replace("FragmentReference", "SubmodelElementCollection")
30
+ return json.loads(dict_string)
31
+
32
+ def sink_reference_as_dict(self) -> dict:
33
+ """Convert the sink reference to a dictionary.
34
+
35
+ :return: The sink reference as a dictionary.
36
+ """
37
+ return json.dumps(self.sink_properties.reference, cls=basyx.aas.adapter.json.AASToJsonEncoder)
38
+
39
+
40
+ class MappingConfiguration:
41
+ """Class representing a mapping configuration."""
42
+
43
+ interface_reference: model.ReferenceElement = field(metadata={"description": "Reference to the interface in the AID submodel."})
44
+ aid_submodel_id: str = field(metadata={"description": "Identifier of the AID submodel used by the interface reference."})
45
+ source_sink_relations: list[SourceSinkRelation] = field(metadata={"description": "List of source-sink relations in the mapping configuration."})
46
+
47
+
48
+ class MappingConfigurations:
49
+ """Class representing mapping configurations from AIMC submodel."""
50
+
51
+ configurations: list[MappingConfiguration] = field(metadata={"description": "List of mapping configurations."})
52
+ aid_submodel_ids: list[str] = field(metadata={"description": "List of AID submodel IDs used in the mapping configurations."})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-standard-parser
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
@@ -13,6 +13,7 @@ aas_standard_parser.egg-info/SOURCES.txt
13
13
  aas_standard_parser.egg-info/dependency_links.txt
14
14
  aas_standard_parser.egg-info/requires.txt
15
15
  aas_standard_parser.egg-info/top_level.txt
16
+ aas_standard_parser/classes/aimc_parser_classes.py
16
17
  aas_standard_parser/demo/demo_process.py
17
18
  aas_standard_parser/demo/logging_handler.py
18
19
  tests/test_aimc_parser.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-standard-parser"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Some auxiliary functions for parsing standard submodels"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -1,7 +1,7 @@
1
1
  import pytest
2
2
  from basyx.aas import model
3
3
 
4
- from aas_standard_parser.aimc_parser import MappingConfiguration, SourceSinkRelation
4
+ from aas_standard_parser.classes.aimc_parser_classes import MappingConfiguration, SourceSinkRelation, ReferenceProperties
5
5
  import aas_standard_parser.aimc_parser as aimc_parser
6
6
  from aas_standard_parser.utils import create_submodel_from_file
7
7
 
@@ -41,7 +41,6 @@ def test_003_parse_mapping_configuration_element(aimc_submodel: model.submodel):
41
41
  assert configuration is not None
42
42
  _check_interface_ref(configuration)
43
43
  _check_relations(configuration)
44
- _check_relations(configuration)
45
44
 
46
45
  def test_004_parse_mapping_configurations(aimc_submodel: model.submodel):
47
46
  mapping_configurations = aimc_parser.parse_mapping_configurations(aimc_submodel)
@@ -57,7 +56,6 @@ def test_004_parse_mapping_configurations(aimc_submodel: model.submodel):
57
56
 
58
57
  _check_interface_ref(configuration)
59
58
  _check_relations(configuration)
60
- _check_relations(configuration)
61
59
 
62
60
  def _check_interface_ref(configuration: MappingConfiguration):
63
61
  assert configuration.interface_reference is not None
@@ -81,51 +79,51 @@ def _check_relations(configuration: MappingConfiguration):
81
79
  relation = configuration.source_sink_relations[0]
82
80
  assert relation is not None
83
81
 
84
- assert relation.source is not None
85
- assert relation.source_submodel_id == configuration.aid_submodel_id
82
+ assert relation.source_properties is not None
83
+ assert relation.source_properties.submodel_id == configuration.aid_submodel_id
86
84
 
87
- assert relation.sink is not None
85
+ assert relation.sink_properties is not None
88
86
 
89
- _check_relations_source(relation)
90
- _check_relations_sink(relation)
87
+ _check_relations_source(relation.source_properties)
88
+ _check_relations_sink(relation.sink_properties)
91
89
  _check_relation_methods(relation)
92
90
 
93
- def _check_relations_source(relation: SourceSinkRelation):
94
- assert relation is not None
91
+ def _check_relations_source(reference_properties: ReferenceProperties):
92
+ assert reference_properties is not None
95
93
 
96
- assert isinstance(relation.source, model.ExternalReference)
94
+ assert isinstance(reference_properties.reference, model.ExternalReference)
97
95
 
98
- assert relation.source_property_name is not None
99
- assert relation.source_property_name == "HandlingC"
96
+ assert reference_properties.property_name is not None
97
+ assert reference_properties.property_name == "HandlingC"
100
98
 
101
- assert relation.source_parent_path is not None
102
- assert len(relation.source_parent_path) == 5
103
- assert relation.source_parent_path[3] == "axes_position"
99
+ assert reference_properties.parent_path is not None
100
+ assert len(reference_properties.parent_path) == 5
101
+ assert reference_properties.parent_path[3] == "axes_position"
104
102
 
105
- assert relation.source_submodel_id is not None
106
- assert relation.source_submodel_id == relation.source.key[0].value
103
+ assert reference_properties.submodel_id is not None
104
+ assert reference_properties.submodel_id == reference_properties.reference.key[0].value
107
105
 
108
- def _check_relations_sink(relation: SourceSinkRelation):
109
- assert relation is not None
106
+ def _check_relations_sink(reference_properties: ReferenceProperties):
107
+ assert reference_properties is not None
110
108
 
111
- assert isinstance(relation.sink, model.ExternalReference)
109
+ assert isinstance(reference_properties.reference, model.ExternalReference)
112
110
 
113
- assert relation.sink_property_name is not None
114
- assert relation.sink_property_name == "HandlingC"
111
+ assert reference_properties.property_name is not None
112
+ assert reference_properties.property_name == "HandlingC"
115
113
 
116
- assert relation.sink_parent_path is not None
117
- assert len(relation.sink_parent_path) == 2
118
- assert relation.sink_parent_path[1] == "AxesPosition"
114
+ assert reference_properties.parent_path is not None
115
+ assert len(reference_properties.parent_path) == 2
116
+ assert reference_properties.parent_path[1] == "AxesPosition"
119
117
 
120
- assert relation.sink_submodel_id is not None
121
- assert relation.sink_submodel_id == relation.sink.key[0].value
118
+ assert reference_properties.submodel_id is not None
119
+ assert reference_properties.submodel_id == reference_properties.reference.key[0].value
122
120
 
123
121
  def _check_relation_methods(relation: SourceSinkRelation):
124
122
  # test to_json methods
125
- source_json = relation.source_as_dict()
123
+ source_json = relation.source_reference_as_dict()
126
124
  assert source_json is not None
127
125
  assert "type" in source_json
128
126
 
129
- sink_json = relation.sink_as_dict()
127
+ sink_json = relation.sink_reference_as_dict()
130
128
  assert sink_json is not None
131
129
  assert "type" in sink_json