Pārlūkot izejas kodu

combined lhs and nac to create set of final matches

tpinna 10 gadi atpakaļ
vecāks
revīzija
2ec7789bcf
1 mainītis faili ar 47 papildinājumiem un 11 dzēšanām
  1. 47 11
      integration/code/pn_interface.alc

+ 47 - 11
integration/code/pn_interface.alc

@@ -251,7 +251,7 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
 	Integer pattern_size
 	pattern_size = SearchState["pattern_size"]
 	if pattern_size == list_len(current_match):
-		set_add(SearchState["matches"], SearchState["curmatch"])
+		list_append(SearchState["matches"], SearchState["curmatch"])
 		return SearchState
 
 	//feasability checks
@@ -368,29 +368,65 @@ Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Elem
 	return SearchState["matches"]
 
 Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
+	//TODO support for multiple ruleTypes
 	
 	//find LHS
-	
-	log("=== FINDING LHS")
+	//TODO if no 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"))
 	tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
-	log(string_join(cast_i2s(list_len(tf_er_lhs)), " matches found"))
-	
-	//find NAC
+	Integer nr_of_lhs_matches
+	nr_of_lhs_matches = list_len(tf_er_lhs)
+	//log(string_join(cast_i2s(list_len(tf_er_lhs)), " matches found"))
 	
-	log("=== FINDING NAC")
+	//find NACs if at least one lhs is found (otherwise not needed)
+	Integer nr_of_nac_matches
+	nr_of_nac_matches = 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"))
-	tf_er_nac = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac)), tf_er_model)
-	log(string_join(cast_i2s(list_len(tf_er_nac)), " matches found"))
-	
+	tf_er_nac = create_node()
+	if(nr_of_lhs_matches > 0): //TODO unless there is no lhs, then we might have situations were we just want to prevent nodes from spawning
+		tf_er_nac = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
+		//TODO make this a loop
+		tf_er_nac = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac)), tf_er_model)
+		nr_of_nac_matches = list_len(tf_er_nac)
+		//log(string_join(cast_i2s(list_len(tf_er_nac)), " matches found"))
+		
+	//remove from lhs matches that share a node with a nac match
+	//TODO join lhs and nacs to conclusive amount of matches
+	Element final_matches
+	final_matches = create_node()
+	Element lhs_match
+	Element nac_match
+	Element lhs_match_keys
+	Element lhs_match_key
+	Boolean allow_match
+	Integer nac_index
+	while(list_len(tf_er_lhs) > 0):
+		lhs_match = set_pop(tf_er_lhs)
+		allow_match=True
+		nac_index = 0
+		while(bool_and(nac_index < read_nr_out(tf_er_nac), allow_match)):
+			nac_match = list_read(tf_er_nac, nac_index)
+			nac_index = nac_index + 1 
+			lhs_match_keys = dict_keys(lhs_match)
+			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):
+					if (element_eq(nac_match[lhs_match_key]["hn"],lhs_match[lhs_match_key]["hn"])):
+						allow_match = False
+		if (allow_match):
+			list_append(final_matches, lhs_match)
+	log(string_join("number of allowed matches: ", cast_i2s(list_len(final_matches))))
+
+	//TODO RHS
+
 	return 0
 
 Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
 	//create a list of all rules	
 	Element tf_tf_rules
 	tf_tf_rules = allInstances(tf_tf_transformation, dict_read(dict_read(dict_read(tf_tf_transformation, "metamodel"), "model"), "Rule"))
+	//TODO give order to syntax
 	//execute rules in random order 
 	Element tf_tf_rule
 	while (integer_lt(0, read_nr_out(tf_tf_rules))):