include "primitives.alh" include "constructors.alh" include "object_operations.alh" include "library.alh" include "conformance_scd.alh" include "io.alh" include "metamodels.alh" include "modelling.alh" Element function petrinet_transformation(root: Element): // Create A transformation model for petrinets (useful for testing) ////////////////////////////////// //initialise an empty transformation model for petrinet Element my_model my_model = instantiate_model(root["PetriNets_MTransformation"]) define_inheritance(my_model, "l3") dict_add(root, "transf_petrinet_fire", my_model) //////////////////////////// // root node instantiate_node(my_model, "Transformation", "PetrinetFire") instantiate_attribute(my_model, "PetrinetFire", "name", "PetriNetFire") //////////////////////////// // rule: find transitions //rule: find_transitions log("find_transitions") instantiate_node(my_model, "Rule", "find_transitions") instantiate_attribute(my_model, "find_transitions", "name", "find_transitions") instantiate_attribute(my_model, "find_transitions", "precedence", 1) //connect to transformation instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "find_transitions") //precondition: lhs_precondition log("lhs_precondition") instantiate_node(my_model, "Precondition","lhs_precondition") //connect to rule instantiate_link(my_model, "lhs", "", "find_transitions", "lhs_precondition") //Transition_LHS: lhs_find_all log("lhs_find_all") instantiate_node(my_model, "Transition_LHS","lhs_find_all") instantiate_attribute(my_model, "lhs_find_all", "plabel", 1) //connect to rule instantiate_link(my_model, "pre2ram", "", "lhs_precondition", "lhs_find_all") //precondition: nac_precondition log("nac_precondition") instantiate_node(my_model, "Precondition","nac_precondition") //connect to rule instantiate_link(my_model, "nac", "", "find_transitions", "nac_precondition") //Transition_LHS: nac_transition_place_before log("nac_transition_place_before") instantiate_node(my_model, "Transition_LHS","nac_transition_place_before") instantiate_attribute(my_model, "nac_transition_place_before", "plabel", 1) //connect to rule instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_transition_place_before") //Place_LHS: nac_place_before log("nac_place_before") instantiate_node(my_model, "Place_LHS","nac_place_before") instantiate_attribute(my_model, "nac_place_before", "plabel", 2) instantiate_attribute(my_model, "nac_place_before", "tokens", "lambda x: sum([1 for i in x.out if i.weight 0): v_m = set_pop(keys_m) // Filter out anonymous objects typename = getName(model["metamodel"], dict_read_node(model["type_mapping"], model["model"][v_m])) if (bool_not(string_startswith(v_m, "__"))): output(((" " + v_m) + " : ") + typename) elif (cmd == "read"): output("Element to read?") cmd = input() if (dict_in(model["model"], cmd)): Element read_elem read_elem = model["model"][cmd] metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem) output("Name: " + cmd) output("Type: " + getName(model["metamodel"], metamodel_element_pn)) if (is_edge(read_elem)): output("Source: " + getName(model, read_edge_src(read_elem))) output("Destination: " + getName(model, read_edge_dst(read_elem))) if (cast_v2s(read_elem) != "None"): output("Value: " + cast_v2s(read_elem)) output("Defines attributes:") attr_list_pn = getInstantiatableAttributes(model, read_elem) attr_keys_pn = dict_keys(attr_list_pn) while (0 < read_nr_out(attr_keys_pn)): attr_key_pn = set_pop(attr_keys_pn) output((((" " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn]))) output("Attributes:") attr_list_pn = getAttributeList(model, cmd) attr_keys_pn = dict_keys(attr_list_pn) while (0 < read_nr_out(attr_keys_pn)): attr_key_pn = set_pop(attr_keys_pn) output(((((" " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn))) else: output("Unknown element; aborting") elif (cmd == "verify"): output(conformance_scd(model)) elif (cmd == "types"): Element keys_t keys_t = dict_keys(model["metamodel"]["model"]) output("List of types:") String v_t while (read_nr_out(keys_t) > 0): v_t = set_pop(keys_t) if (bool_not(string_startswith(v_t, "__"))): output(string_join((" " + v_t) + " : ", getName(model["metamodel"]["metamodel"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t])))) elif (cmd == "retype"): output("Element to retype?") String elementname elementname = input() if (dict_in(model["model"], elementname)): output("New type") typename = input() if (dict_in(model["metamodel"]["model"], typename)): // OK, do the retyping // First try removing the previous type if it exists dict_delete(model["type_mapping"], model["model"][elementname]) // Now add the new type dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename]) output("Retyped!") else: output("Unknown type; aborting") else: output("Unknown element; aborting") elif (cmd == "switch"): bottom = bool_not(bottom) Element tmp_model tmp_model = model model = other_metamodel other_metamodel = tmp_model if (bottom): // The type mapping we are using is probably not complete for our model // so we completely recreate it from the model we have. output("Switching to conformance bottom mode!") generate_bottom_type_mapping(model) else: // We already switched the models and such, so we are already done! output("Switching to linguistic metamodel!") elif (bool_and(dict_in(pn_operations(), cmd), bool_not(bottom))): // A model-specific operation, so execute that one Element specific_op specific_op = dict_read(pn_operations(), cmd) specific_op(model) else: output("Unknown command; aborting") output("Use command 'help' to get a list of available commands") Element function initial_prompt(): output("Welcome to the Model Management Interface, running live on the Modelverse!") output("Use 'help' command for a list of possible commands") String command Element root Element metamodel String name Element my_model String mm_name root = create_metamodels() while (True): output("Please give your command.") command = input() if (command == "help"): output("Currently no model is loaded, so your operations are limited to:") output(" new -- Create a new model and save it for future use") output(" load -- Load a previously made model") output(" rename -- Rename a previously made model") output(" delete -- Delete a previously made model") output(" list -- Show a list of all stored models") output(" help -- Show a list of possible commands") elif (command == "new"): output("Metamodel to instantiate?") mm_name = input() if (dict_in(root, mm_name)): output("Name of model?") name = input() if (dict_in(root, name)): output("Model exists; aborting") else: my_model = instantiate_model(root[mm_name]) dict_add(root, name, my_model) petrinet_loaded(my_model) else: output("Unknown metamodel; aborting") elif (command == "load"): output("Model to load?") name = input() if (dict_in(root, name)): my_model = root[name] petrinet_loaded(my_model) else: output("Model not found; aborting") elif (command == "list"): Element keys String m_menu_list keys = dict_keys(root) output("Found models:") while (read_nr_out(keys) > 0): m_menu_list = set_pop(keys) output(((" " + m_menu_list) + " : ") + reverseNameLookup(root, root[m_menu_list]["metamodel"])) elif (command == "delete"): output("Model to delete?") name = input() if (dict_in(root, name)): dict_delete(root, name) output("Deleted!") else: output("Model not found; aborting") elif (command == "rename"): output("Old name?") String old_name old_name = input() if (dict_in(root, old_name)): output("New name?") String new_name new_name = input() if (dict_in(root, new_name)): output("Model exists; aborting") else: dict_add(root, new_name, root[old_name]) dict_delete(root, old_name) output("Rename complete!") else: output("Model not found; aborting") else: output("Command not recognized, use 'help' for a list of possible commands") Void function main(): //initial_prompt() Element root root = create_metamodels() petrinet_transformation(root) log("done") return