conformance_finding.alc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. log("Got type mapping: " + cast_e2s(tm))
  17. // 1) remove elements from type mapping that are not in the model or metamodel
  18. elems = dict_keys(tm)
  19. while (set_len(elems) > 0):
  20. elem = set_pop(elems)
  21. if (bool_not(dict_in(model["model"], elem))):
  22. // Remove the key, as the model does not contain the element anymore
  23. dict_delete(tm, elem)
  24. else:
  25. if (bool_not(dict_in(model["metamodel"]["model"], tm[elem]))):
  26. // Remove the key, as the metamodel does not contain the type anymore
  27. dict_delete(tm, elem)
  28. // 2) find a mapping based on the current partial mapping, but only if it is not yet complete
  29. if (dict_len(model["model"]) > dict_len(tm)):
  30. // TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
  31. // and it makes the assumption that SCD is the M3 level...
  32. // First find the name of the edge and node elements
  33. Element elems
  34. String elem
  35. String node_element
  36. String edge_element
  37. node_element = read_root()
  38. edge_element = read_root()
  39. elems = dict_keys(model["metamodel"]["model"])
  40. while (set_len(elems) > 0):
  41. elem = set_pop(elems)
  42. if (bool_not(is_edge(model["metamodel"]["model"][elem]))):
  43. if (element_neq(node_element, read_root())):
  44. return False!
  45. node_element = elem
  46. else:
  47. // Is an edge, but might be the inheritance link...
  48. if (read_type(model["metamodel"], elem) != "Inheritance"):
  49. // Is not the inheritance link
  50. if (element_neq(edge_element, read_root())):
  51. return False!
  52. edge_element = elem
  53. if (bool_or(element_eq(node_element, read_root()), element_eq(edge_element, read_root()))):
  54. return False!
  55. // Now we have bot an edge_element and node_element of the metamodel
  56. // Now just trivially bind all elements!
  57. elems = dict_keys(model["model"])
  58. while (set_len(elems) > 0):
  59. elem = set_pop(elems)
  60. if (is_edge(elem)):
  61. retype(model, elem, edge_element)
  62. else:
  63. retype(model, elem, node_element)
  64. // 3) (optional) verify that the mapping is correct with conformance checking
  65. // TODO
  66. return True!