3. Data Types and Data Values¶
This Jupyter notebook demonstrates how Data Values in Capella can be handled. First, let’s load the model again…
[1]:
import capellambse
path_to_model = "../../../tests/data/melodymodel/5_2/Melody Model Test.aird"
model = capellambse.MelodyModel(path_to_model)
model
[1]:
<capellambse.model._model.MelodyModel at 0x72bcc64d7b30>
As explained in the notebook 01, please ignore the warning about PVMT missing above.
3.1. Example 1: Look into the Data package of the Logical Architecture¶
Let’s have a look into the data package on the Logical Architecture. It works the same with the other architectures, just replace the oa
accordingly. We can see the defined classes, collections, enuemrations, and so on.
[2]:
model.la.data_package
[2]:
Data (org.polarsys.capella.core.data.information:DataPkg)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
classes | |
collections | (Empty list) |
complex_values | (Empty list) |
constraints | (Empty list) |
datatypes |
|
description | |
diagrams |
|
enumerations |
|
filtering_criteria | (Empty list) |
layer | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
name | Data |
owned_associations | (Empty list) |
packages |
|
parent | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for DataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17) |
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
unions | (Empty list) |
uuid | 39e99d4a-a32c-4b70-b4b6-d03fec612e17 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcbc33e8a0> |
visible_on_diagrams | (Empty list) |
xtype | org.polarsys.capella.core.data.information:DataPkg |
For Enumerations we can see the Literals assigned to it. We can see both the literals that have been inherited by the specialized super class, and the literals that are defined within this model element (own_literals).
[3]:
model.la.data_package.enumerations[0]
[3]:
Wand Core (org.polarsys.capella.core.data.information.datatype:Enumeration)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
domain_type | None |
filtering_criteria | (Empty list) |
is_discrete | False |
layer | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
literals |
|
max_inclusive | False |
min_inclusive | False |
name | Wand Core |
owned_literals |
|
parent | DataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17) |
pattern | |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for "Wand Core" (546cd75a-c7ac-4e07-9d2d-8a1f93d82419) |
requirements | (Empty list) |
sid | |
sub | Backreference to Enumeration - omitted: can be slow to compute. Display this property directly to show. |
summary | |
super | None |
traces | (Empty list) |
uuid | 546cd75a-c7ac-4e07-9d2d-8a1f93d82419 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcc431e4e0> |
visibility | <VisibilityKind.UNSET: 'UNSET'> |
visible_on_diagrams |
|
xtype | org.polarsys.capella.core.data.information.datatype:Enumeration |
Let’s do the same for a class. Again, we can see the properties of the super class and the properties of the own model element.
[4]:
model.la.data_package.classes[0]
[4]:
Wand (org.polarsys.capella.core.data.information:Class)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
generalizations |
|
is_abstract | False |
is_final | False |
is_primitive | False |
layer | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
name | Wand |
owned_properties | |
parent | DataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17) |
progress_status | NOT_SET |
properties | |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040) |
realizations |
|
realized_by | Backreference to Class - omitted: can be slow to compute. Display this property directly to show. |
realized_classes |
|
requirements | (Empty list) |
sid | |
state_machines | (Empty list) |
sub | Backreference to Class - omitted: can be slow to compute. Display this property directly to show. |
summary | |
super | "Branch" (2b34c799-769c-42f2-8a1b-4533dba209a0) |
traces | (Empty list) |
tree_view | Tree view of Wand (uuid: c710f1c2-ede6-444e-9e2b-0ff30d7fd040_tree_view) |
uuid | c710f1c2-ede6-444e-9e2b-0ff30d7fd040 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcb2f72f60> |
visibility | <VisibilityKind.UNSET: 'UNSET'> |
visible_on_diagrams |
|
xtype | org.polarsys.capella.core.data.information:Class |
We can investigate the properties of a Class
[5]:
model.la.data_package.classes[0].properties[0]
[5]:
owner (org.polarsys.capella.core.data.information:Property)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
association | Backreference to Association - omitted: can be slow to compute. Display this property directly to show. |
constraints | (Empty list) |
default_value | None |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
is_abstract | False |
is_derived | False |
is_ordered | False |
is_part_of_key | False |
is_read_only | False |
is_static | False |
is_unique | False |
kind | <AggregationKind.UNSET: 'UNSET'> |
layer | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
max_card | LiteralNumericValue: 1 (43e39098-ace4-47c4-8f1c-1df1986063e2) |
max_value | None |
min_card | LiteralNumericValue: 1 (95d6a6e5-6442-408d-afb2-d8f7a24c5f56) |
min_value | None |
name | owner |
null_value | None |
parent | "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Property "owner" (9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51) |
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
type | StringType "String" (b2f035e6-78c8-4dfd-99f0-bf4a40ea3e81) |
uuid | 9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcb2f715b0> |
visibility | <VisibilityKind.UNSET: 'UNSET'> |
visible_on_diagrams | (Empty list) |
xtype | org.polarsys.capella.core.data.information:Property |
As you can see the kind
attribute is UNSET
. That means this property isn’t modelled as an association. An example for a COMPOSITION
:
[6]:
prop = model.sa.all_classes.by_name("Trajectory").properties[0]
prop
[6]:
waypoints (org.polarsys.capella.core.data.information:Property)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
association | Backreference to Association - omitted: can be slow to compute. Display this property directly to show. |
constraints | (Empty list) |
default_value | None |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
is_abstract | False |
is_derived | False |
is_ordered | False |
is_part_of_key | False |
is_read_only | False |
is_static | False |
is_unique | False |
kind | <AggregationKind.COMPOSITION: 'COMPOSITION'> |
layer | SystemAnalysis "System Analysis" (79d35fe7-f172-4405-b499-48aef545148a) |
max_card | LiteralNumericValue: * (57d146cf-6e40-42f4-9413-1cd0240d1431) |
max_value | None |
min_card | LiteralNumericValue: 1 (1df38231-5a0a-4c47-8c99-96119b8b8af8) |
min_value | None |
name | waypoints |
null_value | None |
parent | "Trajectory" (c3c96805-d6f6-4092-b9f4-df7970651cdc) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Property "waypoints" (424efd65-eaa9-4220-b61b-fb3340dbc19a) |
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
type | "Waypoint" (c89849fd-0643-4708-a4da-74c9ea9ca7b1) |
uuid | 424efd65-eaa9-4220-b61b-fb3340dbc19a |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcb2f70320> |
visibility | <VisibilityKind.UNSET: 'UNSET'> |
visible_on_diagrams | (Empty list) |
xtype | org.polarsys.capella.core.data.information:Property |
The role name is exposed as the name
attribute of the property. As you can see the only navigable role is waypoints
and its min- and max-card are also accessible. The Class
can be accessed via the type
attribute and the association
is there to receive information about the incoming role/property. Let’s have a look at it:
[7]:
prop.association
[7]:
waypoint association (org.polarsys.capella.core.data.information:Association)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
layer | SystemAnalysis "System Analysis" (79d35fe7-f172-4405-b499-48aef545148a) |
members |
|
name | waypoint association |
navigable_members |
|
parent | DataPkg "Data" (814464a3-3278-48eb-b66c-e255ed11afa8) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for Association "waypoint association" (3d738685-83e8-45f9-ade2-d5bcc6de1a0c) |
requirements | (Empty list) |
roles |
|
sid | |
summary | Find waypoints and you will finish consistently. |
traces | (Empty list) |
uuid | 3d738685-83e8-45f9-ade2-d5bcc6de1a0c |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcb2f71910> |
visible_on_diagrams |
|
xtype | org.polarsys.capella.core.data.information:Association |
An Association
has navigable_members
which can be at most 2 (the source and target roles) and a source_role
. Whenever the is Navigable
option is ticked in Capella the property element will appear underneath the target Class
of the Association
.
3.2. Example 2: Complex Values (instances of Classes)¶
Capella allows to create Complex Values which have the type of a class model element. Complex Values can contain Value Parts that instantiate the properties of the class. Let’s have a look at Harry’s wand:
[8]:
model.la.data_package.packages[0].complex_values[0]
[8]:
Harry's Wand (org.polarsys.capella.core.data.information.datavalue:ComplexValue)
applied_property_value_groups | (Empty list) |
---|---|
applied_property_values | (Empty list) |
constraints | (Empty list) |
description | |
diagrams | (Empty list) |
filtering_criteria | (Empty list) |
layer | LogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b) |
name | Harry's Wand |
parent | DataPkg "Wand Objects" (880af86d-6fac-4fba-a559-2fffd036fa9a) |
progress_status | NOT_SET |
property_value_groups | (Empty list) |
property_value_packages | (Empty list) |
property_values | (Empty list) |
pvmt | Property Value Management for ComplexValue "Harry's Wand" (3a467d68-f53c-4d66-9d32-fe032a8cb2c5) |
requirements | (Empty list) |
sid | |
summary | |
traces | (Empty list) |
type | "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040) |
uuid | 3a467d68-f53c-4d66-9d32-fe032a8cb2c5 |
validation | <capellambse.extensions.validation._validate.ElementValidation object at 0x72bcb2f73410> |
value_parts |
|
visible_on_diagrams | (Empty list) |
xtype | org.polarsys.capella.core.data.information.datavalue:ComplexValue |
and let’s see what wood Harry’s wand is made of:
[9]:
from capellambse.metamodel.information import datavalue
instance = model.la.data_package.packages[0].complex_values[0]
for value_part in instance.value_parts:
value = value_part.value.value
if isinstance(value, datavalue.EnumerationLiteral):
value = value.name
print(
f"The {value_part.referenced_property.name} of {instance.name} is {value}."
)
The owner of Harry's Wand is Harry Potter.
The core of Harry's Wand is Pheonix Feather.
The wood of Harry's Wand is Holly.