Changeset 805 for trunk/quest-core-tasktrees
- Timestamp:
- 09/10/12 17:31:34 (12 years ago)
- Location:
- trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
r655 r805 24 24 private NodeEqualityRuleManager nodeEqualityRuleManager; 25 25 26 /** */ 27 private NodeEquality minimalNodeEquality; 28 26 29 /** 27 30 * TODO: comment 28 31 * 29 32 */ 30 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 33 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 34 NodeEquality minimalNodeEquality) 35 { 31 36 super(); 32 37 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 38 this.minimalNodeEquality = minimalNodeEquality; 33 39 } 34 40 … … 64 70 65 71 if (equalVariants != null) { 66 if (!finalize) { 67 // check, if the iteration may go on. This may be the case, if the detected 68 // iteration finishes with the last child of the parent, or if the 69 // remaining children, which were not identified as part of the iteration, 70 // start a further occurrence of the iteration 71 if (end == (parent.getChildren().size() - 1)) { 72 RuleApplicationResult result = new RuleApplicationResult(); 73 result.setRuleApplicationStatus 72 RuleApplicationResult result = new RuleApplicationResult(); 73 74 if ((!finalize) && (iterationMayContinue(equalVariants, parent, end + 1))) { 75 result.setRuleApplicationStatus 74 76 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 75 return result; 76 } 77 78 boolean allNodesEqual = true; 79 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 80 { 81 if ((end + i + 1) >= parent.getChildren().size()) { 82 break; 83 } 84 85 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 86 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 87 88 allNodesEqual &= 89 nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 90 } 91 92 if (allNodesEqual) { 93 RuleApplicationResult result = new RuleApplicationResult(); 94 result.setRuleApplicationStatus 95 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 96 return result; 97 } 77 return result; 98 78 } 99 79 100 RuleApplicationResult result = new RuleApplicationResult(); 101 IIteration newIteration = nodeFactory.createNewIteration(); 102 result.addNewlyCreatedParentNode(newIteration); 103 104 if (equalVariants.size() == 1) { 105 // all children are the same. Create an iteration of this child 106 if (equalVariants.get(0).length == 1) { 107 // all children are the same. Create an iteration of this child 108 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 109 } 110 else { 111 // there was an iteration of structurally equal sequences 112 ISequence sequence = nodeFactory.createNewSequence(); 113 result.addNewlyCreatedParentNode(sequence); 114 115 for (ITaskTreeNode node : equalVariants.get(0)) { 116 treeBuilder.addChild(sequence, node); 117 } 118 119 treeBuilder.setChild(newIteration, sequence); 120 } 121 } 122 else { 123 // there are distinct variants of semantically equal subsequences or 124 // children --> 125 // create an iterated selection 126 ISelection selection = nodeFactory.createNewSelection(); 127 result.addNewlyCreatedParentNode(selection); 128 129 for (ITaskTreeNode[] variant : equalVariants) { 130 if (variant.length == 1) { 131 treeBuilder.addChild(selection, variant[0]); 132 } 133 else { 134 ISequence sequence = nodeFactory.createNewSequence(); 135 result.addNewlyCreatedParentNode(sequence); 136 137 for (ITaskTreeNode node : variant) { 138 treeBuilder.addChild(sequence, node); 139 } 140 141 treeBuilder.addChild(selection, sequence); 142 } 143 } 144 145 treeBuilder.setChild(newIteration, selection); 146 } 80 IIteration newIteration = createIterationBasedOnIdentifiedVariants 81 (equalVariants, treeBuilder, nodeFactory, result); 82 147 83 148 84 // remove iterated children … … 193 129 194 130 /** 195 *196 */131 * 132 */ 197 133 private List<ITaskTreeNode[]> getEqualSublistVariantsForSubListLength(ITaskTreeNode parent, 198 134 int start, … … 217 153 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 218 154 219 if (!nodeEquality.isAtLeast( NodeEquality.LEXICALLY_EQUAL)) {220 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) {221 otherVariant[i] = parent.getChildren().get(parentIdx + i);222 }223 else {224 return null;225 }226 } 227 } 228 229 // check, if there is a s emantically equal other variant. If so, add it to the list of230 // variants155 if (!nodeEquality.isAtLeast(minimalNodeEquality)) { 156 return null; 157 } 158 else if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 159 // if the node is a syntactical or semantical equivalent of the first variant, 160 // then store it. 161 otherVariant[i] = parent.getChildren().get(parentIdx + i); 162 } 163 } 164 165 // check, if there is a syntactically or semantically equal other variant. If so, add 166 // it to the list of variants 231 167 boolean semanticallyUnequal = false; 232 168 for (int i = 0; i < subListLen; i++) { … … 247 183 } 248 184 185 /** 186 * <p> 187 * TODO: comment 188 * </p> 189 * 190 * @param equalVariants 191 * @param parent 192 * @return 193 */ 194 private boolean iterationMayContinue(List<ITaskTreeNode[]> equalVariants, 195 ITaskTreeNode parent, 196 int remainderIndex) 197 { 198 // check, if the iteration may go on. This may be the case, if the 199 // remaining children, which were not identified as part of the iteration, 200 // start a further occurrence of the iteration 201 202 boolean allNodesEqual = true; 203 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 204 { 205 if ((remainderIndex + i) >= parent.getChildren().size()) { 206 break; 207 } 208 209 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 210 (equalVariants.get(0)[i], parent.getChildren().get(remainderIndex + i)); 211 212 allNodesEqual &= nodeEquality.isAtLeast(minimalNodeEquality); 213 } 214 215 return allNodesEqual; 216 } 217 218 /** 219 * <p> 220 * TODO: comment 221 * </p> 222 * 223 * @param equalVariants 224 * @param result 225 * @return 226 */ 227 private IIteration createIterationBasedOnIdentifiedVariants(List<ITaskTreeNode[]> equalVariants, 228 ITaskTreeBuilder treeBuilder, 229 ITaskTreeNodeFactory nodeFactory, 230 RuleApplicationResult result) 231 { 232 IIteration newIteration = nodeFactory.createNewIteration(); 233 result.addNewlyCreatedParentNode(newIteration); 234 235 if (equalVariants.size() == 1) { 236 // all children are the same. Create an iteration of this child 237 if (equalVariants.get(0).length == 1) { 238 // all children are the same. Create an iteration of this child 239 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 240 } 241 else { 242 // there was an iteration of structurally equal sequences 243 ISequence sequence = nodeFactory.createNewSequence(); 244 result.addNewlyCreatedParentNode(sequence); 245 246 for (ITaskTreeNode node : equalVariants.get(0)) { 247 treeBuilder.addChild(sequence, node); 248 } 249 250 treeBuilder.setChild(newIteration, sequence); 251 } 252 } 253 else { 254 // there are distinct variants of semantically equal subsequences or 255 // children --> 256 // create an iterated selection 257 ISelection selection = nodeFactory.createNewSelection(); 258 result.addNewlyCreatedParentNode(selection); 259 260 for (ITaskTreeNode[] variant : equalVariants) { 261 if (variant.length == 1) { 262 treeBuilder.addChild(selection, variant[0]); 263 } 264 else { 265 ISequence sequence = nodeFactory.createNewSequence(); 266 result.addNewlyCreatedParentNode(sequence); 267 268 for (ITaskTreeNode node : variant) { 269 treeBuilder.addChild(sequence, node); 270 } 271 272 treeBuilder.addChild(selection, sequence); 273 } 274 } 275 276 treeBuilder.setChild(newIteration, selection); 277 } 278 279 return newIteration; 280 } 281 249 282 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r799 r805 5 5 import java.util.logging.Level; 6 6 7 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 7 8 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 8 9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; … … 43 44 ruleIndex.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager)); 44 45 ruleIndex.add(new DefaultGuiEventSequenceDetectionRule()); 45 ruleIndex.add(new DefaultIterationDetectionRule(nodeEqualityRuleManager)); 46 47 ruleIndex.add(new DefaultIterationDetectionRule 48 (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL)); 49 ruleIndex.add(new DefaultIterationDetectionRule 50 (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL)); 51 ruleIndex.add(new DefaultIterationDetectionRule 52 (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL)); 46 53 } 47 54
Note: See TracChangeset
for help on using the changeset viewer.