Working on conformance

This commit is contained in:
Andrei Bondarenko 2021-08-23 15:11:25 +02:00
parent 8ddb5ac12b
commit 3c1d1fa002
9 changed files with 386 additions and 9 deletions

View file

@ -1,5 +1,6 @@
from state.base import State, UUID
from services.bottom.V0 import Bottom
from services.primitives.integer_type import Integer
def bootstrap_type(type_name: str, python_type: str, scd_root: UUID, model_root: UUID, state: State):
@ -10,7 +11,9 @@ def bootstrap_type(type_name: str, python_type: str, scd_root: UUID, model_root:
scd_node, = bottom.read_outgoing_elements(scd_root, "Class") # retrieve type
bottom.create_edge(class_node, scd_node, "Morphism") # create morphism link
# set min_cardinality
min_c_node = bottom.create_node(1)
min_c_model = bottom.create_node()
Integer(min_c_model, state).create(1)
min_c_node = bottom.create_node(str(min_c_model))
bottom.create_edge(model_root, min_c_node, f"{type_name}.lower_cardinality")
min_c_link = bottom.create_edge(class_node, min_c_node)
bottom.create_edge(model_root, min_c_link, f"{type_name}.lower_cardinality_link")
@ -19,7 +22,9 @@ def bootstrap_type(type_name: str, python_type: str, scd_root: UUID, model_root:
bottom.create_edge(min_c_node, scd_node, "Morphism")
bottom.create_edge(min_c_link, scd_link, "Morphism")
# set max_cardinality
max_c_node = bottom.create_node(1)
max_c_model = bottom.create_node()
Integer(max_c_model, state).create(1)
max_c_node = bottom.create_node(str(max_c_model))
bottom.create_edge(model_root, max_c_node, f"{type_name}.upper_cardinality")
max_c_link = bottom.create_edge(class_node, max_c_node)
bottom.create_edge(model_root, max_c_link, f"{type_name}.upper_cardinality_link")
@ -28,7 +33,7 @@ def bootstrap_type(type_name: str, python_type: str, scd_root: UUID, model_root:
bottom.create_edge(max_c_node, scd_node, "Morphism")
bottom.create_edge(max_c_link, scd_link, "Morphism")
# set constraint
constraint_node = bottom.create_node(f"isinstance(read_value(x),{python_type})")
constraint_node = bottom.create_node(f"isinstance(read_value(element),{python_type})")
bottom.create_edge(model_root, constraint_node, f"{type_name}.constraint")
constraint_link = bottom.create_edge(class_node, constraint_node)
bottom.create_edge(model_root, constraint_link, f"{type_name}.constraint_link")

View file

@ -110,9 +110,10 @@ def bootstrap_scd(state: State) -> UUID:
assoc_t_l_c_edge = add_edge_element("Association_target_lower_cardinality", assoc_edge, integer_node)
assoc_t_u_c_edge = add_edge_element("Association_target_upper_cardinality", assoc_edge, integer_node)
# # bootstrap primitive types
# # order is important, integer must be first
bootstrap_integer_type(mcl_root, integer_type_root, state)
bootstrap_boolean_type(mcl_root, boolean_type_root, state)
bootstrap_float_type(mcl_root, float_type_root, state)
bootstrap_integer_type(mcl_root, integer_type_root, state)
bootstrap_string_type(mcl_root, string_type_root, state)
bootstrap_type_type(mcl_root, type_type_root, state)
# # ATTRIBUTE ATTRIBUTES, assign 'name' and 'optional' attributes to all AttributeLinks
@ -156,6 +157,11 @@ def bootstrap_scd(state: State) -> UUID:
m_name, m_opt = add_attribute_attributes("Association_target_upper_cardinality", assoc_t_u_c_edge)
String(m_name, state).create("target_upper_cardinality")
Boolean(m_opt, state).create(True)
# # Make Element abstract
abs_model = bottom.create_node()
abs_node = add_node_element(f"Element.abstract", str(abs_model))
abs_edge = add_edge_element(f"Element.abstract_link", element_node, abs_node)
Boolean(abs_model, state).create(True)
# create phi(SCD,SCD) to type MCL with itself
@ -245,6 +251,9 @@ def bootstrap_scd(state: State) -> UUID:
add_mcl_morphism("Association_source_upper_cardinality.optional", "Boolean")
add_mcl_morphism("Association_target_lower_cardinality.optional", "Boolean")
add_mcl_morphism("Association_target_upper_cardinality.optional", "Boolean")
add_mcl_morphism("Element.abstract", "Boolean")
# Class_abstract
add_mcl_morphism("Element.abstract_link", "Class_abstract")
return mcl_root