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
Cannot load PVMT extension: ValueError: Provided model does not have a PropertyValuePkg
Property values are not available in this model
[1]:
<capellambse.model.MelodyModel at 0x7f48dee48b80>

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
  1. Class "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040)
  2. Class "Class 2" (1adf8097-18f9-474e-b136-6c845fc6d9e9)
  3. Class "Branch" (2b34c799-769c-42f2-8a1b-4533dba209a0)
collections

(Empty list)

complex_values

(Empty list)

constraints

(Empty list)

description
diagrams
  1. [CDB] Harry's Wand (uuid: _kqdwsF9REe2rko4oG1H6IQ)
enumerations
  1. Enumeration "Wand Core" (546cd75a-c7ac-4e07-9d2d-8a1f93d82419)
  2. Enumeration "Wand Wood" (60314ce6-bc96-4b57-8965-7187241148ae)
filtering_criteria

(Empty list)

nameData
packages
  1. DataPkg "Wand Objects" (880af86d-6fac-4fba-a559-2fffd036fa9a)
parentLogicalArchitecture "Logical Architecture" (853cb005-cba0-489b-8fe3-bb694ad4543b)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

summaryNone
traces

(Empty list)

unions

(Empty list)

uuid39e99d4a-a32c-4b70-b4b6-d03fec612e17
xtypeorg.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)

filtering_criteria

(Empty list)

literals
  1. EnumerationLiteral "Unicorn Hair" (79263437-b45d-410d-a264-8aa28d7574d1)
  2. EnumerationLiteral "Dragon Heartstring" (6bb9876c-f3a7-4d59-a6d1-819372368fa0)
  3. EnumerationLiteral "Pheonix Feather" (492fd9ca-88cb-4e9d-b92e-df14a1c1543b)
  4. EnumerationLiteral "Thestral Tail-Hair" (1e73d13b-1c26-4537-834d-e467f993befe)
nameWand Core
owned_literals
  1. EnumerationLiteral "Unicorn Hair" (79263437-b45d-410d-a264-8aa28d7574d1)
  2. EnumerationLiteral "Dragon Heartstring" (6bb9876c-f3a7-4d59-a6d1-819372368fa0)
  3. EnumerationLiteral "Pheonix Feather" (492fd9ca-88cb-4e9d-b92e-df14a1c1543b)
  4. EnumerationLiteral "Thestral Tail-Hair" (1e73d13b-1c26-4537-834d-e467f993befe)
parentDataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

subBackreference to Enumeration - omitted: can be slow to compute. Display this property directly to show.
summaryNone
superNone
traces

(Empty list)

uuid546cd75a-c7ac-4e07-9d2d-8a1f93d82419
xtypeorg.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.

Harry's Wand

[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)

is_abstractFalse
is_finalFalse
is_primitiveFalse
nameWand
owned_properties
  1. Property "owner" (9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51)
  2. Property "core" (32f70910-a1fd-4ec9-8d22-4c585ceaf7b9)
  3. Property "wood" (df884a71-e774-49e1-8aee-0a675179c647)
parentDataPkg "Data" (39e99d4a-a32c-4b70-b4b6-d03fec612e17)
progress_statusNOT_SET
properties
  1. Property "owner" (9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51)
  2. Property "core" (32f70910-a1fd-4ec9-8d22-4c585ceaf7b9)
  3. Property "wood" (df884a71-e774-49e1-8aee-0a675179c647)
  4. Property "wood" (87f356eb-c79e-4155-b297-8d733685621c)
property_value_groups

(Empty list)

property_values

(Empty list)

realizations
  1. InformationRealization "" (793520e1-acbf-4f93-a219-587840aa5a3b)
realized_byBackreference to Class - omitted: can be slow to compute. Display this property directly to show.
realized_classes
  1. Class "SpecialTwist" (0fef2887-04ce-4406-b1a1-a1b35e1ce0f3)
requirements

(Empty list)

state_machines

(Empty list)

subBackreference to Class - omitted: can be slow to compute. Display this property directly to show.
summaryNone
superClass "Branch" (2b34c799-769c-42f2-8a1b-4533dba209a0)
traces

(Empty list)

uuidc710f1c2-ede6-444e-9e2b-0ff30d7fd040
visibility<VisibilityKind.UNSET: 1>
xtypeorg.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)

associationBackreference to Association - omitted: can be slow to compute. Display this property directly to show.
constraints

(Empty list)

default_valueNone
description
diagrams

(Empty list)

filtering_criteria

(Empty list)

is_abstractFalse
is_derivedFalse
is_orderedFalse
is_part_of_keyFalse
is_read_onlyFalse
is_staticFalse
is_uniqueFalse
kind<AggregationKind.UNSET: 1>
maxNone
max_cardLiteralNumericValue "": 1 (43e39098-ace4-47c4-8f1c-1df1986063e2)
minNone
min_cardLiteralNumericValue "": 1 (95d6a6e5-6442-408d-afb2-d8f7a24c5f56)
nameowner
null_valueNone
parentClass "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

