12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- include "primitives.alh"
- include "object_operations.alh"
- include "typing.alh"
- Boolean function find_type_mapping(model : Element):
- // Finds a correct type mapping for the provided model (with partial type mapping)
- // We go through several phases:
- // 1) remove elements from type mapping that are not in the model or metamodel
- // 2) find a mapping based on the current partial mapping
- // 3) (optional) verify that the mapping is correct with conformance checking
- // Returns True if the type mapping was altered
- // Start of with some initialization
- Element tm
- Element elems
- String elem
- tm = get_type_mapping_as_dict(model)
- // 1) remove elements from type mapping that are not in the model or metamodel
- elems = dict_keys(tm)
- while (set_len(elems) > 0):
- elem = set_pop(elems)
- if (bool_not(dict_in(model["model"], elem))):
- // Remove the key, as the model does not contain the element anymore
- dict_delete(tm, elem)
- else:
- if (bool_not(dict_in(model["metamodel"]["model"], tm[elem]))):
- // Remove the key, as the metamodel does not contain the type anymore
- dict_delete(tm, elem)
-
- // 2) find a mapping based on the current partial mapping, but only if it is not yet complete
- // TODO this must be expanded for other things than trivial metamodels!
- if (dict_len(model["model"]) > dict_len(tm)):
- // TODO for now, this only returns something for a simple case, where the MM has one edge, and one node
- // and it makes the assumption that SCD is the M3 level...
- // First find the name of the edge and node elements
- Element elems
- String elem
- String node_source_element
- String node_target_element
- String edge_element
- Element nodes
- Element edges
- nodes = allInstances(model["metamodel"], "Class")
- edges = allInstances(model["metamodel"], "Association")
- if (bool_and(set_len(edges) == 1, set_len(nodes) == 1)):
- // Simple allocation: this seems like conformance bottom
- node_source_element = set_pop(nodes)
- node_target_element = node_source_element
- edge_element = set_pop(edges)
- elif (bool_and(set_len(edges) == 1, set_len(nodes) == 2)):
- // Simple allocation: this seems like a type mapping
- // Make sure to check that the edge goes from one node to the other!
- edge_element = set_pop(edges)
- node_source_element = readAssociationSource(model["metamodel"], edge_element)
- node_target_element = readAssociationDestination(model["metamodel"], edge_element)
- if (value_eq(node_source_element, node_target_element)):
- log("Could not automatically deduce mapping in a trivial way!")
- return False!
- else:
- log("Could not automatically deduce mapping in a trivial way!")
- return False!
- // Now we have both an edge_element and node_element of the metamodel
- // Now just trivially bind all elements!
- elems = dict_keys(model["model"])
- while (set_len(elems) > 0):
- elem = set_pop(elems)
- if (bool_and(is_edge(model["model"][elem]), read_nr_out(model["model"][elem]) == 0)):
- // An edge, and there is always exactly one, so type
- retype(model, elem, edge_element)
- // The source and target are ALWAYS typed as well!
- retype(model, readAssociationSource(model, elem), node_source_element)
- retype(model, readAssociationDestination(model, elem), node_target_element)
- elif (node_source_element == node_target_element):
- // A node, and we are sure that there is only one
- if (is_edge(model["model"][elem])):
- retype(model, elem, edge_element)
- else:
- retype(model, elem, node_source_element)
- // 3) (optional) verify that the mapping is correct with conformance checking
- // TODO
-
- return True!
|