Browse Source

Added minimal MetaDepth conformance algorithm

Yentl Van Tendeloo 7 years ago
parent
commit
b6779694c3
1 changed files with 97 additions and 0 deletions
  1. 97 0
      models/Conformance/MetaDepth.alc

+ 97 - 0
models/Conformance/MetaDepth.alc

@@ -0,0 +1,97 @@
+include "primitives.alh"
+include "object_operations.alh"
+include "modelling.alh"
+include "library.alh"
+
+Boolean function main(model : Element):
+	// Contains three types of models: model, metamodel, and type_mapping.
+	// Each with the obvious meanings.
+
+	// Note that this is only a placeholder that serves as a proof of concept.
+	// Thus only the check for multiple inheritance is being done, which checks for attributes.
+	// A full example is given in the Modelverse's internal conformance relation.
+
+	// Find all instances of classes
+	// First, find the class types
+	Element classes
+	classes = allInstances(model, "metamodel/Class")
+
+	Element links
+	String link
+	Element type_mapping
+	type_mapping = dict_create()
+
+	Element instances
+	String instance
+	instances = allInstances(model, "type_mapping/Instance")
+	while (set_len(instances) > 0):
+		instance = set_pop(instances)
+		dict_add(type_mapping, "model/" + string_replace(instance, "type_mapping/instance_", ""), "metamodel/" + string_replace(set_pop(allAssociationDestinations(model, instance, "type_mapping/TypeLink")), "type_mapping/type_", ""))
+	
+	// Check if each attribute is there, and satisfies the constraints
+	instances = dict_keys(type_mapping)
+	while (set_len(instances) > 0):
+		instance = set_pop(instances)
+		if (read_type(model, type_mapping[instance]) == "metamodel/Class"):
+			// Got an instance of a Class
+			String type
+			Element inherits_from
+			type = type_mapping[instance]
+
+			Element outgoing_links
+			String outgoing_link
+			Element attrs
+
+			outgoing_links = allOutgoingAssociationInstances(model, instance, "")
+			attrs = dict_create()
+			while (set_len(outgoing_links) > 0):
+				outgoing_link = set_pop(outgoing_links)
+				String name
+				if (dict_in(type_mapping, outgoing_link)):
+					name = read_attribute(model, type_mapping[outgoing_link], "name")
+					dict_add(attrs, name, model["model"][readAssociationDestination(model, outgoing_link)])
+
+			// Fetch a list of attributes that should be defined
+			inherits_from = allAssociationDestinations(model, type, "metamodel/Inheritance")
+
+			String superclass
+			Element defining_attributes
+			Element last_found
+
+			Element inherits_mapping
+			inherits_mapping = dict_create()
+
+			String key
+			while (set_len(inherits_from) > 0):
+				key = set_pop(inherits_from)
+				dict_add(inherits_mapping, read_attribute(model, key, "name"), key)
+
+			Element sorted_inherits
+			sorted_inherits = list_sort(set_to_list(dict_keys(inherits_mapping)))
+
+			inherits_from = list_create()
+			while (list_len(sorted_inherits) > 0):
+				list_append(inherits_from, inherits_mapping[list_pop(sorted_inherits, 0)])
+
+			last_found = dict_create()
+			while (list_len(inherits_from) > 0):
+				superclass = list_pop_final(inherits_from)
+				defining_attributes = getInstantiatableAttributes(model, superclass, "metamodel/AttributeLink")
+				dict_update(last_found, defining_attributes)
+
+			Element keys
+			String attr
+			Element constraint
+			String result
+			keys = dict_keys(attrs)
+			while (set_len(keys) > 0):
+				attr = set_pop(keys)
+				constraint = get_func_AL_model(import_node(read_attribute(model, last_found[attr], "constraint")))
+				result = constraint(attrs[attr])
+
+				if (result != "OK"):
+					log("Conformance not OK: " + result)
+					return False!
+
+	log("Conformance OK")
+	return True!