|
@@ -39,24 +39,35 @@ Boolean function find_type_mapping(model : Element):
|
|
|
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")
|
|
|
|
|
|
+ // Simple allocation: this seems like conformance bottom
|
|
|
if (bool_and(set_len(edges) == 1, set_len(nodes) == 1)):
|
|
|
- // Simple allocation: this seems like conformance bottom
|
|
|
+ String node_source_element
|
|
|
+ String edge_element
|
|
|
+
|
|
|
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!
|
|
|
+ elems = dict_keys(model["model"])
|
|
|
+ while (set_len(elems) > 0):
|
|
|
+ elem = set_pop(elems)
|
|
|
+ if (is_edge(model["model"][elem])):
|
|
|
+ retype(model, elem, edge_element)
|
|
|
+ else:
|
|
|
+ retype(model, elem, node_source_element)
|
|
|
+ return True!
|
|
|
+
|
|
|
+ // Simple allocation: this seems like a traceability model or so
|
|
|
+ // Make sure to check that the edge goes from one node to the other!
|
|
|
+ if (bool_and(set_len(edges) == 1, set_len(nodes) == 2)):
|
|
|
+ String node_target_element
|
|
|
+ String node_source_element
|
|
|
+ String edge_element
|
|
|
+
|
|
|
edge_element = set_pop(edges)
|
|
|
node_source_element = readAssociationSource(model["metamodel"], edge_element)
|
|
|
node_target_element = readAssociationDestination(model["metamodel"], edge_element)
|
|
@@ -65,33 +76,83 @@ Boolean function find_type_mapping(model : Element):
|
|
|
log("Could not automatically deduce mapping in a trivial way!")
|
|
|
return False!
|
|
|
|
|
|
- else:
|
|
|
- log("Could not automatically deduce mapping in a trivial way!")
|
|
|
- log("Model: " + set_to_string(dict_keys(model["model"])))
|
|
|
- log("TM: " + set_to_string(dict_keys(tm)))
|
|
|
- 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)
|
|
|
+ elems = dict_keys(model["model"])
|
|
|
+ while (set_len(elems) > 0):
|
|
|
+ elem = set_pop(elems)
|
|
|
|
|
|
- if (node_source_element == node_target_element):
|
|
|
- if (is_edge(model["model"][elem])):
|
|
|
+ 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)
|
|
|
- else:
|
|
|
- retype(model, elem, node_source_element)
|
|
|
- elif (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)
|
|
|
+ // 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)
|
|
|
+
|
|
|
+ return True!
|
|
|
+
|
|
|
+ // Simple allocation: this seems like a dictionary model or so
|
|
|
+ log("Edges: " + cast_string(set_len(edges)))
|
|
|
+ log("Nodes: " + cast_string(set_len(nodes)))
|
|
|
+ if (bool_and(set_len(edges) == 2, set_len(nodes) == 3)):
|
|
|
+ log("Potential dictionary...")
|
|
|
+ String main_edge
|
|
|
+ String small_edge
|
|
|
+ main_edge = set_pop(edges)
|
|
|
+ small_edge = set_pop(edges)
|
|
|
+
|
|
|
+ log("Main edge: " + main_edge)
|
|
|
+ log("Small edge: " + small_edge)
|
|
|
+ log("Main source: " + readAssociationSource(model["metamodel"], main_edge))
|
|
|
+ log("Main destination: " + readAssociationDestination(model["metamodel"], main_edge))
|
|
|
+ log("Small source: " + readAssociationSource(model["metamodel"], small_edge))
|
|
|
+ log("Small destination: " + readAssociationDestination(model["metamodel"], small_edge))
|
|
|
+
|
|
|
+ if (readAssociationSource(model["metamodel"], main_edge) == small_edge):
|
|
|
+ // Switch both
|
|
|
+ log("Switch")
|
|
|
+ String tmp
|
|
|
+ tmp = main_edge
|
|
|
+ main_edge = small_edge
|
|
|
+ small_edge = tmp
|
|
|
+
|
|
|
+ if (readAssociationSource(model["metamodel"], small_edge) == main_edge):
|
|
|
+ log("Dictionary working...")
|
|
|
+ String origin
|
|
|
+ String value
|
|
|
+ String key
|
|
|
+ String middle_edge
|
|
|
+ origin = readAssociationSource(model["metamodel"], main_edge)
|
|
|
+ value = readAssociationDestination(model["metamodel"], main_edge)
|
|
|
+ key = readAssociationDestination(model["metamodel"], small_edge)
|
|
|
+
|
|
|
+ if (bool_and(bool_and(origin != value, origin != key), value != key)):
|
|
|
+ // All three nodes are different, meaning that we are complete and have identified a simple mapping!
|
|
|
+
|
|
|
+ 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 with no outgoing links, meaning that it is the small_edge
|
|
|
+ retype(model, elem, small_edge)
|
|
|
+
|
|
|
+ // Source is main_edge and target is key
|
|
|
+ middle_edge = readAssociationSource(model, elem)
|
|
|
+ retype(model, middle_edge, main_edge)
|
|
|
+ log("Type " + middle_edge + " : " + main_edge)
|
|
|
+ retype(model, readAssociationDestination(model, elem), key)
|
|
|
+ log("Type " + readAssociationDestination(model, elem) + " : " + key)
|
|
|
+
|
|
|
+ // The main_edge goes from root to the value
|
|
|
+ retype(model, readAssociationSource(model, middle_edge), origin)
|
|
|
+ log("Type " + readAssociationSource(model, middle_edge) + " : " + origin)
|
|
|
+ retype(model, readAssociationDestination(model, middle_edge), value)
|
|
|
+ log("Type " + readAssociationDestination(model, middle_edge) + " : " + value)
|
|
|
+
|
|
|
+ return True!
|
|
|
+
|
|
|
+ log("Could not automatically deduce mapping in a trivial way!")
|
|
|
+ log("Model: " + set_to_string(dict_keys(model["model"])))
|
|
|
+ log("TM: " + set_to_string(dict_keys(tm)))
|
|
|
+ return False!
|
|
|
|
|
|
- // 3) (optional) verify that the mapping is correct with conformance checking
|
|
|
- // TODO
|
|
|
-
|
|
|
return True!
|