Changeset 807 for trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java
- Timestamp:
- 09/11/12 16:45:51 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java
r655 r807 7 7 * <p> 8 8 * 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. 14 16 * </p> 15 17 * … … 46 48 } 47 49 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. 49 56 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 50 57 return NodeEquality.LEXICALLY_EQUAL; 51 58 } 59 else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { 60 return NodeEquality.UNEQUAL; 61 } 52 62 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; 58 64 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 } 73 79 } 74 80 } 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 } 79 88 } 80 89 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 } 83 111 } 84 else { 85 return NodeEquality.SYNTACTICALLY_EQUAL; 86 } 112 113 return selectionEquality; 87 114 } 115 88 116 }
Note: See TracChangeset
for help on using the changeset viewer.