conformance_finding.alc 3.0 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("Difference: " + 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. Element nodes
  44. Element edges
  45. nodes = allInstances(model["metamodel"], "Class")
  46. edges = allInstances(model["metamodel"], "Association")
  47. if (set_len(nodes) > 1):
  48. log("Got nodes: " + set_to_string(nodes))
  49. log("Multiple nodes detected!")
  50. return False!
  51. elif (set_len(edges) > 1):
  52. log("Got edges: " + set_to_string(edges))
  53. log("Multiple edges detected!")
  54. return False!
  55. elif (set_len(nodes) != 1):
  56. log("No node found!")
  57. return False!
  58. elif (set_len(edges) != 1):
  59. log("No edge found!")
  60. return False!
  61. else:
  62. node_element = set_pop(nodes)
  63. edge_element = set_pop(edges)
  64. log("Found node: " + node_element)
  65. log("Found edge: " + edge_element)
  66. // Now we have bot an edge_element and node_element of the metamodel
  67. // Now just trivially bind all elements!
  68. elems = dict_keys(model["model"])
  69. while (set_len(elems) > 0):
  70. elem = set_pop(elems)
  71. if (is_edge(model["model"][elem])):
  72. retype(model, elem, edge_element)
  73. else:
  74. retype(model, elem, node_element)
  75. // 3) (optional) verify that the mapping is correct with conformance checking
  76. // TODO
  77. return True!