conformance_finding.alc 2.4 KB

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