-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#43 state initiator implementation #45
#43 state initiator implementation #45
Conversation
Hi @atextor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me, although one minor change is necessary to make the code style checker happy.
core/esmf-aspect-meta-model-python/tests/integration/test_characteristics.py
Outdated
Show resolved
Hide resolved
…acteristics.py Fix stylecheck Co-authored-by: Andreas Textor <[email protected]>
from esmf_aspect_meta_model_python.vocabulary.SAMMC import SAMMC | ||
|
||
|
||
class StateInstantiator(InstantiatorBase[State]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be inherited from class EnumerationInstantiator (../loader/instantiator/enumeration_instantiator)
Have a look at structure of base classes
`
from esmf_aspect_meta_model_python.base.characteristics.enumeration import Enumeration
class State(Enumeration, ABC):
"""State interface class.
Enumeration that has also a Default value.
"""
...
`
f"a URI reference to a ComplexType. Values of type {type(value_node).__name__} are not allowed" | ||
) | ||
|
||
def __is_collection_value(self, property_subject: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After updating the parent class (InstantiatorBase -> EnumerationInstantiator), this method becomes redundant and can be removed for the class StateInstantiator.
characteristic_type = self._aspect_graph.value(subject=characteristic, predicate=rdflib.RDF.type) | ||
return characteristic_type in self._sammc.collections_urns() | ||
|
||
def __instantiate_state_collection(self, value_list) -> typing.List[typing.Dict]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After updating the parent class (InstantiatorBase -> EnumerationInstantiator), this method becomes redundant and can be removed for the class StateInstantiator.
|
||
def __to_state_node_value(self, value_node: Node) -> typing.Dict: | ||
""" | ||
This method instantiates one possible value of an state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method instantiates one possible value of a state.
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
import typing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the code consistency, please import only used classes from the typing library
from typing import Any, Dict, List, Optional
|
||
return DefaultState(meta_model_base_attributes, data_type, values, default) | ||
|
||
def __to_state_node_value(self, value_node: Node) -> typing.Dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value_node can be None
so, definition can update with
def __to_state_node_value(self, value_node: Optional[Node])
in the method _create_instance
'
defaultValue = self._aspect_graph.value(
subject=element_node,
predicate=self._sammc.get_urn(SAMMC.default_value),
)
default = self.__to_state_node_value(defaultValue)
'
self._aspect_graph.value can return None for the defaultValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, correct the parts of the code for which comments have been added.
@thec0dewriter please have a look at comments to your PR Looking forward for your changes |
* StateInstantiator modified for EnumerationInstantiator inheritance
Thanks @Hanna-Shalamitskaya-EPAM for the detailed feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Thank you for your contribution @thec0dewriter! |
@thec0dewriter, thank you for your contribution |
Description
added a first implementation mainly based on the Enum implementation, given it's an enum with a default value.
Maybe a better option would be to reuse the enum implementation
Fixes #43
Type of change
Please delete options that are not relevant.
Checklist:
Additional notes:
Add any other notes or comments here.