Browse Source

Added yet some more "primitives" and fixed minor problems with matching function

Yentl Van Tendeloo 8 years ago
parent
commit
42631635bb

BIN
bootstrap/bootstrap.m.gz


+ 56 - 0
bootstrap/primitives.alc

@@ -209,3 +209,59 @@ Element function set_to_string(s : Element):
 	result = result + "}"
 	result = result + "}"
 
 
 	return result!
 	return result!
+
+Element function dict_to_string(d : Element):
+	String result
+	Element keys
+	Element key
+
+	result = "{"
+	keys = dict_keys(d)
+
+	while (read_nr_out(keys)):
+		key = set_pop(keys)
+		result = result + cast_v2s(key)
+		result = result + ": "
+		result = result + cast_v2s(dict_read_node(d, key))
+		result = result + ", "
+	
+	result = result + "}"
+
+	return result!
+
+Element function set_overlap(sa : Element, sb : Element):
+	Element result
+	Integer i
+
+	if (read_nr_out(sa) > read_nr_out(sb)):
+		// Pick the smallest set to iterate over, so switch if sa is not the smallest
+		result = sa
+		sa = sb
+		sb = result
+
+	result = create_node()
+	i = 0
+
+	// Iterate over each element of sa and only add it to the result if it is also in sb
+	while (i < read_nr_out(sa)):
+		if (set_in(sb, read_edge_dst(read_out(sa, i)))):
+			// Shared between both
+			set_add(result, read_edge_dst(read_out(sa, i)))
+		i = i + 1
+
+	return result!
+
+Element function dict_copy(d : Element):
+	String result
+	Element keys
+	Element key
+
+	result = create_node()
+	keys = dict_keys(d)
+
+	while (read_nr_out(keys)):
+		key = set_pop(keys)
+		dict_add(result, key, dict_read_node(d, key))
+
+	return result!
+

+ 44 - 5
bootstrap/transform.alc

@@ -57,10 +57,49 @@ Element function make_matching_schedule(LHS_model : Element):
 
 
 Element function get_possible_bindings(host_model : Element, LHS_model : Element, current_element : String, map : Element):
 Element function get_possible_bindings(host_model : Element, LHS_model : Element, current_element : String, map : Element):
 	Element options
 	Element options
+	String src_label
+	String dst_label
+	String typename
+	String original_typename
 
 
-	output("FIND BINDING")
+	log("FIND BINDING")
 	options = create_node()
 	options = create_node()
 
 
+	typename = reverseKeyLookup(LHS_model["metamodel"]["model"], dict_read_node(LHS_model["type_mapping"], LHS_model["model"][current_element]))
+	original_typename = string_substr(typename, 4, string_len(typename))
+	log("Found type: " + typename)
+	log("Original type: " + original_typename)
+
+	if (is_edge(LHS_model["model"][current_element])):
+		// Is an edge, so check for already bound source/target
+		src_label = read_attribute(LHS_model, reverseKeyLookup(LHS_model["model"], read_edge_src(LHS_model["model"][current_element])), "label")
+		dst_label = read_attribute(LHS_model, reverseKeyLookup(LHS_model["model"], read_edge_dst(LHS_model["model"][current_element])), "label")
+
+		if (bool_and(set_in(dict_keys(map), src_label), set_in(dict_keys(map), dst_label))):
+			// Source and destination are bound
+			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
+			options = set_overlap(options, allIncomingAssociationInstances(host_model, map[src_label], original_typename))
+
+		elif (set_in(dict_keys(map), src_label)):
+			// Source is bound
+			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
+
+		elif (set_in(dict_keys(map), dst_label)):
+			// Destination is bound
+			options = allIncomingAssociationInstances(host_model, map[src_label], original_typename)
+
+		else:
+			// Neither is bound, so just get all of them
+			log("ERROR: unbound source/target for association!")
+			return create_node()!
+	else:
+		// Is a node, so check for already bound incoming/outgoing
+		options = allInstances(host_model, original_typename)
+
+	// Filter out duplicate matches from the map
+
+	// Filter out based on local constraints
+
 	return options!
 	return options!
 
 
 Element function match(host_model : Element, LHS_model : Element):
 Element function match(host_model : Element, LHS_model : Element):
@@ -88,15 +127,15 @@ Element function match(host_model : Element, LHS_model : Element):
 
 
 		while (read_nr_out(mappings) > 0):
 		while (read_nr_out(mappings) > 0):
 			map = set_pop(mappings)
 			map = set_pop(mappings)
-			log("In context " + set_to_string(map))
+			log("In context " + dict_to_string(map))
 			options = get_possible_bindings(host_model, LHS_model, current_element, map)
 			options = get_possible_bindings(host_model, LHS_model, current_element, map)
 			log("Found options " + set_to_string(options))
 			log("Found options " + set_to_string(options))
 
 
 			while (read_nr_out(options) > 0):
 			while (read_nr_out(options) > 0):
 				option = set_pop(options)
 				option = set_pop(options)
-				new_map = set_copy(map)
-				dict_add(new_map, current_element, option)
-				log(" --> adding mapping " + set_to_string(new_map))
+				new_map = dict_copy(map)
+				dict_add(new_map, read_attribute(LHS_model, current_element, "label"), option)
+				log(" --> adding mapping " + dict_to_string(new_map))
 				set_add(new_mappings, new_map)
 				set_add(new_mappings, new_map)
 
 
 		mappings = new_mappings
 		mappings = new_mappings

+ 3 - 0
interface/HUTN/includes/primitives.alh

@@ -98,3 +98,6 @@ Boolean function has_input()
 Element function list_pop(lst : Element, index : Integer)
 Element function list_pop(lst : Element, index : Integer)
 Element function set_copy(set : Element)
 Element function set_copy(set : Element)
 String function set_to_string(set : Element)
 String function set_to_string(set : Element)
+String function dict_to_string(dict : Element)
+Element function set_overlap(sa : Element, sb : Element)
+Element function dict_copy(dict : Element)