|
|
@@ -443,6 +443,73 @@ Element function extractPivots(final_matches : Element, pivots: Element, tf_er_t
|
|
|
set_add(pivots[pivotOutName], getName(tf_er_model,host_match_node))
|
|
|
return 0
|
|
|
|
|
|
+Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element, tf_er_transformation:Element, tf_er_model:Element ):
|
|
|
+ //loop over all matches
|
|
|
+ Integer match_index
|
|
|
+ match_index = 0
|
|
|
+ Element rhs_plabels
|
|
|
+ Element rhs_plabel
|
|
|
+ Element rhs_action
|
|
|
+ String new_TypeName
|
|
|
+ String new_MetaTypeName
|
|
|
+ Element rhs_to_host //keep this mapping, so that we know wich nodes in the hostmodel new edges connect
|
|
|
+ Element lhs_match_keys
|
|
|
+ Element lhs_match_key
|
|
|
+ Element host_match_node
|
|
|
+ Element lhs_match
|
|
|
+ Integer source_plabel
|
|
|
+ Integer destination_plabel
|
|
|
+ while (match_index < read_nr_out(final_matches)):
|
|
|
+ lhs_match = list_read(final_matches, match_index)
|
|
|
+ match_index = match_index +1
|
|
|
+ //get set of plables
|
|
|
+ rhs_plabels = dict_keys(plabel_to_rhsnode)
|
|
|
+ //loop trough every node in the match
|
|
|
+ lhs_match_keys = dict_keys(lhs_match)
|
|
|
+ rhs_to_host = create_node()
|
|
|
+ while (read_nr_out(lhs_match_keys) > 0):
|
|
|
+ lhs_match_key = set_pop(lhs_match_keys)
|
|
|
+ host_match_node = lhs_match[lhs_match_key]["hn"]
|
|
|
+ if set_in(rhs_plabels, lhs_match_key): //if node matches plabel with rhs
|
|
|
+ //run function
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[lhs_match_key]), "function")
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
+ rhs_action(tf_er_model, host_match_node)
|
|
|
+ dict_add(rhs_to_host, lhs_match_key, host_match_node)
|
|
|
+ //remove key from rhs_plabels
|
|
|
+ set_remove(rhs_plabels, lhs_match_key)
|
|
|
+ else: // if node doesn't match plabel with rhs
|
|
|
+ model_delete_element(tf_er_model, getName(tf_er_model, host_match_node))
|
|
|
+ //for each remaining rhs-key (it is not in the match, so should be added)
|
|
|
+ while (read_nr_out(rhs_plabels) > 0):
|
|
|
+ rhs_plabel = set_pop(rhs_plabels)
|
|
|
+ //get type and metatype
|
|
|
+ new_TypeName = string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4)
|
|
|
+ new_MetaTypeName = getMetaTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel])
|
|
|
+ //if it is a node, than we can simply add it
|
|
|
+ if (new_MetaTypeName == "Class"):
|
|
|
+ host_match_node = instantiate_node(tf_er_model, new_TypeName, "")
|
|
|
+ //run the function
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
+ rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
+ elif (new_MetaTypeName == "l5"):
|
|
|
+ //if it is an edge, we can only add it of source and edge exist, else we have to store the edge and get it later
|
|
|
+ source_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
+ destination_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
+ if(bool_and(dict_in(rhs_to_host, source_plabel), dict_in(rhs_to_host, destination_plabel))):
|
|
|
+ rhs_action = instantiate_link(tf_er_model, new_TypeName, "", getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel])), getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel])))
|
|
|
+ //run function
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
+ rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
+ else:
|
|
|
+ //TODO this is wrong and might cause an infinite loop
|
|
|
+ set_add(rhs_plabels, rhs_plabel)
|
|
|
+ else:
|
|
|
+ log("unsupported metatype in rhs")
|
|
|
+ return 0
|
|
|
+
|
|
|
Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
//TODO support for multiple ruleTypes
|
|
|
|
|
|
@@ -497,69 +564,9 @@ Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Elemen
|
|
|
rhs_node = read_edge_dst(set_pop(post2ram))
|
|
|
rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
|
|
|
dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
|
|
|
- //loop over all matches
|
|
|
- Integer match_index
|
|
|
- match_index = 0
|
|
|
- Element rhs_plabels
|
|
|
- Element rhs_action
|
|
|
- String new_TypeName
|
|
|
- String new_MetaTypeName
|
|
|
- Element rhs_to_host //keep this mapping, so that we know wich nodes in the hostmodel new edges connect
|
|
|
- Element lhs_match_keys
|
|
|
- Element lhs_match_key
|
|
|
- Element host_match_node
|
|
|
- Element lhs_match
|
|
|
- Integer source_plabel
|
|
|
- Integer destination_plabel
|
|
|
- while (match_index < read_nr_out(final_matches)):
|
|
|
- lhs_match = list_read(final_matches, match_index)
|
|
|
- match_index = match_index +1
|
|
|
- //get set of plables
|
|
|
- rhs_plabels = dict_keys(plabel_to_rhsnode)
|
|
|
- //loop trough every node in the match
|
|
|
- lhs_match_keys = dict_keys(lhs_match)
|
|
|
- rhs_to_host = create_node()
|
|
|
- while (read_nr_out(lhs_match_keys) > 0):
|
|
|
- lhs_match_key = set_pop(lhs_match_keys)
|
|
|
- host_match_node = lhs_match[lhs_match_key]["hn"]
|
|
|
- if set_in(rhs_plabels, lhs_match_key): //if node matches plabel with rhs
|
|
|
- //run function
|
|
|
- rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[lhs_match_key]), "function")
|
|
|
- rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
- rhs_action(tf_er_model, host_match_node)
|
|
|
- dict_add(rhs_to_host, lhs_match_key, host_match_node)
|
|
|
- //remove key from rhs_plabels
|
|
|
- set_remove(rhs_plabels, lhs_match_key)
|
|
|
- else: // if node doesn't match plabel with rhs
|
|
|
- model_delete_element(tf_er_model, getName(tf_er_model, host_match_node))
|
|
|
- //for each remaining rhs-key (it is not in the match, so should be added)
|
|
|
- while (read_nr_out(rhs_plabels) > 0):
|
|
|
- rhs_plabel = set_pop(rhs_plabels)
|
|
|
- //get type and metatype
|
|
|
- new_TypeName = string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4)
|
|
|
- new_MetaTypeName = getMetaTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel])
|
|
|
- //if it is a node, than we can simply add it
|
|
|
- if (new_MetaTypeName == "Class"):
|
|
|
- host_match_node = instantiate_node(tf_er_model, new_TypeName, "")
|
|
|
- //run the function
|
|
|
- rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
- rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
- rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
- elif (new_MetaTypeName == "l5"):
|
|
|
- //if it is an edge, we can only add it of source and edge exist, else we have to store the edge and get it later
|
|
|
- source_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
- destination_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
- if(bool_and(dict_in(rhs_to_host, source_plabel), dict_in(rhs_to_host, destination_plabel))):
|
|
|
- rhs_action = instantiate_link(tf_er_model, new_TypeName, "", getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel])), getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel])))
|
|
|
- //run function
|
|
|
- rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
- rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
- rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
- else:
|
|
|
- //TODO this is wrong and might cause an infinite loop
|
|
|
- set_add(rhs_plabels, rhs_plabel)
|
|
|
- else:
|
|
|
- log("unsupported metatype in rhs")
|
|
|
+
|
|
|
+ rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
|
|
|
+
|
|
|
return pivots
|
|
|
|
|
|
Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
|