conformance_finding.alc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. log("Elements in metamodel: " + set_to_string(elems))
  45. while (set_len(elems) > 0):
  46. elem = set_pop(elems)
  47. // log("Check " + elem)
  48. if (bool_not(is_edge(model["metamodel"]["model"][elem]))):
  49. if (element_neq(node_element, read_root())):
  50. log("Multiple nodes detected!")
  51. return False!
  52. node_element = elem
  53. else:
  54. // Is an edge, but might be the inheritance link...
  55. log("type: " + read_type(model["metamodel"], elem))
  56. if (read_type(model["metamodel"], elem) != "Inheritance"):
  57. // Is not the inheritance link
  58. if (element_neq(edge_element, read_root())):
  59. log("Multiple edges detected")
  60. return False!
  61. edge_element = elem
  62. if (bool_or(element_eq(node_element, read_root()), element_eq(edge_element, read_root()))):
  63. log("Not both node and edge detected")
  64. return False!
  65. // Now we have bot an edge_element and node_element of the metamodel
  66. // Now just trivially bind all elements!
  67. elems = dict_keys(model["model"])
  68. while (set_len(elems) > 0):
  69. elem = set_pop(elems)
  70. if (is_edge(model["model"][elem])):
  71. retype(model, elem, edge_element)
  72. else:
  73. retype(model, elem, node_element)
  74. // 3) (optional) verify that the mapping is correct with conformance checking
  75. // TODO
  76. return True!