Changeset 1294 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality
- Timestamp:
- 08/14/13 17:04:42 (11 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/EventTaskComparisonRule.java
r1146 r1294 15 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 import java.util.Collection; 18 17 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 18 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 19 23 20 24 /** … … 29 33 30 34 /* (non-Javadoc) 31 * @see NodeComparisonRule#isApplicable(ITask, ITask)35 * @see TaskComparisonRule#isApplicable(ITask, ITask) 32 36 */ 33 37 @Override … … 37 41 38 42 /* (non-Javadoc) 39 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)43 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 40 44 */ 41 45 @Override 42 46 public boolean areLexicallyEqual(ITask task1, ITask task2) { 43 IEventTask eventTask1 = (IEventTask) task1;44 IEventTask eventTask2 = (IEventTask) task2;47 Collection<ITaskInstance> taskInstances1 = task1.getInstances(); 48 Collection<ITaskInstance> taskInstances2 = task2.getInstances(); 45 49 46 return (eventTask1.getEventType().equals(eventTask2.getEventType()) && 47 eventTask1.getEventTarget().equals(eventTask2.getEventTarget())); 50 for (ITaskInstance instance1 : taskInstances1) { 51 boolean found = false; 52 53 for (ITaskInstance instance2 : taskInstances2) { 54 if (areLexicallyEqual(instance1, instance2)) { 55 found = true; 56 break; 57 } 58 } 59 60 if (!found) { 61 return false; 62 } 63 } 64 65 return true; 48 66 } 49 67 50 68 /* (non-Javadoc) 51 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)69 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 52 70 */ 53 71 @Override … … 57 75 58 76 /* (non-Javadoc) 59 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)77 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 60 78 */ 61 79 @Override … … 64 82 } 65 83 84 /* (non-Javadoc) 85 * @see TaskComparisonRule#compare(ITask, ITask) 86 */ 66 87 @Override 67 88 public TaskEquality compare(ITask task1, ITask task2) { … … 74 95 } 75 96 97 98 /* (non-Javadoc) 99 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 100 */ 101 @Override 102 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 103 return 104 (instance1 instanceof IEventTaskInstance) && (instance2 instanceof IEventTaskInstance); 105 } 106 107 /* (non-Javadoc) 108 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 109 */ 110 @Override 111 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 112 IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1; 113 IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2; 114 115 return (eventTask1.getEvent().getType().equals(eventTask2.getEvent().getType()) && 116 eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())); 117 } 118 119 /* (non-Javadoc) 120 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 121 */ 122 @Override 123 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 124 return areLexicallyEqual(instance1, instance2); 125 } 126 127 /* (non-Javadoc) 128 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 129 */ 130 @Override 131 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 132 return areLexicallyEqual(instance1, instance2); 133 } 134 135 /* (non-Javadoc) 136 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 137 */ 138 @Override 139 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 140 if (areLexicallyEqual(instance1, instance2)) { 141 return TaskEquality.LEXICALLY_EQUAL; 142 } 143 else { 144 return TaskEquality.UNEQUAL; 145 } 146 } 147 76 148 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/GUIEventTaskComparisonRule.java
r1154 r1294 14 14 15 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 17 import java.util.Collection; 16 18 17 19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; … … 41 43 import de.ugoe.cs.autoquest.eventcore.guimodel.IText; 42 44 import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip; 43 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask ;45 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 44 46 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 47 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 45 48 46 49 /** … … 61 64 62 65 /* (non-Javadoc) 63 * @see NodeComparisonRule#isApplicable(ITask, ITask)66 * @see TaskComparisonRule#isApplicable(ITask, ITask) 64 67 */ 65 68 @Override 66 69 public boolean isApplicable(ITask task1, ITask task2) { 67 return 68 ((task1 instanceof IEventTask) && (task2 instanceof IEventTask) && 69 (((IEventTask) task1).getEventType() instanceof IInteraction) && 70 (((IEventTask) task2).getEventType() instanceof IInteraction)); 71 } 72 73 /* (non-Javadoc) 74 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 70 for (ITaskInstance instance : task1.getInstances()) { 71 if ((!(instance instanceof IEventTaskInstance)) || 72 (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) 73 { 74 return false; 75 } 76 } 77 78 for (ITaskInstance instance : task2.getInstances()) { 79 if ((!(instance instanceof IEventTaskInstance)) || 80 (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) 81 { 82 return false; 83 } 84 } 85 86 return true; 87 } 88 89 /* (non-Javadoc) 90 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 75 91 */ 76 92 @Override … … 81 97 82 98 /* (non-Javadoc) 83 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)99 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 84 100 */ 85 101 @Override … … 90 106 91 107 /* (non-Javadoc) 92 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)108 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 93 109 */ 94 110 @Override … … 99 115 100 116 /* (non-Javadoc) 101 * @see NodeComparisonRule#compare(ITask, ITask)117 * @see TaskComparisonRule#compare(ITask, ITask) 102 118 */ 103 119 @Override … … 106 122 } 107 123 108 /** 109 * 110 */ 111 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 112 IEventTask eventTask1 = (IEventTask) task1; 113 IEventTask eventTask2 = (IEventTask) task2; 114 115 if (!eventTask1.getEventTarget().equals(eventTask2.getEventTarget())) { 124 /* (non-Javadoc) 125 * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#isApplicable(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 126 */ 127 @Override 128 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 129 return 130 (instance1 instanceof IEventTaskInstance) && 131 (instance2 instanceof IEventTaskInstance) && 132 (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction) && 133 (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction); 134 } 135 136 /* (non-Javadoc) 137 * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areLexicallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 138 */ 139 @Override 140 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 141 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 142 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 143 } 144 145 /* (non-Javadoc) 146 * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSyntacticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 147 */ 148 @Override 149 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 150 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 151 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 152 } 153 154 /* (non-Javadoc) 155 * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSemanticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 156 */ 157 @Override 158 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 159 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 160 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 161 } 162 163 /* (non-Javadoc) 164 * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#compare(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 165 */ 166 @Override 167 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 168 return getEquality(instance1, instance2, null); 169 } 170 171 /** 172 * 173 */ 174 private TaskEquality getEquality(ITask task1, 175 ITask task2, 176 TaskEquality requiredEqualityLevel) 177 { 178 Collection<ITaskInstance> taskInstances1 = task1.getInstances(); 179 Collection<ITaskInstance> taskInstances2 = task2.getInstances(); 180 181 TaskEquality checkedEquality = 182 requiredEqualityLevel != null ? requiredEqualityLevel : TaskEquality.SEMANTICALLY_EQUAL; 183 184 TaskEquality commonDenominator = TaskEquality.LEXICALLY_EQUAL; 185 186 for (ITaskInstance instance1 : taskInstances1) { 187 TaskEquality mostConcreteEquality = null; 188 189 for (ITaskInstance instance2 : taskInstances2) { 190 TaskEquality equality = getEquality(instance1, instance2, requiredEqualityLevel); 191 192 if ((equality != null) && ((mostConcreteEquality == null) || 193 (equality.isAtLeast(mostConcreteEquality)))) 194 { 195 mostConcreteEquality = equality; 196 197 if (((requiredEqualityLevel != null) && 198 (mostConcreteEquality.isAtLeast(requiredEqualityLevel))) || 199 (mostConcreteEquality.isAtLeast(TaskEquality.LEXICALLY_EQUAL))) 200 { 201 break; 202 } 203 } 204 } 205 206 commonDenominator = commonDenominator.getCommonDenominator(mostConcreteEquality); 207 208 if (!commonDenominator.isAtLeast(checkedEquality)) { 209 return TaskEquality.UNEQUAL; 210 } 211 } 212 213 return commonDenominator; 214 } 215 216 /** 217 * 218 */ 219 private TaskEquality getEquality(ITaskInstance instance1, 220 ITaskInstance instance2, 221 TaskEquality requiredEqualityLevel) 222 { 223 IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1; 224 IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2; 225 226 if (!eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())) { 116 227 return TaskEquality.UNEQUAL; 117 228 } 118 229 119 IInteraction interaction1 = (IInteraction) eventTask1.getEvent Type();120 IInteraction interaction2 = (IInteraction) eventTask2.getEvent Type();230 IInteraction interaction1 = (IInteraction) eventTask1.getEvent().getType(); 231 IInteraction interaction2 = (IInteraction) eventTask2.getEvent().getType(); 121 232 122 233 return compareInteractions 123 (interaction1, interaction2, eventTask1.getEvent Target(), requiredEqualityLevel);234 (interaction1, interaction2, eventTask1.getEvent().getTarget(), requiredEqualityLevel); 124 235 } 125 236 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/IterationComparisonRule.java
r1190 r1294 15 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;18 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;21 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 22 22 23 23 /** … … 82 82 83 83 /* (non-Javadoc) 84 * @see NodeComparisonRule#isApplicable(ITask, ITask)84 * @see TaskComparisonRule#isApplicable(ITask, ITask) 85 85 */ 86 86 @Override … … 90 90 91 91 /* (non-Javadoc) 92 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)92 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 93 93 */ 94 94 @Override 95 95 public boolean areLexicallyEqual(ITask task1, ITask task2) { 96 ITask child1 = ((IIteration) task1).getMarkedTask();97 ITask child2 = ((IIteration) task2).getMarkedTask();98 99 if (child1 != null) {100 if (child2 == null) {101 return false;102 }103 else {104 // iterations may have 3 different structures.105 // 1. they have one child, which is the iterated one106 // 2. they have a sequence of children, which is iterated107 // 3. they have a selection of different iterated variants (usually the variants108 // are semantically equal)109 // check if the type of children match. If not, return false. If they match,110 // use the equality manager to perform further comparisons111 112 if (((child1 instanceof ISelection) && (child2 instanceof ISelection)) ||113 ((child1 instanceof ISequence) && (child2 instanceof ISequence)) ||114 ((child1 instanceof IEventTask) && (child2 instanceof IEventTask)))115 {116 return getNodeEquality117 (child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL);118 }119 }120 }121 else if (child2 == null) {122 return true;123 }124 125 return false;126 }127 128 /* (non-Javadoc)129 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)130 */131 @Override132 public boolean areSyntacticallyEqual(ITask task1, ITask task2) {133 96 ITask child1 = ((IIteration) task1).getMarkedTask(); 134 97 ITask child2 = ((IIteration) task2).getMarkedTask(); … … 146 109 // ignore the type of the children but check them for equality. 147 110 148 return getNodeEquality(child1, child2).isAtLeast(TaskEquality. SYNTACTICALLY_EQUAL);111 return getNodeEquality(child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 149 112 } 150 113 } … … 157 120 158 121 /* (non-Javadoc) 159 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 122 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 123 */ 124 @Override 125 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 126 return areLexicallyEqual(task1, task2); 127 } 128 129 /* (non-Javadoc) 130 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 160 131 */ 161 132 @Override … … 165 136 166 137 /* (non-Javadoc) 167 * @see NodeComparisonRule#compare(ITask, ITask)138 * @see TaskComparisonRule#compare(ITask, ITask) 168 139 */ 169 140 @Override … … 203 174 // all other combinations (i.e. sequence with single child and sequence with selection) 204 175 // can not match 176 } 177 178 /* (non-Javadoc) 179 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 180 */ 181 @Override 182 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 183 return isApplicable(instance1.getTask(), instance2.getTask()); 184 } 185 186 /* (non-Javadoc) 187 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 188 */ 189 @Override 190 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 191 IIterationInstance iteration1 = (IIterationInstance) instance1; 192 IIterationInstance iteration2 = (IIterationInstance) instance2; 193 194 // if both sequences do not have children, they are equal although this doesn't make sense 195 if ((iteration1.size() == 0) && (iteration2.size() == 0)) { 196 return true; 197 } 198 199 if (iteration1.size() != iteration2.size()) { 200 return false; 201 } 202 203 for (int i = 0; i < iteration1.size(); i++) { 204 ITaskInstance child1 = iteration1.get(i); 205 ITaskInstance child2 = iteration2.get(i); 206 207 TaskEquality taskEquality = 208 callRuleManager(child1, child2, TaskEquality.LEXICALLY_EQUAL); 209 210 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 211 return false; 212 } 213 } 214 215 return true; 216 } 217 218 /* (non-Javadoc) 219 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 220 */ 221 @Override 222 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 223 return areLexicallyEqual(instance1, instance2); 224 } 225 226 /* (non-Javadoc) 227 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 228 */ 229 @Override 230 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 231 return areLexicallyEqual(instance1, instance2); 232 } 233 234 /* (non-Javadoc) 235 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 236 */ 237 @Override 238 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 239 if (areLexicallyEqual(instance1, instance2)) { 240 return TaskEquality.LEXICALLY_EQUAL; 241 } 242 else { 243 return TaskEquality.UNEQUAL; 244 } 205 245 } 206 246 … … 272 312 callRuleManager(task, child, commonDenominatorForAllComparisons); 273 313 274 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) 275 { 314 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 276 315 return TaskEquality.UNEQUAL; 277 316 } … … 314 353 } 315 354 } 355 356 /** 357 * <p> 358 * used to to call the task equality rule manager for the comparison of the two provided 359 * children. If no required equality level is provided, than the most concrete equality is 360 * returned. Otherwise, the required equality is returned as long as the children are equal 361 * on that level. 362 * </p> 363 * 364 * @param taskInstance1 the first task instance to be compared 365 * @param taskInstance2 the second task instance to be compared 366 * @param requiredEqualityLevel the equality level to be checked for 367 * 368 * @return the determined equality 369 */ 370 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 371 ITaskInstance taskInstance2, 372 TaskEquality requiredEqualityLevel) 373 { 374 if (requiredEqualityLevel == null) { 375 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 376 } 377 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 378 (taskInstance1, taskInstance2, requiredEqualityLevel)) 379 { 380 return requiredEqualityLevel; 381 } 382 else { 383 return TaskEquality.UNEQUAL; 384 } 385 } 316 386 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SelectionComparisonRule.java
r1190 r1294 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 23 22 24 /** … … 39 41 40 42 /* (non-Javadoc) 41 * @see NodeComparisonRule#isApplicable(ITask, ITask)43 * @see TaskComparisonRule#isApplicable(ITask, ITask) 42 44 */ 43 45 @Override … … 47 49 48 50 /* (non-Javadoc) 49 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)51 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 50 52 */ 51 53 @Override … … 56 58 57 59 /* (non-Javadoc) 58 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)60 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 59 61 */ 60 62 @Override … … 65 67 66 68 /* (non-Javadoc) 67 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)69 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 68 70 */ 69 71 @Override … … 74 76 75 77 /* (non-Javadoc) 76 * @see NodeComparisonRule#compare(ITask, ITask)78 * @see TaskComparisonRule#compare(ITask, ITask) 77 79 */ 78 80 @Override 79 81 public TaskEquality compare(ITask task1, ITask task2) { 80 82 return getEquality(task1, task2, null); 83 } 84 85 /* (non-Javadoc) 86 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 87 */ 88 @Override 89 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 90 return isApplicable(instance1.getTask(), instance2.getTask()); 91 } 92 93 /* (non-Javadoc) 94 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 95 */ 96 @Override 97 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 98 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 99 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 100 } 101 102 /* (non-Javadoc) 103 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 104 */ 105 @Override 106 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 107 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 108 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 109 } 110 111 /* (non-Javadoc) 112 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 113 */ 114 @Override 115 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 116 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 117 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 118 } 119 120 /* (non-Javadoc) 121 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 122 */ 123 @Override 124 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 125 return getEquality(instance1, instance2, null); 81 126 } 82 127 … … 107 152 } 108 153 109 TaskEquality selectionEquality;110 111 154 if (requiredEqualityLevel == null) { 112 155 // calculate the common equality level for all children of both selections. 113 156 // do it in both directions to ensure commutative comparison 114 selectionEquality = getCommonEqualityLevel(children1, children2); 115 if (selectionEquality != TaskEquality.UNEQUAL) { 116 return selectionEquality.getCommonDenominator 117 (getCommonEqualityLevel(children2, children1)); 118 } 119 else { 120 return TaskEquality.UNEQUAL; 121 } 157 return getMostConcreteEqualityLevel(children1, children2); 122 158 } 123 159 else { 124 160 // we are searching for a specific equality 125 if (checkEqualityLevel(children1, children2, requiredEqualityLevel) && 126 checkEqualityLevel(children2, children1, requiredEqualityLevel)) 127 { 161 if (checkEqualityLevel(children1, children2, requiredEqualityLevel)) { 128 162 return requiredEqualityLevel; 129 163 } … … 136 170 /** 137 171 * <p> 138 * determines the commonequality level for all tasks in the first list compared to all139 * tasks in the second list. I f for one task in the first list, there is no equal task in the140 * second list, the method return unequality.172 * determines the most concrete equality level for all tasks in the first list compared to all 173 * tasks in the second list. It is sufficient, if there is one task in one list for which there 174 * exist an equal task in the other list. 141 175 * </p> 142 176 * … … 144 178 * @param children2 the second list to be compared 145 179 * 146 * @return the common task equality identified for all tasks in the first list with respect to 147 * the second list 148 */ 149 private TaskEquality getCommonEqualityLevel(List<ITask> children1, List<ITask> children2) { 150 TaskEquality listEquality = TaskEquality.LEXICALLY_EQUAL; 151 180 * @return the most concrete task equality identified for all tasks in the first list with 181 * respect to the second list 182 */ 183 private TaskEquality getMostConcreteEqualityLevel(List<ITask> children1, List<ITask> children2) 184 { 152 185 TaskEquality childEquality; 153 186 TaskEquality currentEquality; … … 164 197 } 165 198 166 if (childEquality == TaskEquality.SEMANTICALLY_EQUAL) { 167 // as we calculate only the common denominator, we can break up here for 168 // the current child. We will not improve the denominator anymore 169 break; 199 if (childEquality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)) { 200 // as we calculate the most concrete equality, we can break up here 201 return TaskEquality.LEXICALLY_EQUAL; 170 202 } 171 203 } 172 204 } 173 174 if (childEquality == null) { 175 // we did not find any child in the second list, that is equal to the searched 176 // child 177 return TaskEquality.UNEQUAL; 178 } 179 else { 180 listEquality = listEquality.getCommonDenominator(childEquality); 181 } 182 } 183 184 return listEquality; 185 } 186 187 /** 188 * <p> 189 * ensures for the two given lists, that for each task in the first list there is a task 205 } 206 207 // as the comparison should be commutative, we do not need to check, if in list 2 there is 208 // a child equal to one in list 1 209 return TaskEquality.UNEQUAL; 210 } 211 212 /** 213 * <p> 214 * ensures for the two given lists, that for at least one task in the first list there is a task 190 215 * in the second list being on the given level equal to the task in the first list. 191 216 * </p> … … 195 220 * @param requiredEqualityLevel the equality level to be checked for 196 221 * 197 * @return true if each task in the first list has an equal task in the second list when198 * considering the given equality level, false else.222 * @return true if there is a task in the first list that has an equal task in the second list 223 * when considering the given equality level, false else. 199 224 */ 200 225 private boolean checkEqualityLevel(List<ITask> children1, … … 202 227 TaskEquality requiredEqualityLevel) 203 228 { 204 TaskEquality childEquality;205 229 TaskEquality currentEquality; 206 230 for (ITask child1 : children1) { 207 childEquality = null;208 231 for (ITask child2 : children2) { 209 232 currentEquality = callRuleManager(child1, child2, requiredEqualityLevel); … … 212 235 // we found at least one equal child with sufficient equality in the 213 236 // second list. So be can break up for this child. 214 childEquality = currentEquality; 215 break; 237 return true; 216 238 } 217 239 } 218 219 if (childEquality == null) { 220 // we did not find any child in the second list, that is equal to the searched 221 // child 222 return false; 223 } 224 } 225 226 // for all children, we found an equality 227 return true; 240 } 241 242 return false; 228 243 } 229 244 … … 259 274 } 260 275 276 /** 277 * <p> 278 * compares two selection instances with each other checking for the provided required level of 279 * equality. If this level is ensured, the method immediately returns. The more concrete 280 * the required equality level, the more checks this method performs. 281 * </p> 282 * 283 * @param taskInstance1 the first task instance to be compared 284 * @param taskInstance2 the second task instance to be compared 285 * @param requiredEqualityLevel the equality level to be checked for 286 * 287 * @return the determined equality. 288 */ 289 private TaskEquality getEquality(ITaskInstance taskInstance1, 290 ITaskInstance taskInstance2, 291 TaskEquality requiredEqualityLevel) 292 { 293 ITaskInstance child1 = ((ISelectionInstance) taskInstance1).getChild(); 294 ITaskInstance child2 = ((ISelectionInstance) taskInstance2).getChild(); 295 296 // if both selections do not have children, they are lexically equal. If only one of them 297 // has children, they are unequal. 298 if ((child1 == null) && (child2 == null)) { 299 return TaskEquality.LEXICALLY_EQUAL; 300 } 301 else if ((child1 == null) || (child2 == null)) { 302 return TaskEquality.UNEQUAL; 303 } 304 305 TaskEquality equality = callRuleManager(child1, child2, requiredEqualityLevel); 306 307 if (equality == TaskEquality.IDENTICAL) { 308 // two different selection instances can be at most lexically equal even if their 309 // children are identical 310 return TaskEquality.LEXICALLY_EQUAL; 311 } 312 else { 313 return equality; 314 } 315 } 316 317 /** 318 * <p> 319 * used to to call the task equality rule manager for the comparison of the two provided 320 * children. If no required equality level is provided, than the most concrete equality is 321 * returned. Otherwise, the required equality is returned as long as the children are equal 322 * on that level. 323 * </p> 324 * 325 * @param taskInstance1 the first task instance to be compared 326 * @param taskInstance2 the second task instance to be compared 327 * @param requiredEqualityLevel the equality level to be checked for 328 * 329 * @return the determined equality 330 */ 331 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 332 ITaskInstance taskInstance2, 333 TaskEquality requiredEqualityLevel) 334 { 335 if (requiredEqualityLevel == null) { 336 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 337 } 338 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 339 (taskInstance1, taskInstance2, requiredEqualityLevel)) 340 { 341 return requiredEqualityLevel; 342 } 343 else { 344 return TaskEquality.UNEQUAL; 345 } 346 } 261 347 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SequenceComparisonRule.java
r1190 r1294 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 23 22 24 /** … … 34 36 35 37 /* (non-Javadoc) 36 * @see NodeComparisonRule#isApplicable(ITask, ITask)38 * @see TaskComparisonRule#isApplicable(ITask, ITask) 37 39 */ 38 40 @Override … … 42 44 43 45 /* (non-Javadoc) 44 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)46 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 45 47 */ 46 48 @Override … … 51 53 52 54 /* (non-Javadoc) 53 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)55 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 54 56 */ 55 57 @Override … … 60 62 61 63 /* (non-Javadoc) 62 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)64 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 63 65 */ 64 66 @Override … … 69 71 70 72 /* (non-Javadoc) 71 * @see NodeComparisonRule#compare(ITask, ITask)73 * @see TaskComparisonRule#compare(ITask, ITask) 72 74 */ 73 75 @Override 74 76 public TaskEquality compare(ITask task1, ITask task2) { 75 77 return getEquality(task1, task2, null); 78 } 79 80 /* (non-Javadoc) 81 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 82 */ 83 @Override 84 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 85 return isApplicable(instance1.getTask(), instance2.getTask()); 86 } 87 88 /* (non-Javadoc) 89 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 90 */ 91 @Override 92 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 93 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 94 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 95 } 96 97 /* (non-Javadoc) 98 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 99 */ 100 @Override 101 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 102 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 103 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 104 } 105 106 /* (non-Javadoc) 107 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 108 */ 109 @Override 110 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 111 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 112 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 113 } 114 115 /* (non-Javadoc) 116 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 117 */ 118 @Override 119 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 120 return getEquality(instance1, instance2, null); 76 121 } 77 122 … … 149 194 } 150 195 } 196 197 /** 198 * <p> 199 * compares two sequence instances with each other checking for the provided required level of 200 * equality. If this level is ensured, the method immediately returns. The more concrete 201 * the required equality level, the more checks this method performs. 202 * </p> 203 * 204 * @param taskInstance1 the first task instance to be compared 205 * @param taskInstance2 the second task instance to be compared 206 * @param requiredEqualityLevel the equality level to be checked for 207 * 208 * @return the determined equality. 209 */ 210 private TaskEquality getEquality(ITaskInstance taskInstance1, 211 ITaskInstance taskInstance2, 212 TaskEquality requiredEqualityLevel) 213 { 214 ISequenceInstance sequence1 = (ISequenceInstance) taskInstance1; 215 ISequenceInstance sequence2 = (ISequenceInstance) taskInstance2; 216 217 // if both sequences do not have children, they are equal although this doesn't make sense 218 if ((sequence1.size() == 0) && (sequence2.size() == 0)) { 219 return TaskEquality.LEXICALLY_EQUAL; 220 } 221 222 if (sequence1.size() != sequence2.size()) { 223 return TaskEquality.UNEQUAL; 224 } 225 226 TaskEquality resultingEquality = TaskEquality.LEXICALLY_EQUAL; 227 for (int i = 0; i < sequence1.size(); i++) { 228 ITaskInstance child1 = sequence1.get(i); 229 ITaskInstance child2 = sequence2.get(i); 230 231 TaskEquality taskEquality = callRuleManager(child1, child2, requiredEqualityLevel); 232 233 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 234 return TaskEquality.UNEQUAL; 235 } 236 237 resultingEquality = resultingEquality.getCommonDenominator(taskEquality); 238 } 239 240 return resultingEquality; 241 } 242 243 /** 244 * <p> 245 * used to to call the task equality rule manager for the comparison of the two provided 246 * children. If no required equality level is provided, than the most concrete equality is 247 * returned. Otherwise, the required equality is returned as long as the children are equal 248 * on that level. 249 * </p> 250 * 251 * @param taskInstance1 the first task instance to be compared 252 * @param taskInstance2 the second task instance to be compared 253 * @param requiredEqualityLevel the equality level to be checked for 254 * 255 * @return the determined equality 256 */ 257 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 258 ITaskInstance taskInstance2, 259 TaskEquality requiredEqualityLevel) 260 { 261 if (requiredEqualityLevel == null) { 262 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 263 } 264 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 265 (taskInstance1, taskInstance2, requiredEqualityLevel)) 266 { 267 return requiredEqualityLevel; 268 } 269 else { 270 return TaskEquality.UNEQUAL; 271 } 272 } 151 273 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndIterationComparisonRule.java
r1190 r1294 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 18 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 19 21 20 22 /** … … 33 35 34 36 /* (non-Javadoc) 35 * @see NodeComparisonRule#isApplicable(ITask, ITask)37 * @see TaskComparisonRule#isApplicable(ITask, ITask) 36 38 */ 37 39 @Override … … 42 44 43 45 /* (non-Javadoc) 44 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)46 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 45 47 */ 46 48 @Override … … 51 53 52 54 /* (non-Javadoc) 53 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)55 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 54 56 */ 55 57 @Override … … 60 62 61 63 /* (non-Javadoc) 62 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)64 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 63 65 */ 64 66 @Override … … 69 71 70 72 /* (non-Javadoc) 71 * @see NodeComparisonRule#compare(ITask, ITask)73 * @see TaskComparisonRule#compare(ITask, ITask) 72 74 */ 73 75 @Override 74 76 public TaskEquality compare(ITask task1, ITask task2) { 75 77 return getEquality(task1, task2, null); 78 } 79 80 /* (non-Javadoc) 81 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 82 */ 83 @Override 84 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 85 return isApplicable(instance1.getTask(), instance2.getTask()); 86 } 87 88 /* (non-Javadoc) 89 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 90 */ 91 @Override 92 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 93 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 94 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 95 } 96 97 /* (non-Javadoc) 98 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 99 */ 100 @Override 101 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 102 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 103 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 104 } 105 106 /* (non-Javadoc) 107 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 108 */ 109 @Override 110 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 111 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 112 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 113 } 114 115 /* (non-Javadoc) 116 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 117 */ 118 @Override 119 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 120 return getEquality(instance1, instance2, null); 76 121 } 77 122 … … 167 212 } 168 213 } 214 215 /** 216 * <p> 217 * compares two task instances with each other checking for the provided required level of 218 * equality. One of the task instances must be a iteration, the other one not. If this is not 219 * the case, the method returns null. The returned equality level is at most lexical equality 220 * as the iteration can not be identical to something not being a iteration. 221 * </p> 222 * 223 * @param taskInstance1 the first task instance to be compared 224 * @param taskInstance2 the second task instance to be compared 225 * @param requiredEqualityLevel the equality level to be checked for 226 * 227 * @return the determined equality. 228 */ 229 private TaskEquality getEquality(ITaskInstance taskInstance1, 230 ITaskInstance taskInstance2, 231 TaskEquality requiredEqualityLevel) 232 { 233 IIterationInstance iteration = null; 234 ITaskInstance task = null; 235 236 if (taskInstance1 instanceof IIterationInstance) { 237 if (taskInstance2 instanceof IIterationInstance) { 238 // the rule is not responsible for two iterations 239 return null; 240 } 241 242 iteration = (IIterationInstance) taskInstance1; 243 task = taskInstance2; 244 } 245 else if (taskInstance2 instanceof IIterationInstance) { 246 if (taskInstance1 instanceof IIterationInstance) { 247 // the rule is not responsible for two iterations 248 return null; 249 } 250 251 iteration = (IIterationInstance) taskInstance2; 252 task = taskInstance1; 253 } 254 else { 255 return null; 256 } 257 258 // now, that we found the iteration and the task, lets compare the children of the iteration 259 // with the task. 260 261 if (iteration.size() < 1) { 262 return null; 263 } 264 265 TaskEquality mostConcreteNodeEquality = null; 266 267 for (ITaskInstance child : iteration) { 268 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 269 270 if (taskEquality != TaskEquality.UNEQUAL) { 271 if (mostConcreteNodeEquality == null) { 272 mostConcreteNodeEquality = taskEquality; 273 } 274 else if (mostConcreteNodeEquality.isAtLeast(taskEquality)) { 275 mostConcreteNodeEquality = taskEquality; 276 277 } 278 279 if ((requiredEqualityLevel != null) && 280 (mostConcreteNodeEquality.isAtLeast(requiredEqualityLevel))) 281 { 282 // if we found one child of the selection that is as equal as required, then 283 // we can consider the selection to be sufficiently equal to the other task. 284 // So we break up checking further children. 285 break; 286 } 287 } 288 } 289 290 // although the subtask may be identical to the task, we can not return identical, as 291 // the selection is not identical to the task, but at most lexically equal 292 if (mostConcreteNodeEquality == TaskEquality.IDENTICAL) { 293 return TaskEquality.LEXICALLY_EQUAL; 294 } 295 else { 296 return mostConcreteNodeEquality; 297 } 298 299 } 300 301 /** 302 * <p> 303 * used to to call the task equality rule manager for the comparison of the two provided 304 * children. If no required equality level is provided, than the most concrete equality is 305 * returned. Otherwise, the required equality is returned as long as the children are equal 306 * on that level. 307 * </p> 308 * 309 * @param taskInstance1 the first task instance to be compared 310 * @param taskInstance2 the second task instance to be compared 311 * @param requiredEqualityLevel the equality level to be checked for 312 * 313 * @return the determined equality 314 */ 315 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 316 ITaskInstance taskInstance2, 317 TaskEquality requiredEqualityLevel) 318 { 319 if (requiredEqualityLevel == null) { 320 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 321 } 322 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 323 (taskInstance1, taskInstance2, requiredEqualityLevel)) 324 { 325 return requiredEqualityLevel; 326 } 327 else { 328 return TaskEquality.UNEQUAL; 329 } 330 } 169 331 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndSelectionComparisonRule.java
r1190 r1294 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 23 22 24 /** … … 34 36 35 37 /* (non-Javadoc) 36 * @see NodeComparisonRule#isApplicable(ITask, ITask)38 * @see TaskComparisonRule#isApplicable(ITask, ITask) 37 39 */ 38 40 @Override … … 43 45 44 46 /* (non-Javadoc) 45 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)47 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 46 48 */ 47 49 @Override … … 52 54 53 55 /* (non-Javadoc) 54 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)56 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 55 57 */ 56 58 @Override … … 61 63 62 64 /* (non-Javadoc) 63 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)65 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 64 66 */ 65 67 @Override … … 70 72 71 73 /* (non-Javadoc) 72 * @see NodeComparisonRule#compare(ITask, ITask)74 * @see TaskComparisonRule#compare(ITask, ITask) 73 75 */ 74 76 @Override … … 77 79 } 78 80 81 /* (non-Javadoc) 82 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 83 */ 84 @Override 85 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 86 return isApplicable(instance1.getTask(), instance2.getTask()); 87 } 88 89 /* (non-Javadoc) 90 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 91 */ 92 @Override 93 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 94 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 95 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 96 } 97 98 /* (non-Javadoc) 99 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 100 */ 101 @Override 102 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 103 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 104 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 105 } 106 107 /* (non-Javadoc) 108 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 109 */ 110 @Override 111 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 112 TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 113 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 114 } 115 116 /* (non-Javadoc) 117 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 118 */ 119 @Override 120 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 121 return getEquality(instance1, instance2, null); 122 } 123 79 124 /** 80 125 * <p> … … 191 236 } 192 237 } 238 239 /** 240 * <p> 241 * compares two task instances with each other checking for the provided required level of 242 * equality. One of the task instances must be a selection, the other one not. If this is not 243 * the case, the method returns null. The returned equality level is at most lexical equality 244 * as the selection can not be identical to something not being a selection. 245 * </p> 246 * 247 * @param taskInstance1 the first task instance to be compared 248 * @param taskInstance2 the second task instance to be compared 249 * @param requiredEqualityLevel the equality level to be checked for 250 * 251 * @return the determined equality. 252 */ 253 private TaskEquality getEquality(ITaskInstance taskInstance1, 254 ITaskInstance taskInstance2, 255 TaskEquality requiredEqualityLevel) 256 { 257 ISelectionInstance selection = null; 258 ITaskInstance task = null; 259 260 if (taskInstance1 instanceof ISelectionInstance) { 261 if (taskInstance2 instanceof ISelectionInstance) { 262 // the rule is not responsible for two selections 263 return null; 264 } 265 266 selection = (ISelectionInstance) taskInstance1; 267 task = taskInstance2; 268 } 269 else if (taskInstance2 instanceof ISelectionInstance) { 270 if (taskInstance1 instanceof ISelectionInstance) { 271 // the rule is not responsible for two selections 272 return null; 273 } 274 275 selection = (ISelectionInstance) taskInstance2; 276 task = taskInstance1; 277 } 278 else { 279 return null; 280 } 281 282 // now, that we found the selection and the task, lets compare the child of the selection 283 // with the task. 284 ITaskInstance child = selection.getChild(); 285 286 if (child == null) { 287 return null; 288 } 289 290 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 291 292 // although the subtask may be identical to the task, we can not return identical, as 293 // the selection is not identical to the task, but at most lexically equal 294 if (taskEquality == TaskEquality.IDENTICAL) { 295 return TaskEquality.LEXICALLY_EQUAL; 296 } 297 else { 298 return taskEquality; 299 } 300 301 } 302 303 /** 304 * <p> 305 * used to to call the task equality rule manager for the comparison of the two provided 306 * children. If no required equality level is provided, than the most concrete equality is 307 * returned. Otherwise, the required equality is returned as long as the children are equal 308 * on that level. 309 * </p> 310 * 311 * @param taskInstance1 the first task instance to be compared 312 * @param taskInstance2 the second task instance to be compared 313 * @param requiredEqualityLevel the equality level to be checked for 314 * 315 * @return the determined equality 316 */ 317 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 318 ITaskInstance taskInstance2, 319 TaskEquality requiredEqualityLevel) 320 { 321 if (requiredEqualityLevel == null) { 322 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 323 } 324 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 325 (taskInstance1, taskInstance2, requiredEqualityLevel)) 326 { 327 return requiredEqualityLevel; 328 } 329 else { 330 return TaskEquality.UNEQUAL; 331 } 332 } 193 333 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskComparisonRule.java
r1146 r1294 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 18 19 19 20 /** 20 21 * <p> 21 * A task comparison rule is used by the {@link TaskEqualityRuleManager} to compare tasks with22 * each other. It provides several methods to be called for a comparison.22 * A task comparison rule is used by the {@link TaskEqualityRuleManager} to compare tasks and 23 * task instances with each other. It provides several methods to be called for a comparison. 23 24 * </p> 24 25 * … … 90 91 public TaskEquality compare(ITask task1, ITask task2); 91 92 93 /** 94 * <p> 95 * checks if the rule is applicable for comparing the two provided task instances 96 * </p> 97 * 98 * @param instance1 the first task instance to compare 99 * @param instance2 the second task instance to compare 100 * 101 * @return true, if the rule is applicable, false else 102 */ 103 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2); 104 105 /** 106 * <p> 107 * checks, if the provided task instances are lexically equal 108 * </p> 109 * 110 * @param instance1 the first task instance to compare 111 * @param instance2 the second task instance to compare 112 * 113 * @return true, if the tasks are equal, false else 114 */ 115 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2); 116 117 /** 118 * <p> 119 * checks, if the provided task instances are syntactically equal 120 * </p> 121 * 122 * @param instance1 the first task instance to compare 123 * @param instance2 the second task instance to compare 124 * 125 * @return true, if the tasks are equal, false else 126 */ 127 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2); 128 129 /** 130 * <p> 131 * checks, if the provided task instances are semantically equal 132 * </p> 133 * 134 * @param instance1 the first task instance to compare 135 * @param instance2 the second task instance to compare 136 * 137 * @return true, if the tasks are equal, false else 138 */ 139 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2); 140 141 /** 142 * <p> 143 * compares two task instances with each other. The result of the method is either a task 144 * instance equality or null. If it is null, it means, that the rule is not able to correctly 145 * compare the two given task instances 146 * </p> 147 * 148 * @param instance1 the first task instance to compare 149 * @param instance2 the second task instance to compare 150 * 151 * @return as described 152 */ 153 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2); 154 92 155 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.java
r1190 r1294 19 19 20 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 22 22 23 /** 23 24 * <p> 24 * The task equality rule manager is capable of comparing tasks based on its internal list25 * of comparison rules. These rules are asked for comparing the two provided tasks. If a rule26 * returns a task equality other than null, this equality is returned. Otherwise the next rule27 * is asked.25 * The task equality rule manager is capable of comparing tasks and task instances based on its 26 * internal list of comparison rules. These rules are asked for comparing the two provided tasks or 27 * task instance. If a rule returns a task equality other than null, this equality is returned. 28 * Otherwise the next rule is asked. 28 29 * </p> 29 30 * 30 * @version $Revision: $ $Date: 19.02.2012$ 31 * @author 2012, last modified by $Author: patrick$ 31 * @author Patrick Harms 32 32 */ 33 33 public class TaskEqualityRuleManager { … … 269 269 } 270 270 271 /** 272 * <p> 273 * this method performs a comparison of the two provided task instances. It iterates its 274 * internal comparison rules. If the first rule returns a task instance equality other than 275 * null, this equality is returned. Otherwise the next rule is tried. If no rule returns an 276 * equality <code>TaskEquality.UNEQUAL</code> is returned. 277 * </p> 278 * 279 * @param instance1 the first task instance to be compared 280 * @param instance2 the second task instance to be compared 281 * 282 * @return as described 283 * 284 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 285 * manager before a call to this method. 286 */ 287 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) 288 throws IllegalStateException 289 { 290 if (mRuleIndex == null) { 291 throw new IllegalStateException("not initialized"); 292 } 293 294 // LOG.info("checking for equality of " + instance1 + " and " + instance2); 295 TaskEquality instanceEquality = null; 296 297 for (TaskComparisonRule rule : mRuleIndex) { 298 if (rule.isApplicable(instance1, instance2)) { 299 instanceEquality = rule.compare(instance1, instance2); 300 if (instanceEquality != null) { 301 // LOG.warning("used rule " + rule + " for equality check"); 302 return instanceEquality; 303 } 304 } 305 } 306 307 // LOG.warning("no rule could be applied --> handling tasks as unequal"); 308 309 return TaskEquality.UNEQUAL; 310 } 311 312 /** 313 * <p> 314 * this method compares two task instances with respect to the given equality level and returns 315 * true, if this level is given. 316 * </p> 317 * 318 * @param instance1 the first task instance to be compared 319 * @param instance2 the second task instance to be compared 320 * @param equalityLevel the level of equality to be checked for 321 * 322 * @return as described 323 * 324 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 325 * manager before a call to this method. 326 */ 327 public boolean areAtLeastEqual(ITaskInstance instance1, 328 ITaskInstance instance2, 329 TaskEquality equalityLevel) 330 { 331 if (equalityLevel == null) { 332 throw new IllegalArgumentException("required equality level must not be null"); 333 } 334 335 switch (equalityLevel) { 336 case IDENTICAL: 337 return areIdentical(instance1, instance2); 338 case LEXICALLY_EQUAL: 339 return areLexicallyEqual(instance1, instance2); 340 case SYNTACTICALLY_EQUAL: 341 return areSyntacticallyEqual(instance1, instance2); 342 case SEMANTICALLY_EQUAL: 343 return areSemanticallyEqual(instance1, instance2); 344 case UNEQUAL: 345 return !areSemanticallyEqual(instance1, instance2); 346 default: 347 throw new IllegalArgumentException("unknown required equality: " + equalityLevel); 348 } 349 } 350 351 /** 352 * <p> 353 * this method checks if the two given task instances are identical. For this, it iterates its 354 * internal comparison rules. If the first rule returns true, than this method returns true 355 * as well. If no rule returns true, this method returns false. 356 * </p> 357 * 358 * @param instance1 the first task instance to be compared 359 * @param instance2 the second task instance to be compared 360 * 361 * @return as described 362 * 363 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 364 * manager before a call to this method. 365 */ 366 public boolean areIdentical(ITaskInstance instance1, ITaskInstance instance2) { 367 if (mRuleIndex == null) { 368 throw new IllegalStateException("not initialized"); 369 } 370 371 for (TaskComparisonRule rule : mRuleIndex) { 372 if (rule.isApplicable(instance1, instance2) && 373 rule.areLexicallyEqual(instance1, instance2)) 374 { 375 return true; 376 } 377 } 378 379 return false; 380 } 381 382 /** 383 * <p> 384 * this method checks if the two given task instances are lexically equal. For this, it 385 * iterates its internal comparison rules. If the first rule returns true, than this method 386 * returns true, as well. If no rule returns true, this method returns false. 387 * </p> 388 * 389 * @param instance1 the first task instance to be compared 390 * @param instance2 the second task instance to be compared 391 * 392 * @return as described 393 * 394 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 395 * manager before a call to this method. 396 */ 397 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 398 if (mRuleIndex == null) { 399 throw new IllegalStateException("not initialized"); 400 } 401 402 for (TaskComparisonRule rule : mRuleIndex) { 403 if (rule.isApplicable(instance1, instance2) && 404 rule.areLexicallyEqual(instance1, instance2)) 405 { 406 return true; 407 } 408 } 409 410 return false; 411 } 412 413 /** 414 * <p> 415 * this method checks if the two given task instances are syntactically equal. For this, it 416 * iterates its internal comparison rules. If the first rule returns true, than this method 417 * returns true, as well. If no rule returns true, this method returns false. 418 * </p> 419 * 420 * @param instance1 the first task instance to be compared 421 * @param instance2 the second task instance to be compared 422 * 423 * @return as described 424 * 425 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 426 * manager before a call to this method. 427 */ 428 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 429 if (mRuleIndex == null) { 430 throw new IllegalStateException("not initialized"); 431 } 432 433 for (TaskComparisonRule rule : mRuleIndex) { 434 if (rule.isApplicable(instance1, instance2) && 435 rule.areSyntacticallyEqual(instance1, instance2)) 436 { 437 return true; 438 } 439 } 440 441 return false; 442 } 443 444 /** 445 * <p> 446 * this method checks if the two given task instances are semantically equal. For this, it 447 * iterates its internal comparison rules. If the first rule returns true, than this method 448 * returns true, as well. If no rule returns true, this method returns false. 449 * </p> 450 * 451 * @param instance1 the first task instance to be compared 452 * @param instance2 the second task instance to be compared 453 * 454 * @return as described 455 * 456 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 457 * manager before a call to this method. 458 */ 459 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 460 if (mRuleIndex == null) { 461 throw new IllegalStateException("not initialized"); 462 } 463 464 for (TaskComparisonRule rule : mRuleIndex) { 465 if (rule.isApplicable(instance1, instance2) && 466 rule.areSemanticallyEqual(instance1, instance2)) 467 { 468 return true; 469 } 470 } 471 472 return false; 473 } 474 271 475 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskIdentityRule.java
r1146 r1294 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 18 19 19 20 /** 20 21 * <p> 21 22 * This comparison rule returns <code>TaskEquality.IDENTICAL</code> if the comparison of the two 22 * tasks using the <code>==</code> operator or the <code>equals</code> method return true.23 * Else it returns null to denote, thatit can not compare the tasks.23 * tasks using the <code>==</code> operator returns true. Else it returns null to denote, that 24 * it can not compare the tasks. 24 25 * </p> 25 26 * … … 30 31 31 32 /* (non-Javadoc) 32 * @see NodeComparisonRule#isApplicable(ITask, ITask)33 * @see TaskComparisonRule#isApplicable(ITask, ITask) 33 34 */ 34 35 @Override … … 38 39 39 40 /* (non-Javadoc) 40 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)41 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 41 42 */ 42 43 @Override … … 46 47 47 48 /* (non-Javadoc) 48 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)49 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 49 50 */ 50 51 @Override … … 54 55 55 56 /* (non-Javadoc) 56 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask)57 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 57 58 */ 58 59 @Override … … 62 63 63 64 /* (non-Javadoc) 64 * @see NodeComparisonRule#compare(ITask, ITask)65 * @see TaskComparisonRule#compare(ITask, ITask) 65 66 */ 66 67 @Override … … 74 75 } 75 76 77 /* (non-Javadoc) 78 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 79 */ 80 @Override 81 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 82 return (instance1.getTask() == instance2.getTask()); 83 } 84 85 /* (non-Javadoc) 86 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 87 */ 88 @Override 89 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 90 return (instance1.getTask() == instance2.getTask()); 91 } 92 93 /* (non-Javadoc) 94 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 95 */ 96 @Override 97 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 98 return (instance1.getTask() == instance2.getTask()); 99 } 100 101 /* (non-Javadoc) 102 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 103 */ 104 @Override 105 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 106 return (instance1.getTask() == instance2.getTask()); 107 } 108 109 /* (non-Javadoc) 110 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 111 */ 112 @Override 113 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 114 if (isApplicable(instance1, instance2)) { 115 return TaskEquality.IDENTICAL; 116 } 117 else { 118 return null; 119 } 120 } 121 76 122 }
Note: See TracChangeset
for help on using the changeset viewer.