|
@@ -63,22 +63,18 @@ class Verifier(object):
|
|
|
|
|
|
def verify_node_multiplicity(self):
|
|
|
"""
|
|
|
- A node is mandatory in the instance model if it occurs in every example model.
|
|
|
- More specifically, if a node type appears occ = [n0, n1, ... n_i] times in example model i,
|
|
|
- it needs to occur min(occ) in the instance model.
|
|
|
+ A node is mandatory in the instance model if it occurs at least once in every example model.
|
|
|
"""
|
|
|
- total_occurences = {k: [] for k in self._available_types}
|
|
|
- for node, occ_list in total_occurences.iteritems():
|
|
|
- for exm in self._example_models:
|
|
|
- num_occ = commons.count_occurences(node, exm)
|
|
|
- occ_list.append(num_occ)
|
|
|
-
|
|
|
- elem_cardinality = {k: min(v) for k, v in total_occurences.iteritems()}
|
|
|
- for el, min_occ in elem_cardinality.iteritems():
|
|
|
- if not commons.count_occurences(el, self._instance_model) >= min_occ:
|
|
|
- return {"OK": False, "error": "Node with type {} needs to occur at least {} times".format(el, min_occ)}
|
|
|
+ type_mandatory = {t:False for t in self._available_types}
|
|
|
+ for node_type,_ in type_mandatory.iteritems():
|
|
|
+ if commons.is_type_mandatory(node_type):
|
|
|
+ type_mandatory[node_type] = True
|
|
|
|
|
|
- return {"OK": True, "error": None, "affected":[]}
|
|
|
+ mandatory_types = [node_type for node_type, mandatory in type_mandatory.iteritems() if mandatory]
|
|
|
+ for mand_type in mandatory_types:
|
|
|
+ all_of_type = commons.all_nodes_with_type(self._instance_model, mand_type)
|
|
|
+ if not all_of_type:
|
|
|
+ return {"OK": False, "error": "Mandatory node of type {} not found".format(mand_type), "affected":[]}
|
|
|
|
|
|
def _get_attributes_of_all_types(self):
|
|
|
"""
|
|
@@ -123,9 +119,7 @@ class Verifier(object):
|
|
|
"""
|
|
|
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).
|
|
|
+ 2. An attribute for a type is mandatory if it occurs in every example model where the associated type node occurs.
|
|
|
"""
|
|
|
|
|
|
# Check attribute keys for every node in instance model
|