123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- include "primitives.alh"
- include "io.alh"
- include "object_operations.alh"
- include "constructors.alh"
- include "metamodels.alh"
- include "library.alh"
- include "modelling.alh"
- Element function model_fuse(models : Element):
- Element new_model
- Element tagged_model
- String model_name
- Element model
- Element keys
- String key
- Element selected_MM
- String type
- // Read out some data first
- tagged_model = set_pop(models)
- set_add(models, tagged_model)
- new_model = instantiate_model(tagged_model[1]["metamodel"])
- // Do the iteration
- while (read_nr_out(models)):
- tagged_model = set_pop(models)
- model_name = string_join(list_read(tagged_model, 0), "/")
- model = list_read(tagged_model, 1)
- // Add all elements from 'model', but prepend it with the 'model_name'
- keys = set_to_list(dict_keys(model["model"]))
- while (read_nr_out(keys) > 0):
- key = list_pop(keys, 0)
- type = read_type(model, key)
- if (is_edge(model["model"][key])):
- String src
- String dst
- src = model_name + reverseKeyLookup(model["model"], read_edge_src(model["model"][key]))
- dst = model_name + reverseKeyLookup(model["model"], read_edge_dst(model["model"][key]))
- if (bool_and(dict_in(new_model["model"], src), dict_in(new_model["model"], dst))):
- instantiate_link(new_model, type, model_name + key, src, dst)
- else:
- list_append(keys, key)
- elif (has_value(model["model"][key])):
- instantiate_value(new_model, type, model_name + key, model["model"][key])
- else:
- instantiate_node(new_model, type, model_name + key)
- return new_model!
- Element function model_copy(src_model : Element):
- Element dst_model
- Element queue
- Element name
- String type
- dst_model = instantiate_model(src_model["metamodel"])
- queue = set_to_list(dict_keys(src_model["model"]))
- while (read_nr_out(queue) > 0):
- name = list_pop(queue, 0)
- if (is_edge(src_model["model"][name])):
- // Is an edge, so potentially queue it
- String src
- String dst
- src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
- dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
- type = read_type(src_model, name)
- if (bool_and(dict_in(dst_model["model"], src), dict_in(dst_model["model"], dst))):
- // All present, so create the link between them
- instantiate_link(dst_model, type, name, src, dst)
- else:
- list_append(queue, name)
- elif (has_value(src_model["model"][name])):
- // Has a value, so copy that as well
- type = read_type(src_model, name)
- instantiate_value(dst_model, type, name, src_model["model"][name])
- else:
- // Is a node
- type = read_type(src_model, name)
- instantiate_node(dst_model, type, name)
- return dst_model!
- Element function model_retype_on_name(model : Element, new_MM : Element, operation : String, name : String):
- String key
- String type
- Element keys
- Integer length
- keys = dict_keys(model["model"])
- length = string_len(name)
- while (read_nr_out(keys) > 0):
- key = set_pop(keys)
- if (dict_in(model["model"], key)):
- // Check if the element is still there, as a delete of a node might remove all attached links automatically
- type = read_type(model, key)
- if (operation == "+"):
- // Keep all, but augment typename
- dict_delete(model["type_mapping"], key)
- dict_add(model["type_mapping"], key, name + type)
- elif (operation == "-"):
- // Keep only if typename beginning matches and remove from typename
- if (string_startswith(type, name)):
- dict_delete(model["type_mapping"], key)
- dict_add(model["type_mapping"], key, string_substr(type, length, string_len(type)))
- else:
- model_delete_element(model, key)
- dict_delete(model, "metamodel")
- dict_add(model, "metamodel", new_MM)
- return model!
- Void function model_join(dst_model : Element, src_model : Element, retyping_key : String):
- Element queue
- Element mapping
- String name
- String type
- String src
- String dst
- queue = set_to_list(dict_keys(src_model["model"]))
- mapping = create_node()
- while (read_nr_out(queue) > 0):
- name = list_pop(queue, 0)
- type = read_type(src_model, name)
- if (is_edge(src_model["model"][name])):
- // Is an edge, so potentially queue it
- String src
- String dst
- src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
- dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
- if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
- // All present, so create the link between them
- dict_add(mapping, name, instantiate_link(dst_model, retyping_key + type, "", mapping[src], mapping[dst]))
- else:
- list_append(queue, name)
- elif (has_value(src_model["model"][name])):
- // Has a value, so copy that as well
- dict_add(mapping, name, instantiate_value(dst_model, retyping_key + type, "", src_model["model"][name]))
- else:
- // Is a node
- dict_add(mapping, name, instantiate_node(dst_model, retyping_key + type, ""))
- return!
-
- Element function model_split(src_model : Element, target_metamodel : Element, retyping_key : String):
- Element dst_model
- dst_model = instantiate_model(target_metamodel)
- Element queue
- Element mapping
- String name
- String type
- String src
- String dst
- Integer length
- String new_type
- queue = set_to_list(dict_keys(src_model["model"]))
- mapping = create_node()
- length = string_len(retyping_key)
- while (read_nr_out(queue) > 0):
- name = list_pop(queue, 0)
- type = read_type(src_model, name)
- if (string_startswith(type, retyping_key)):
- new_type = string_substr(type, length, string_len(type))
- if (is_edge(src_model["model"][name])):
- // Is an edge, so potentially queue it
- String src
- String dst
- src = reverseKeyLookup(src_model["model"], read_edge_src(src_model["model"][name]))
- dst = reverseKeyLookup(src_model["model"], read_edge_dst(src_model["model"][name]))
- if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
- // All present, so create the link between them
- dict_add(mapping, name, instantiate_link(dst_model, new_type, "", mapping[src], mapping[dst]))
- elif (bool_not(bool_or(set_in(queue, src), set_in(queue, dst)))):
- // Source/target not in the queue, but we need it to split!
- // This is an error as it indicates problems with links crossing different formalisms
- log("ERROR: source/target of link to be included is not included!")
- log("Source: " + src)
- log(" type: " + read_type(src_model, src))
- log("Destination: " + dst)
- log(" type: " + read_type(src_model, dst))
- log("For link: " + name)
- log(" type: " + type)
- return create_node()!
- else:
- // Still source or destination in the queue, so we wait for that
- list_append(queue, name)
- elif (has_value(src_model["model"][name])):
- // Has a value, so copy that as well
- dict_add(mapping, name, instantiate_value(dst_model, new_type, "", src_model["model"][name]))
- else:
- // Is a node
- dict_add(mapping, name, instantiate_node(dst_model, new_type, ""))
- return dst_model!
|