Browse Source

fixed verifying attributes of instance model: now an attribute is mandatory if all nodes of the same type have the same attribute

Lucas Heer 7 years ago
parent
commit
e9e9031aff
3 changed files with 18 additions and 14 deletions
  1. 1 0
      sketchUI/graphics_edge_item.py
  2. 16 13
      verifier.py
  3. 1 1
      wrappers/modelverse_SCCD.py

+ 1 - 0
sketchUI/graphics_edge_item.py

@@ -6,6 +6,7 @@ as well as the modelverse edge id.
 from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem
 from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem
 from sketchUI.graphics_node_item import GraphicsNodeItem
 from sketchUI.graphics_node_item import GraphicsNodeItem
 
 
+
 class GraphicsEdgeItem(QGraphicsLineItem):
 class GraphicsEdgeItem(QGraphicsLineItem):
     def __init__(self, from_item, to_item, edge_id=None):
     def __init__(self, from_item, to_item, edge_id=None):
         #type: (GraphicsNodeItem, GraphicsNodeItem) -> None
         #type: (GraphicsNodeItem, GraphicsNodeItem) -> None

+ 16 - 13
verifier.py

@@ -94,35 +94,38 @@ class Verifier(object):
                         attrs.append(attr)
                         attrs.append(attr)
         return attrs_of_types
         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:
             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):
     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
         Helper for attribute check that returns True if the attribute attr_key of type node_type is mandatory by
         looking at all example models.
         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:
         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):
     def verify_attributes(self):
         """
         """
         1. For every attribute key of a typed node in the instance model, there must be a corresponding
         1. For every attribute key of a typed node in the instance model, there must be a corresponding
         attribute key in some example model.
         attribute key in some example model.
         2. An attribute for a type is mandatory if it occurs in every 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
         # Check attribute keys for every node in instance model

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Sat Apr 28 14:38:25 2018
+Date:   Wed May  2 10:07:40 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server