conformance_finding.alc 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // 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_source_element
  36. String node_target_element
  37. String edge_element
  38. Element nodes
  39. Element edges
  40. nodes = allInstances(model["metamodel"], "Class")
  41. edges = allInstances(model["metamodel"], "Association")
  42. if (bool_and(set_len(edges) == 1, set_len(nodes) == 1)):
  43. // Simple allocation: this seems like conformance bottom
  44. node_source_element = set_pop(nodes)
  45. node_target_element = node_source_element
  46. edge_element = set_pop(edges)
  47. elif (bool_and(set_len(edges) == 1, set_len(nodes) == 2)):
  48. // Simple allocation: this seems like a type mapping
  49. // Make sure to check that the edge goes from one node to the other!
  50. edge_element = set_pop(edges)
  51. node_source_element = readAssociationSource(model["metamodel"], edge_element)
  52. node_target_element = readAssociationDestination(model["metamodel"], edge_element)
  53. if (value_eq(node_source_element, node_target_element)):
  54. log("Could not automatically deduce mapping in a trivial way!")
  55. return False!
  56. else:
  57. log("Could not automatically deduce mapping in a trivial way!")
  58. return False!
  59. // Now we have both an edge_element and node_element of the metamodel
  60. // Now just trivially bind all elements!
  61. elems = dict_keys(model["model"])
  62. while (set_len(elems) > 0):
  63. elem = set_pop(elems)
  64. if (bool_and(is_edge(model["model"][elem]), read_nr_out(model["model"][elem]) == 0)):
  65. // An edge, and there is always exactly one, so type
  66. retype(model, elem, edge_element)
  67. // The source and target are ALWAYS typed as well!
  68. retype(model, readAssociationSource(model, elem), node_source_element)
  69. retype(model, readAssociationDestination(model, elem), node_target_element)
  70. elif (node_source_element == node_target_element):
  71. // A node, and we are sure that there is only one
  72. if (is_edge(model["model"][elem])):
  73. retype(model, elem, edge_element)
  74. else:
  75. retype(model, elem, node_source_element)
  76. // 3) (optional) verify that the mapping is correct with conformance checking
  77. // TODO
  78. return True!