primitive.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from state.base import State, UUID
  2. from services.bottom.V0 import Bottom
  3. from services.primitives.integer_type import Integer
  4. def bootstrap_type(type_name: str, python_type: str, scd_root: UUID, model_root: UUID, state: State):
  5. bottom = Bottom(state)
  6. # create class
  7. class_node = bottom.create_node() # create class node
  8. bottom.create_edge(model_root, class_node, type_name) # attach to model
  9. scd_node, = bottom.read_outgoing_elements(scd_root, "Class") # retrieve type
  10. bottom.create_edge(class_node, scd_node, "Morphism") # create morphism link
  11. # set min_cardinality
  12. min_c_model = bottom.create_node()
  13. Integer(min_c_model, state).create(1)
  14. min_c_node = bottom.create_node(str(min_c_model))
  15. bottom.create_edge(model_root, min_c_node, f"{type_name}.lower_cardinality")
  16. min_c_link = bottom.create_edge(class_node, min_c_node)
  17. bottom.create_edge(model_root, min_c_link, f"{type_name}.lower_cardinality_link")
  18. scd_node, = bottom.read_outgoing_elements(scd_root, "Integer")
  19. scd_link, = bottom.read_outgoing_elements(scd_root, "Class_lower_cardinality")
  20. bottom.create_edge(min_c_node, scd_node, "Morphism")
  21. bottom.create_edge(min_c_link, scd_link, "Morphism")
  22. # set max_cardinality
  23. max_c_model = bottom.create_node()
  24. Integer(max_c_model, state).create(1)
  25. max_c_node = bottom.create_node(str(max_c_model))
  26. bottom.create_edge(model_root, max_c_node, f"{type_name}.upper_cardinality")
  27. max_c_link = bottom.create_edge(class_node, max_c_node)
  28. bottom.create_edge(model_root, max_c_link, f"{type_name}.upper_cardinality_link")
  29. scd_node, = bottom.read_outgoing_elements(scd_root, "Integer")
  30. scd_link, = bottom.read_outgoing_elements(scd_root, "Class_upper_cardinality")
  31. bottom.create_edge(max_c_node, scd_node, "Morphism")
  32. bottom.create_edge(max_c_link, scd_link, "Morphism")
  33. # set constraint
  34. constraint_node = bottom.create_node(f"isinstance(read_value(element),{python_type})")
  35. bottom.create_edge(model_root, constraint_node, f"{type_name}.constraint")
  36. constraint_link = bottom.create_edge(class_node, constraint_node)
  37. bottom.create_edge(model_root, constraint_link, f"{type_name}.constraint_link")
  38. scd_node, = bottom.read_outgoing_elements(scd_root, "ActionCode")
  39. scd_link, = bottom.read_outgoing_elements(scd_root, "Element_constraint")
  40. bottom.create_edge(constraint_node, scd_node, "Morphism")
  41. bottom.create_edge(constraint_link, scd_link, "Morphism")
  42. def bootstrap_type_type(scd_root: UUID, model_root: UUID, state: State):
  43. bootstrap_type("Type", "tuple", scd_root, model_root, state)
  44. def bootstrap_boolean_type(scd_root: UUID, model_root: UUID, state: State):
  45. bootstrap_type("Boolean", "bool", scd_root, model_root, state)
  46. def bootstrap_integer_type(scd_root: UUID, model_root: UUID, state: State):
  47. bootstrap_type("Integer", "int", scd_root, model_root, state)
  48. def bootstrap_float_type(scd_root: UUID, model_root: UUID, state: State):
  49. bootstrap_type("Float", "float", scd_root, model_root, state)
  50. def bootstrap_string_type(scd_root: UUID, model_root: UUID, state: State):
  51. bootstrap_type("String", "str", scd_root, model_root, state)