summaryNone
traces

(Empty list)

typeModelElement "String" (b2f035e6-78c8-4dfd-99f0-bf4a40ea3e81)
uuid9b1f6d9c-58d6-4e5e-a0f1-822cb5440a51
visibility<VisibilityKind.UNSET: 1>
xtypeorg.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:

Waypoint

[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)

associationBackreference to Association - omitted: can be slow to compute. Display this property directly to show.
constraints

(Empty list)

default_valueNone
description
diagrams

(Empty list)

filtering_criteria

(Empty list)

is_abstractFalse
is_derivedFalse
is_orderedFalse
is_part_of_keyFalse
is_read_onlyFalse
is_staticFalse
is_uniqueFalse
kind<AggregationKind.COMPOSITION: 4>
maxNone
max_cardLiteralNumericValue "": inf (57d146cf-6e40-42f4-9413-1cd0240d1431)
minNone
min_cardLiteralNumericValue "": 1 (1df38231-5a0a-4c47-8c99-96119b8b8af8)
namewaypoints
null_valueNone
parentClass "Trajectory" (c3c96805-d6f6-4092-b9f4-df7970651cdc)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

summaryNone
traces

(Empty list)

typeClass "Waypoint" (c89849fd-0643-4708-a4da-74c9ea9ca7b1)
uuid424efd65-eaa9-4220-b61b-fb3340dbc19a
visibility<VisibilityKind.UNSET: 1>
xtypeorg.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)

members
  1. Property "trajectory" (c0e5b34c-297e-4b3c-8957-58bbe4d36199)
namewaypoint association
navigable_members
  1. Property "waypoints" (424efd65-eaa9-4220-b61b-fb3340dbc19a)
parentDataPkg "Data" (814464a3-3278-48eb-b66c-e255ed11afa8)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

roles
  1. Property "trajectory" (c0e5b34c-297e-4b3c-8957-58bbe4d36199)
  2. Property "waypoints" (424efd65-eaa9-4220-b61b-fb3340dbc19a)
source_roleProperty "trajectory" (c0e5b34c-297e-4b3c-8957-58bbe4d36199)
summaryFind waypoints and you will finish consistently.
traces

(Empty list)

uuid3d738685-83e8-45f9-ade2-d5bcc6de1a0c
xtypeorg.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)

nameHarry's Wand
parentDataPkg "Wand Objects" (880af86d-6fac-4fba-a559-2fffd036fa9a)
progress_statusNOT_SET
property_value_groups

(Empty list)

property_values

(Empty list)

requirements

(Empty list)

summaryNone
traces

(Empty list)

typeClass "Wand" (c710f1c2-ede6-444e-9e2b-0ff30d7fd040)
uuid3a467d68-f53c-4d66-9d32-fe032a8cb2c5
value_parts
  1. ValuePart "": .applied_property_value_groups = [] .applied_property_values = [] .constraints = [] .description = '' .diagrams = [] .filtering_criteria = [] .is_abstract = False .name = 'LiteralStringValue' .parent = .progress_status = 'NOT_SET' .property_value_groups = [] .property_values = [] .requirements = [] .summary = None .traces = [] .type = .uuid = 'f7b00d88-cf53-4ae0-a0e6-bb2049b4bdea' .value = 'Harry Potter' .xtype = 'org.polarsys.capella.core.data.information.datavalue:LiteralStringValue' (c996225b-5b1f-4d53-83cb-2bc72597e8ad)
  2. ValuePart "": .applied_property_value_groups = [] .applied_property_values = [] .constraints = [] .description = '' .diagrams = [] .filtering_criteria = [] .name = 'EnumerationReference' .parent = .progress_status = 'NOT_SET' .property_value_groups = [] .property_values = [] .requirements = [] .summary = None .traces = [] .type = .uuid = '3406b669-4572-44e9-b703-1e319c350e9b' .value = .xtype = 'org.polarsys.capella.core.data.information.datavalue:EnumerationReference' (66da894f-6261-47ac-9ad7-217db04671d2)
  3. ValuePart "": .applied_property_value_groups = [] .applied_property_values = [] .constraints = [] .description = '' .diagrams = [] .filtering_criteria = [] .name = 'EnumerationReference' .parent = .progress_status = 'NOT_SET' .property_value_groups = [] .property_values = [] .requirements = [] .summary = None .traces = [] .type = .uuid = '9645687f-9485-45f0-a10b-01f8b9d24914' .value = .xtype = 'org.polarsys.capella.core.data.information.datavalue:EnumerationReference' (a10de770-c6de-43fc-8d9f-868efe5cd29f)
xtypeorg.polarsys.capella.core.data.information.datavalue:ComplexValue

and let’s see what wood Harry’s wand is made of:

[9]:
from capellambse.model.crosslayer.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.