Changeset 807


Ignore:
Timestamp:
09/11/12 16:45:51 (12 years ago)
Author:
pharms
Message:
  • improved node equality comparison to match the principle of lexical, syntactical and semantical node equality. As a result, more condensed task trees are created.
Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityTest.java

    r655 r807  
    66 
    77/** 
    8  * TODO comment 
    9  *  
    10  * @version $Revision: $ $Date: 15.08.2012$ 
    11  * @author 2012, last modified by $Author: pharms$ 
     8 * @author Patrick Harms 
    129 */ 
    1310public class NodeEqualityTest { 
    1411 
    1512    /** 
    16      * TODO: comment 
    1713     * 
    1814     */ 
  • trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRuleTest.java

    r655 r807  
    55import org.junit.Test; 
    66 
     7import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 
    78import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 
    89import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 
     
    1415 
    1516/** 
    16  * <p> 
    17  * TODO comment 
    18  * </p> 
    19  *  
    20  * @version $Revision: $ $Date: 16.08.2012$ 
    21  * @author 2012, last modified by $Author: pharms$ 
     17 * @author Patrick Harms 
    2218 */ 
    2319public class SequenceComparisonRuleTest { 
    2420 
    2521    /** 
    26      * <p> 
    27      * TODO: comment 
    28      * </p> 
    29      * 
     22     *  
    3023     */ 
    3124    @Test 
     
    4538         
    4639        ISequence sequence1 = treeNodeFactory.createNewSequence(); 
    47         assertEquals(NodeEquality.LEXICALLY_EQUAL, rule.compare(sequence1, sequence1)); 
     40        assertEquals(NodeEquality.IDENTICAL, rule.compare(sequence1, sequence1)); 
    4841 
    4942        ISequence sequence2 = treeNodeFactory.createNewSequence(); 
     
    5447        treeBuilder.addChild(sequence1, task1); 
    5548         
    56         assertNull(rule.compare(sequence1, sequence2)); 
    57         assertNull(rule.compare(sequence2, sequence1)); 
     49        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence2)); 
     50        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence1)); 
    5851         
    5952        treeBuilder.addChild(sequence2, task1); 
     
    6457        treeBuilder.addChild(sequence1, task2); 
    6558         
    66         assertNull(rule.compare(sequence1, sequence2)); 
    67         assertNull(rule.compare(sequence2, sequence1)); 
     59        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence2)); 
     60        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence1)); 
    6861         
    6962        treeBuilder.addChild(sequence2, task2); 
     
    7669        treeBuilder.addChild(sequence3, task1); 
    7770         
    78         assertNull(rule.compare(sequence1, sequence3)); 
    79         assertNull(rule.compare(sequence3, sequence1)); 
     71        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence3)); 
     72        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence3, sequence1)); 
     73        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence3)); 
     74        assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence3, sequence2)); 
     75 
     76        ISelection selection = treeNodeFactory.createNewSelection(); 
     77        assertNull(rule.compare(sequence1, selection)); 
     78        assertNull(rule.compare(selection, sequence1)); 
     79        assertNull(rule.compare(sequence2, selection)); 
     80        assertNull(rule.compare(selection, sequence2)); 
     81        assertNull(rule.compare(sequence3, selection)); 
     82        assertNull(rule.compare(selection, sequence3)); 
    8083    } 
    8184 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/IterationComparisonRule.java

    r655 r807  
    4141 *   </tr> 
    4242 *   <tr> 
     43 *     <td>an iteration with a selection of syntactically equal children</td> 
     44 *     <td>an iteration with a selection of syntactically equal children that are all syntactically 
     45 *     equal to the selection of children of iteration 1</td> 
     46 *     <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 
     47 *   </tr> 
     48 *   <tr> 
    4349 *     <td>an iteration with a selection of semantically equal children</td> 
    4450 *     <td>an iteration with a child that is semantically equal to the children of the child 
    4551 *     selection of iteration 1</td> 
     52 *     <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 
     53 *   </tr> 
     54 *   <tr> 
     55 *     <td>an iteration with a selection of semantically equal children</td> 
     56 *     <td>an iteration with a selection of semantically equal children that are all semantically 
     57 *     equal to the selection of children of iteration 1</td> 
    4658 *     <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 
    4759 *   </tr> 
     
    8092        } 
    8193 
     94        if (node1 == node2) { 
     95            return NodeEquality.IDENTICAL; 
     96        } 
     97 
    8298        // if both iterations do not have children, they are equal although this doesn't make sense 
    8399        if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 
    84             return NodeEquality.IDENTICAL; 
     100            return NodeEquality.LEXICALLY_EQUAL; 
     101        } 
     102        else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { 
     103            return NodeEquality.UNEQUAL; 
    85104        } 
    86105 
     
    102121 
    103122        if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 
    104             return nodeEquality; 
     123            // prevent, that identical is returned, because the iterations itself are not identical 
     124            // although the iterated tasks are 
     125            if (nodeEquality == NodeEquality.IDENTICAL) { 
     126                return NodeEquality.LEXICALLY_EQUAL; 
     127            } 
     128            else { 
     129                return nodeEquality; 
     130            } 
    105131        } 
    106132 
     
    115141    /** 
    116142     * <p> 
    117      * compares two task tree nodes. One of them must be a selection of at least semantically 
    118      * equal children. The other one can be any task tree node. The method returns a node equality 
    119      * that is not <code>NodeEquality.UNEQUAL</code> if the other node is at least semantically 
    120      * equal to the children of the selection. It returns more concrete equalities, if the 
    121      * equality between the other node and the children of the selection is more concrete. 
     143     * compares two task tree nodes. One of them must be a selection, the other one can be any task 
     144     * tree node. The method returns a node equality that is not <code>NodeEquality.UNEQUAL</code> 
     145     * if the other node is at least semantically equal to the children of the selection. It 
     146     * returns more concrete equalities, if the equality between the other node and the children 
     147     * of the selection is more concrete. 
    122148     * </p>  
    123149     *  
     
    144170        } 
    145171 
    146         NodeEquality lessConcreteEqualityForAllComparisons = NodeEquality.IDENTICAL; 
     172        // Iterations, where one has a selection and the other one not can at most be syntactically 
     173        // equal but not identical 
     174        NodeEquality commonDenominatorForAllComparisons = NodeEquality.SYNTACTICALLY_EQUAL; 
    147175 
    148176        for (ITaskTreeNode child : selection.getChildren()) { 
    149177            NodeEquality nodeEquality = mRuleManager.applyRules(node, child); 
    150178 
    151             if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 
     179            if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) 
     180            { 
    152181                return NodeEquality.UNEQUAL; 
    153182            } 
    154             else if (!lessConcreteEqualityForAllComparisons.isAtLeast(nodeEquality)) { 
    155                 lessConcreteEqualityForAllComparisons = nodeEquality; 
    156             } 
     183             
     184            commonDenominatorForAllComparisons = 
     185                commonDenominatorForAllComparisons.getCommonDenominator(nodeEquality); 
    157186        } 
    158187 
    159         return lessConcreteEqualityForAllComparisons; 
     188        return commonDenominatorForAllComparisons; 
    160189    } 
    161190 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEquality.java

    r655 r807  
    9090        } 
    9191    } 
     92 
     93    /** 
     94     * <p> 
     95     * returns the common denominator of this node equality and the provided one. I.e. if one 
     96     * equality is e.g. syntactical and the other one only semantical, then semantical is returned. 
     97     * </p> 
     98     * 
     99     * @param equality the equality, to compare this with 
     100     * @return 
     101     */ 
     102    public NodeEquality getCommonDenominator(NodeEquality otherEquality) { 
     103        if (this.isAtLeast(otherEquality)) { 
     104            return otherEquality; 
     105        } 
     106        else if (otherEquality.isAtLeast(this)) { 
     107            return this; 
     108        } 
     109        else { 
     110            return NodeEquality.UNEQUAL; 
     111        } 
     112    } 
    92113} 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java

    r725 r807  
    3333        mRuleIndex = new ArrayList<NodeComparisonRule>(); 
    3434        mRuleIndex.add(new NodeIdentityRule()); 
     35        mRuleIndex.add(new GUIEventTaskComparisonRule()); 
     36        mRuleIndex.add(new EventTaskComparisonRule()); 
    3537        mRuleIndex.add(new IterationComparisonRule(this)); 
    3638        mRuleIndex.add(new SequenceComparisonRule(this)); 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeIdentityRule.java

    r655 r807  
    2222    @Override 
    2323    public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    24         if ((node1 == node2) || ((node1 != null) && (node1.equals(node2)))) { 
     24        if (node1 == node2) { 
    2525            return NodeEquality.IDENTICAL; 
    2626        } 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java

    r655 r807  
    77 * <p> 
    88 * this node comparison rule is capable of comparing selections. If both selections do not have 
    9  * children, they are treated as lexically equal. If they have the same number of children other 
    10  * than 0 and all these children are lexically equal, then the selections are lexically equal. 
    11  * They are syntactically equal, if each child of both selections is syntactically equal to any 
    12  * other child. The rule can not compare semantical equality if the nodes are not at least 
    13  * syntactically equal and returns null, if it can not decide this. 
     9 * children, they are treated as identical. If they have children, each child of both selections 
     10 * is compared to each child of the respective other selection. The resulting equality is the most 
     11 * concrete one of all these comparisons. I.e. if all children are at least lexically equal, then 
     12 * the selections are lexically equal. If all children are at least syntactically equal, then the 
     13 * selections are syntactically equal. If all children are at least semantically equal, then the 
     14 * selections are semantically equal. If only one of the selections has children, then the 
     15 * selections are unequal. 
    1416 * </p> 
    1517 *  
     
    4648        } 
    4749 
    48         // if both sequences do not have children, they are equal although this doesn't make sense 
     50        if (node1 == node2) { 
     51            return NodeEquality.IDENTICAL; 
     52        } 
     53 
     54        // if both sequences do not have children, they are identical. If only one of them has 
     55        // children, they are unequal. 
    4956        if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 
    5057            return NodeEquality.LEXICALLY_EQUAL; 
    5158        } 
     59        else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { 
     60            return NodeEquality.UNEQUAL; 
     61        } 
    5262 
    53         // Selections are syntactically equal, if they have children, which are all syntactically 
    54         // equal. 
    55         // They are lexically equals, if they have the same number and order of lexically equal 
    56         // children 
    57         boolean lexicallyEqual = node1.getChildren().size() == node2.getChildren().size(); 
     63        NodeEquality selectionEquality = NodeEquality.LEXICALLY_EQUAL; 
    5864 
    59         for (int i = 0; i < node1.getChildren().size(); i++) { 
    60             ITaskTreeNode child1 = node1.getChildren().get(i); 
    61             boolean foundLexicallyEqualChild = false; 
    62  
    63             for (int j = 0; j < node2.getChildren().size(); j++) { 
    64                 ITaskTreeNode child2 = node2.getChildren().get(j); 
    65  
    66                 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 
    67  
    68                 if (!nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 
    69                     return null; 
    70                 } 
    71                 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 
    72                     foundLexicallyEqualChild = true; 
     65        // compare each child of selection one with each child of selection two 
     66        NodeEquality childEquality; 
     67        NodeEquality currentEquality; 
     68        for (ITaskTreeNode child1 : node1.getChildren()) { 
     69            childEquality = null; 
     70            for (ITaskTreeNode child2 : node2.getChildren()) { 
     71                currentEquality = mRuleManager.applyRules(child1, child2); 
     72                if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 
     73                    if (childEquality == null) { 
     74                        childEquality = currentEquality; 
     75                    } 
     76                    else { 
     77                        childEquality = childEquality.getCommonDenominator(currentEquality); 
     78                    } 
    7379                } 
    7480            } 
    75  
    76             // if we compare two children at the same position and if they are lexically equal 
    77             // then it can be further expected, that the selections are lexically equal 
    78             lexicallyEqual &= foundLexicallyEqualChild; 
     81             
     82            if (childEquality != null) { 
     83                selectionEquality = selectionEquality.getCommonDenominator(childEquality); 
     84            } 
     85            else { 
     86                return NodeEquality.UNEQUAL; 
     87            } 
    7988        } 
    8089 
    81         if (lexicallyEqual) { 
    82             return NodeEquality.LEXICALLY_EQUAL; 
     90        // compare each child of selection two with each child of selection one 
     91        for (ITaskTreeNode child2 : node2.getChildren()) { 
     92            childEquality = null; 
     93            for (ITaskTreeNode child1 : node1.getChildren()) { 
     94                currentEquality = mRuleManager.applyRules(child1, child2); 
     95                if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 
     96                    if (childEquality == null) { 
     97                        childEquality = currentEquality; 
     98                    } 
     99                    else { 
     100                        childEquality = childEquality.getCommonDenominator(currentEquality); 
     101                    } 
     102                } 
     103            } 
     104             
     105            if (childEquality != null) { 
     106                selectionEquality = selectionEquality.getCommonDenominator(childEquality); 
     107            } 
     108            else { 
     109                return NodeEquality.UNEQUAL; 
     110            } 
    83111        } 
    84         else { 
    85             return NodeEquality.SYNTACTICALLY_EQUAL; 
    86         } 
     112 
     113        return selectionEquality; 
    87114    } 
     115 
    88116} 
  • trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRule.java

    r655 r807  
    4444        } 
    4545 
     46        if (node1 == node2) { 
     47            return NodeEquality.IDENTICAL; 
     48        } 
     49 
    4650        // if both sequences do not have children, they are equal although this doesn't make sense 
    4751        if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 
     
    4953        } 
    5054 
    51         //  
    5255        if (node1.getChildren().size() != node2.getChildren().size()) { 
    53             return null; 
     56            return NodeEquality.UNEQUAL; 
    5457        } 
    5558 
     59        NodeEquality resultingEquality = NodeEquality.LEXICALLY_EQUAL; 
    5660        for (int i = 0; i < node1.getChildren().size(); i++) { 
    5761            ITaskTreeNode child1 = node1.getChildren().get(i); 
     
    6064            NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 
    6165 
    62             if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 
    63                 return null; 
     66            if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) { 
     67                return NodeEquality.UNEQUAL; 
    6468            } 
     69             
     70            resultingEquality = resultingEquality.getCommonDenominator(nodeEquality); 
    6571        } 
    6672 
    67         return NodeEquality.LEXICALLY_EQUAL; 
     73        return resultingEquality; 
    6874    } 
    6975 
Note: See TracChangeset for help on using the changeset viewer.