|
|
@@ -378,6 +378,7 @@ Element function mergeLHSNAC(tf_er_lhs : Element, tf_er_nac: Element):
|
|
|
Element lhs_match_key
|
|
|
Boolean allow_match
|
|
|
Integer nac_index
|
|
|
+ Boolean plabel_match_exists
|
|
|
while(list_len(tf_er_lhs) > 0):
|
|
|
lhs_match = set_pop(tf_er_lhs)
|
|
|
allow_match=True
|
|
|
@@ -386,11 +387,15 @@ Element function mergeLHSNAC(tf_er_lhs : Element, tf_er_nac: Element):
|
|
|
nac_match = list_read(tf_er_nac, nac_index)
|
|
|
nac_index = nac_index + 1
|
|
|
lhs_match_keys = dict_keys(lhs_match)
|
|
|
+ plabel_match_exists = False //we assume that the nac prohibits all
|
|
|
while (bool_and(read_nr_out(lhs_match_keys)>0, allow_match)):
|
|
|
lhs_match_key = set_pop(lhs_match_keys)
|
|
|
if dict_in(nac_match, lhs_match_key):
|
|
|
+ plabel_match_exists = True //the assumption is disproved, which means we can continue looking
|
|
|
if (element_eq(nac_match[lhs_match_key]["hn"],lhs_match[lhs_match_key]["hn"])):
|
|
|
allow_match = False
|
|
|
+ if bool_not(plabel_match_exists): //if the assumption is not disproved, the nac prohibits all matches and no matches should remain after merge
|
|
|
+ return create_node()
|
|
|
if (allow_match):
|
|
|
list_append(final_matches, lhs_match)
|
|
|
return final_matches
|
|
|
@@ -419,6 +424,13 @@ Element function extractPivots(final_matches : Element, tf_er_transformation : E
|
|
|
dict_add(pivots, pivotOutName, create_node())
|
|
|
set_add(pivots[pivotOutName], getName(tf_er_model,lhs_match[lhs_match_key]["hn"]))
|
|
|
return 0
|
|
|
+
|
|
|
+Element function cast_set2list(sset:Element):
|
|
|
+ Element rreturnlist
|
|
|
+ rreturnlist = create_node()
|
|
|
+ while (read_nr_out(sset) > 0):
|
|
|
+ list_append(rreturnlist, set_pop(sset))
|
|
|
+ return rreturnlist
|
|
|
|
|
|
Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element, tf_er_transformation:Element, tf_er_model:Element ):
|
|
|
//loop over all matches
|
|
|
@@ -432,6 +444,7 @@ Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element,
|
|
|
Element lhs_match
|
|
|
Integer source_plabel
|
|
|
Integer destination_plabel
|
|
|
+ Integer index
|
|
|
while (read_nr_out(final_matches)>0):
|
|
|
lhs_match = set_pop(final_matches)
|
|
|
//get set of plables
|
|
|
@@ -453,39 +466,44 @@ Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element,
|
|
|
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)
|
|
|
+ rhs_plabels = cast_set2list(rhs_plabels)
|
|
|
while (read_nr_out(rhs_plabels) > 0):
|
|
|
- rhs_plabel = set_pop(rhs_plabels)
|
|
|
- //if it is a node, than we can simply add it
|
|
|
- if (bool_not(is_edge(plabel_to_rhsnode[rhs_plabel]))):
|
|
|
- host_match_node = instantiate_node(tf_er_model, string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4), "")
|
|
|
- //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])
|
|
|
- else:
|
|
|
- //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, string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4), "", 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_plabel = set_pop(rhs_plabels)
|
|
|
+ index = 0
|
|
|
+ while(index < read_nr_out(rhs_plabels)):
|
|
|
+ rhs_plabel = list_read(rhs_plabels, index)
|
|
|
+ //if it is a node, than we can simply add it
|
|
|
+ if (bool_not(is_edge(plabel_to_rhsnode[rhs_plabel]))):
|
|
|
+ host_match_node = instantiate_node(tf_er_model, string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4), "")
|
|
|
+ //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])
|
|
|
+ list_delete(rhs_plabels,index)
|
|
|
else:
|
|
|
- //TODO this is wrong and might cause an infinite loop
|
|
|
- set_add(rhs_plabels, rhs_plabel)
|
|
|
+ //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, string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4), "", 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])
|
|
|
+ list_delete(rhs_plabels,index)
|
|
|
+ else:
|
|
|
+ index = index + 1
|
|
|
|
|
|
return 0
|
|
|
|
|
|
Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
|
|
|
|
|
|
//find LHS
|
|
|
- //TODO if no lhs (is this allowed to happen?) // or empty lhs
|
|
|
Element tf_er_lhs
|
|
|
tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
|
|
|
Integer nr_of_lhs_nodes
|
|
|
nr_of_lhs_nodes = read_nr_out(tf_er_lhs)
|
|
|
+ //match lhses
|
|
|
tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
|
|
|
Integer nr_of_lhs_matches
|
|
|
nr_of_lhs_matches = list_len(tf_er_lhs)
|
|
|
@@ -495,7 +513,7 @@ Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
nr_of_nac_matches = 0
|
|
|
Element tf_er_nac
|
|
|
tf_er_nac = create_node()
|
|
|
- if(nr_of_lhs_matches > 0):
|
|
|
+ if(bool_or(nr_of_lhs_matches > 0, nr_of_lhs_nodes==0)):
|
|
|
Element tf_er_nac_
|
|
|
tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
|
|
|
Element partial_nac_matches
|
|
|
@@ -512,7 +530,6 @@ Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
return False
|
|
|
|
|
|
//remove from lhs matches that share a node with a nac match
|
|
|
- //TODO if nac is not related to match (no plabels match)
|
|
|
Element final_matches
|
|
|
final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
|
|
|
|
|
|
@@ -581,7 +598,7 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
nr_of_nac_matches = 0
|
|
|
Element tf_er_nac
|
|
|
tf_er_nac = create_node()
|
|
|
- if(nr_of_lhs_matches > 0):
|
|
|
+ if(bool_or(nr_of_lhs_matches > 0, nr_of_lhs_nodes==0)):
|
|
|
Element tf_er_nac_
|
|
|
tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
|
|
|
Element partial_nac_matches
|
|
|
@@ -598,7 +615,6 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
return False
|
|
|
|
|
|
//remove from lhs matches that share a node with a nac match
|
|
|
- //TODO if nac is not related to match (no plabels match)
|
|
|
Element final_matches
|
|
|
final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
|
|
|
|
|
|
@@ -642,7 +658,6 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
|
|
|
Element function executeRuleBlock(transformation_model : Element,hostmodel:Element, ruleblock : Element):
|
|
|
//execute the correct ruletype
|
|
|
- //TODO define decent succes_value
|
|
|
String typename
|
|
|
typename = getTypeName(transformation_model, ruleblock)
|
|
|
Boolean succes
|