|
@@ -94,35 +94,38 @@ class Verifier(object):
|
|
|
attrs.append(attr)
|
|
|
return attrs_of_types
|
|
|
|
|
|
- def _is_attribute_mandatory_in(self, model, node_type, attr_key):
|
|
|
+ def _has_attribute_key(self, model, node_id, attr_key):
|
|
|
"""
|
|
|
- Helper for attribute check that returns True if the attribute attr_key of type node_type is mandatory (i.e
|
|
|
- occurs in every node of the type) in model.
|
|
|
+ True if node with node_id has an attribute with key attr_key, False otherwise.
|
|
|
"""
|
|
|
- nodes_of_type = commons.all_nodes_with_type(model, node_type)
|
|
|
- attrs_of_type = commons.get_all_attributes_of_type(model, node_type)
|
|
|
- ctr = 0
|
|
|
- for attr in attrs_of_type:
|
|
|
+ attrs = commons.get_attributes_of_node(model, node_id)
|
|
|
+ for attr in attrs:
|
|
|
if attr.key == attr_key:
|
|
|
- ctr += 1
|
|
|
- return len(nodes_of_type) == ctr
|
|
|
+ return True
|
|
|
+ return False
|
|
|
|
|
|
def _is_attribute_mandatory(self, node_type, attr_key):
|
|
|
"""
|
|
|
Helper for attribute check that returns True if the attribute attr_key of type node_type is mandatory by
|
|
|
looking at all example models.
|
|
|
"""
|
|
|
- mand_list = []
|
|
|
+ # iterate through all example models: If every node with type node_type has the attribute with attr_key,
|
|
|
+ # it is mandatory
|
|
|
for exm in self._example_models:
|
|
|
- is_mandatory = self._is_attribute_mandatory_in(exm, node_type, attr_key)
|
|
|
- mand_list.append(is_mandatory)
|
|
|
- return all(mand_list)
|
|
|
+ nodes_of_type = commons.all_nodes_with_type(exm, node_type)
|
|
|
+ for node in nodes_of_type:
|
|
|
+ if not self._has_attribute_key(exm, node, attr_key):
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
|
|
|
def verify_attributes(self):
|
|
|
"""
|
|
|
1. For every attribute key of a typed node in the instance model, there must be a corresponding
|
|
|
attribute key in some example model.
|
|
|
2. An attribute for a type is mandatory if it occurs in every example model.
|
|
|
+ TODO: Would make more sense to change to: An attribute is mandatory if it occurs in every example model where the
|
|
|
+ associated typed node occurs (as explained in the thesis text).
|
|
|
"""
|
|
|
|
|
|
# Check attribute keys for every node in instance model
|