99#
1010# SPDX-License-Identifier: MPL-2.0
1111
12- import typing
12+ from typing import Any , Dict , Optional
1313
1414import rdflib # type: ignore
1515
1818from esmf_aspect_meta_model_python .base .characteristics .state import State
1919from esmf_aspect_meta_model_python .impl .characteristics .default_state import DefaultState
2020from esmf_aspect_meta_model_python .loader .instantiator .constants import DATA_TYPE_ERROR_MSG
21- from esmf_aspect_meta_model_python .loader .instantiator_base import InstantiatorBase
21+ from esmf_aspect_meta_model_python .loader .instantiator . enumeration_instantiator import EnumerationInstantiator
2222from esmf_aspect_meta_model_python .loader .rdf_helper import RdfHelper
2323from esmf_aspect_meta_model_python .vocabulary .SAMM import SAMM
2424from esmf_aspect_meta_model_python .vocabulary .SAMMC import SAMMC
2525
2626
27- class StateInstantiator (InstantiatorBase [ State ] ):
27+ class StateInstantiator (EnumerationInstantiator ):
2828 def _create_instance (self , element_node : Node ) -> State :
2929 data_type = self ._get_data_type (element_node )
3030 if data_type is None :
@@ -46,9 +46,9 @@ def _create_instance(self, element_node: Node) -> State:
4646
4747 return DefaultState (meta_model_base_attributes , data_type , values , default )
4848
49- def __to_state_node_value (self , value_node : Node ) -> typing . Dict :
49+ def __to_state_node_value (self , value_node : Optional [ Node ] ) -> Dict :
5050 """
51- This method instantiates one possible value of an state.
51+ This method instantiates one possible value of a state.
5252 :param value_node: Node of the Graph that represents one state value.
5353 The Argument can either be a Literal or a URIRef.
5454 - If value_node is a Literal it will represent e.g. a string or an integer value
@@ -66,9 +66,9 @@ def __to_state_node_value(self, value_node: Node) -> typing.Dict:
6666 for property_urn , property_value in value_node_properties :
6767 if property_urn != rdflib .RDF .type and isinstance (property_urn , str ):
6868 property_name = property_urn .split ("#" )[1 ]
69- actual_value : typing . Optional [typing . Any ]
69+ actual_value : Optional [Any ]
7070 if self .__is_collection_value (property_urn ):
71- actual_value = self .__instantiate_state_collection (property_value )
71+ actual_value = self .__instantiate_enum_collection (property_value )
7272 else :
7373 actual_value = self .__to_state_node_value (property_value )
7474 value [property_name ] = actual_value
@@ -84,20 +84,3 @@ def __to_state_node_value(self, value_node: Node) -> typing.Dict:
8484 f"Every value of an state must either be a Literal (string, int, etc.) or "
8585 f"a URI reference to a ComplexType. Values of type { type (value_node ).__name__ } are not allowed"
8686 )
87-
88- def __is_collection_value (self , property_subject : str ) -> bool :
89- characteristic = self ._aspect_graph .value ( # type: ignore
90- subject = property_subject ,
91- predicate = self ._samm .get_urn (SAMM .characteristic ),
92- )
93- characteristic_type = self ._aspect_graph .value (subject = characteristic , predicate = rdflib .RDF .type )
94- return characteristic_type in self ._sammc .collections_urns ()
95-
96- def __instantiate_state_collection (self , value_list ) -> typing .List [typing .Dict ]:
97- """creates a collection as a child for state characteristics"""
98- value_node_list = RdfHelper .get_rdf_list_values (value_list , self ._aspect_graph )
99- values = []
100- for value_node in value_node_list :
101- value = self .__to_state_node_value (value_node )
102- values .append (value )
103- return values
0 commit comments