conformance_finding.alc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. log("Searching for model type!")
  32. result = True
  33. // TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
  34. // and it makes the assumption that SCD is the M3 level...
  35. // First find the name of the edge and node elements
  36. Element elems
  37. String elem
  38. String node_element
  39. String edge_element
  40. elems = dict_keys(model["metamodel"]["model"])
  41. while (set_len(elems) > 0):
  42. elem = set_pop(elems)
  43. if (bool_not(is_edge(model["metamodel"]["model"][elem]))):
  44. node_element = elem
  45. else:
  46. // Is an edge, but might be the inheritance link...
  47. if (read_type(model["metamodel"], elem) != "Inheritance"):
  48. // Is not the inheritance link
  49. edge_element = elem
  50. // Now we have bot an edge_element and node_element of the metamodel
  51. // Now just trivially bind all elements!
  52. elems = dict_keys(model["model"])
  53. while (set_len(elems) > 0):
  54. elem = set_pop(elems)
  55. if (is_edge(elem)):
  56. retype(model, elem, edge_element)
  57. else:
  58. retype(model, elem, node_element)
  59. // 3) (optional) verify that the mapping is correct with conformance checking
  60. // TODO
  61. // If not, set the result to read_root()
  62. return result!