conformance_finding.alc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "typing.alh"
  4. Boolean function find_type_mapping(model : Element):
  5. // Finds a correct type mapping for the provided model (with partial type mapping)
  6. // We go through several phases:
  7. // 1) remove elements from type mapping that are not in the model or metamodel
  8. // 2) find a mapping based on the current partial mapping
  9. // 3) (optional) verify that the mapping is correct with conformance checking
  10. // Returns True if the type mapping was altered
  11. // Start of with some initialization
  12. Element tm
  13. Element elems
  14. String elem
  15. tm = get_type_mapping_as_dict(model)
  16. // 1) remove elements from type mapping that are not in the model or metamodel
  17. elems = dict_keys(tm)
  18. while (set_len(elems) > 0):
  19. elem = set_pop(elems)
  20. if (bool_not(dict_in(model["model"], elem))):
  21. // Remove the key, as the model does not contain the element anymore
  22. dict_delete(tm, elem)
  23. else:
  24. if (bool_not(dict_in(model["metamodel"]["model"], tm[elem]))):
  25. // Remove the key, as the metamodel does not contain the type anymore
  26. dict_delete(tm, elem)
  27. // 2) find a mapping based on the current partial mapping, but only if it is not yet complete
  28. // TODO this must be expanded for other things than trivial metamodels!
  29. if (dict_len(model["model"]) > dict_len(tm)):
  30. // log("Model is incompletely typed!")
  31. // log("Model has: " + set_to_string(dict_keys(model["model"])))
  32. // log("Type mapping has: " + set_to_string(dict_keys(tm)))
  33. // log("Missing: " + set_to_string(set_difference(dict_keys(model["model"]), dict_keys(tm))))
  34. // TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
  35. // and it makes the assumption that SCD is the M3 level...
  36. // First find the name of the edge and node elements
  37. Element elems
  38. String elem
  39. String node_element
  40. String edge_element
  41. node_element = read_root()
  42. edge_element = read_root()
  43. elems = dict_keys(model["metamodel"]["model"])
  44. while (set_len(elems) > 0):
  45. elem = set_pop(elems)
  46. if (bool_not(is_edge(model["metamodel"]["model"][elem]))):
  47. if (element_neq(node_element, read_root())):
  48. return False!
  49. node_element = elem
  50. else:
  51. // Is an edge, but might be the inheritance link...
  52. if (read_type(model["metamodel"], elem) != "Inheritance"):
  53. // Is not the inheritance link
  54. if (element_neq(edge_element, read_root())):
  55. return False!
  56. edge_element = elem
  57. if (bool_or(element_eq(node_element, read_root()), element_eq(edge_element, read_root()))):
  58. return False!
  59. // Now we have bot an edge_element and node_element of the metamodel
  60. // Now just trivially bind all elements!
  61. elems = dict_keys(model["model"])
  62. while (set_len(elems) > 0):
  63. elem = set_pop(elems)
  64. if (is_edge(elem)):
  65. retype(model, elem, edge_element)
  66. else:
  67. retype(model, elem, node_element)
  68. // 3) (optional) verify that the mapping is correct with conformance checking
  69. // TODO
  70. return True!