Skip to content
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

Merged

Conversation

thec0dewriter
Copy link
Contributor

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Additional notes:

Add any other notes or comments here.

@thec0dewriter
Copy link
Contributor Author

Hi @atextor,
Fixed the Eclipse Contributor check

Copy link
Contributor

@atextor atextor left a 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.

…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]):
Copy link
Contributor

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:
Copy link
Contributor

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]:
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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:
Copy link
Contributor

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

Copy link
Contributor

@Hanna-Shalamitskaya-EPAM Hanna-Shalamitskaya-EPAM left a 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.

@Hanna-Shalamitskaya-EPAM
Copy link
Contributor

@thec0dewriter please have a look at comments to your PR

Looking forward for your changes

* StateInstantiator modified for EnumerationInstantiator inheritance
@thec0dewriter
Copy link
Contributor Author

Thanks @Hanna-Shalamitskaya-EPAM for the detailed feedback.
I made the suggested modifications, let me know if I missed something

Copy link
Contributor

@Hanna-Shalamitskaya-EPAM Hanna-Shalamitskaya-EPAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@atextor atextor merged commit 5c053aa into eclipse-esmf:main Oct 21, 2024
2 checks passed
@atextor
Copy link
Contributor

atextor commented Oct 21, 2024

Thank you for your contribution @thec0dewriter!

@Hanna-Shalamitskaya-EPAM
Copy link
Contributor

@thec0dewriter, thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Missing state_initiator implementation
3 participants