Skip to content

Commit 26171ec

Browse files
authored
Merge pull request #54 from bci-oss/fix-max-recursion-depth-issue
update logic of loading graph elements
2 parents ea5748b + 041caa5 commit 26171ec

File tree

102 files changed

+2023
-1534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2023
-1534
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ dmypy.json
7070
# SAMM
7171
core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_aspect_meta_model/samm/
7272
/core/esmf-aspect-meta-model-python/samm-cli/
73+
/core/esmf-aspect-meta-model-python/tests/integration/java_models/resources/

core/esmf-aspect-meta-model-python/README.md

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
The Aspect Model Loader as part of the Python SDK provided by the [*Eclipse Semantic Modeling Framework*](
22
https://projects.eclipse.org/projects/dt.esmf).
33

4-
<!-- TOC -->
5-
* [An Aspect of the Meta Model](#an-aspect-of-the-meta-model)
6-
* [Set Up SAMM Aspect Meta Model](#set-up-samm-aspect-meta-model)
7-
* [Install poetry](#install-poetry)
8-
* [Install project dependencies](#install-project-dependencies)
9-
* [Download SAMM files](#download-samm-files)
10-
* [Download SAMM release](#download-samm-release)
11-
* [Download SAMM branch](#download-samm-branch)
12-
* [Input data handler usage](#input-data-handler-usage)
13-
* [Aspect Meta Model Loader usage](#aspect-meta-model-loader-usage)
14-
* [Samm Units](#samm-units)
15-
* [SAMM CLI wrapper class](#samm-cli-wrapper-class)
16-
* [Scripts](#scripts)
17-
* [Automation Tasks](#automation-tasks)
18-
* [tox](#tox)
19-
* [GitHub actions](#github-actions)
20-
* [Check New Pull Request](#check-new-pull-request)
21-
* [Build release](#build-release)
22-
<!-- TOC -->
23-
244
# An Aspect of the Meta Model
255

266
The `esmf-aspect-model-loader` package provides the Python implementation for the SAMM Aspect Meta Model, or SAMM.
277
Each Meta Model element and each Characteristic class is represented by an interface with a corresponding
288
implementation.
299

10+
## Documentation
11+
12+
* Check the [developer documentation](https://eclipse-esmf.github.io)
13+
* Check the SAMM [specification](https://eclipse-esmf.github.io/samm-specification/snapshot/index.html)
14+
* Having issues with the ESMF SDK Python Aspect Model Loader? Open a [GitHub issue](https://github.com/eclipse-esmf/esmf-sdk-py-aspect-model-loader/issues).
15+
3016
## Set Up SAMM Aspect Meta Model
3117

3218
Before getting started to use the `esmf-aspect-model-loader` library you need to apply some set up actions:
@@ -85,55 +71,42 @@ poetry run download-samm-branch
8571
```
8672
Link to all branches: [SAMM Releases](https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/branches)
8773

88-
## Input data handler usage
89-
90-
The InputHandler is a general-purpose class designed for loading input data into an RDF graph.
91-
It easily accommodates different input sources such as local files (.ttl) or direct data strings containing
92-
RDF formatted data.
74+
## SAMM Aspect Model Graph usage
9375

76+
SAMM Aspect Model Graph is a class that allows you to load and interact with the Semantic Data Aspect Meta Model graph.
77+
Below is an example of how to use SAMM Aspect Model Graph in your Python code:
9478
```python
95-
from esmf_aspect_meta_model_python.resolver.handler import InputHandler
79+
from esmf_aspect_meta_model_python import SAMMGraph
9680

97-
# Instantiating the Handler
98-
# The InputHandler requires a path or data string upon instantiation, which defines the source of RDF data
99-
# local file
100-
model_path = "path/to/local/file/AspectName.ttl"
101-
handler = InputHandler(model_path)
102-
graph, aspect_urn = handler.get_rdf_graph()
81+
# Define the path to your Turtle file
82+
model_path = "absolute/path/to/turtle.ttl"
10383

104-
# returns a tuple containing the RDF graph and the aspect URN derived from the provided data source
105-
```
84+
# Create an instance of SAMMGraph
85+
samm_graph = SAMMGraph()
10686

107-
```python
108-
from esmf_aspect_meta_model_python.resolver.handler import InputHandler
87+
# Parse the Turtle file to load the graph
88+
samm_graph.parse(model_path)
10989

110-
# Alternatively, if you have RDF data in a string format, you can directly pass it as follows:
111-
rdf_data_string = "your RDF data string here"
112-
handler = InputHandler(rdf_data_string)
113-
graph, aspect_urn = handler.get_rdf_graph()
90+
# Load the aspect model from the graph
91+
aspect = samm_graph.load_aspect_model()
11492
```
11593

116-
## Aspect Meta Model Loader usage
117-
118-
An Aspect of the Meta Model can be loaded as follows:
94+
The `load_model_elements` method in the SAMMGraph class creates Python objects to represent all nodes from the Aspect
95+
model graph. It retrieves all SAMM elements from the RDF graph and converts them into structured Python objects.
11996
```python
120-
from esmf_aspect_meta_model_python import AspectLoader
121-
from esmf_aspect_meta_model_python.resolver.handler import InputHandler
97+
from esmf_aspect_meta_model_python import SAMMGraph
12298

99+
# Define the path to your Turtle file
123100
model_path = "absolute/path/to/turtle.ttl"
124-
handler = InputHandler(model_path)
125-
graph, aspect_urn = handler.get_rdf_graph()
126101

127-
loader = AspectLoader()
128-
model_elements = loader.load_aspect_model(graph, aspect_urn)
129-
aspect = model_elements[0]
102+
# Create an instance of SAMMGraph
103+
samm_graph = SAMMGraph()
130104

131-
# or you can provide an Aspect URN
105+
# Parse the Turtle file to load the graph
106+
samm_graph.parse(model_path)
132107

133-
loader = AspectLoader()
134-
aspect_urn = "urn:samm:org.eclipse.esmf.samm:aspect.model:0.0.1#AspectName"
135-
model_elements = loader.load_aspect_model("absolute/path/to/turtle.ttl", aspect_urn)
136-
aspect = model_elements[0]
108+
# Load all model elements from the graph
109+
model_elements = samm_graph.load_model_elements()
137110
```
138111

139112
## Samm Units
@@ -200,7 +173,7 @@ Provided scripts:
200173
All scripts run like a poetry command. The poetry is available from the folder where [pyproject.toml](pyproject.toml)
201174
is located.
202175

203-
# Automation Tasks
176+
# Tests running
204177
## tox
205178

206179
`tox` is used for the tests automation purpose. There are two environments with different purposes and tests can

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,5 @@
8585
DefaultTrait,
8686
DefaultUnit,
8787
)
88-
from .loader.aspect_loader import AspectLoader
8988
from .loader.samm_graph import SAMMGraph
9089
from .resolver.handler import InputHandler

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/base/characteristics/characteristic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
#
1010
# SPDX-License-Identifier: MPL-2.0
11-
1211
from abc import ABC, abstractmethod
1312

1413
from esmf_aspect_meta_model_python.base.base import Base

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/impl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
from .default_either import DefaultEither
4343
from .default_event import DefaultEvent
4444
from .default_operation import DefaultOperation
45-
from .default_property import DefaultProperty
45+
from .default_property import DefaultBlankProperty, DefaultProperty, DefaultPropertyWithExtends
4646
from .default_quantity_kind import DefaultQuantityKind
4747
from .default_unit import DefaultUnit

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/impl/characteristics/collection/default_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DefaultCollection(DefaultCharacteristic, Collection):
2626
def __init__(
2727
self,
2828
meta_model_base_attributes: MetaModelBaseAttributes,
29-
data_type: DataType,
29+
data_type: Optional[DataType],
3030
element_characteristic: Optional[Characteristic],
3131
):
3232
super().__init__(meta_model_base_attributes, data_type)
@@ -35,7 +35,7 @@ def __init__(
3535

3636
def _set_parent_element_on_child_element(self) -> None:
3737
"""Set a parent element on child elements."""
38-
if self._element_characteristic is not None:
38+
if self._element_characteristic:
3939
self._element_characteristic.append_parent_element(self)
4040

4141
@property

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/impl/characteristics/default_characteristic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
#
1010
# SPDX-License-Identifier: MPL-2.0
11+
from typing import Optional
1112

1213
from esmf_aspect_meta_model_python.base.characteristics.characteristic import Characteristic
1314
from esmf_aspect_meta_model_python.base.data_types.complex_type import ComplexType
@@ -21,8 +22,12 @@ class DefaultCharacteristic(BaseImpl, Characteristic):
2122

2223
SCALAR_ATTR_NAMES = BaseImpl.SCALAR_ATTR_NAMES + ["data_type"]
2324

24-
def __init__(self, meta_model_base_attributes: MetaModelBaseAttributes, data_type: DataType):
25+
def __init__(self, meta_model_base_attributes: MetaModelBaseAttributes, data_type: Optional[DataType]):
26+
if data_type is None:
27+
raise ValueError("Attribute 'data_type' is required for Characteristic class.")
28+
2529
super().__init__(meta_model_base_attributes)
30+
2631
self._data_type = data_type
2732

2833
if isinstance(self._data_type, ComplexType):

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/impl/data_types/default_abstract_entity.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ def __init__(
3636
@property
3737
def extending_elements(self) -> List[ComplexType]:
3838
"""Extending elements."""
39-
return [DefaultComplexType._instances[element_subject] for element_subject in self.__extending_elements]
39+
extending_elements = []
40+
for element_subject in self.__extending_elements:
41+
element = DefaultComplexType._instances.get(element_subject)
42+
if element:
43+
extending_elements.append(element)
44+
45+
return extending_elements

0 commit comments

Comments
 (0)