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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.