Changeset 1733 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
- Timestamp:
- 09/05/14 19:33:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r1552 r1733 33 33 * 34 34 * <p> 35 * This class is responsible for applying temporal relationship rules on a task tree. Through this, 36 * a flat task tree is restructured to have more depth but to include more temporal relationships 37 * between tasks which are not only a major sequence. I.e. through the application of the 38 * rules iterations and selections of tasks are detected. Which kind of temporal relations 39 * between tasks are detected depends on the {@link ITaskInstanceScopeRule}s known to 35 * This class is responsible for applying temporal relationship rules on a task 36 * tree. Through this, a flat task tree is restructured to have more depth but 37 * to include more temporal relationships between tasks which are not only a 38 * major sequence. I.e. through the application of the rules iterations and 39 * selections of tasks are detected. Which kind of temporal relations between 40 * tasks are detected depends on the {@link ITaskInstanceScopeRule}s known to 40 41 * this class. 41 42 * </p> 42 * <p>The class holds references to the appropriate {@link ITaskInstanceScopeRule}s and calls 43 * their {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 44 * method for each task in the task tree it is needed for. The general behavior of this class is 45 * the following: 43 * <p> 44 * The class holds references to the appropriate {@link ITaskInstanceScopeRule}s 45 * and calls their 46 * {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 47 * method for each task in the task tree it is needed for. The general behavior 48 * of this class is the following: 46 49 * <ol> 47 * <li> 48 * An instance of this class is created using the constructor and calling the 49 * {@link #init()} method afterwards 50 * </li> 51 * <li> 52 * then the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 53 * method is called for a so far unstructured task 54 * </li> 55 * <li> 56 * the class iterates its internal list of rules and calls their 57 * {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 58 * method. 59 * </li> 60 * <li> 61 * the class evaluates the rule application result 62 * <ul> 63 * <li> 64 * if a rule returns a rule application result that is null, the next rule is tried 65 * </li> 66 * <li> 67 * if a rule returns that it would be feasible if more data was available and the rule 68 * application shall not be finalized (see finalize parameter of the applyRules method) 69 * the rule application is broken up 70 * </li> 71 * <li> 72 * if a rule returns, that it was applied, the same rule is applied again until it returns 73 * null or feasible. For each newly created parent task provided in the rule application 74 * result, the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 75 * method is called. 76 * </li> 77 * </ul> 78 * </li> 50 * <li> 51 * An instance of this class is created using the constructor and calling the 52 * {@link #init()} method afterwards</li> 53 * <li> 54 * then the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 55 * method is called for a so far unstructured task</li> 56 * <li> 57 * the class iterates its internal list of rules and calls their 58 * {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 59 * method.</li> 60 * <li> 61 * the class evaluates the rule application result 62 * <ul> 63 * <li> 64 * if a rule returns a rule application result that is null, the next rule is 65 * tried</li> 66 * <li> 67 * if a rule returns that it would be feasible if more data was available and 68 * the rule application shall not be finalized (see finalize parameter of the 69 * applyRules method) the rule application is broken up</li> 70 * <li> 71 * if a rule returns, that it was applied, the same rule is applied again until 72 * it returns null or feasible. For each newly created parent task provided in 73 * the rule application result, the 74 * {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} method is 75 * called.</li> 76 * </ul> 77 * </li> 79 78 * </ol> 80 * Through this, all rules are tried to be applied at least once to the provided parent task and81 * all parent tasks created during the rule application.79 * Through this, all rules are tried to be applied at least once to the provided 80 * parent task and all parent tasks created during the rule application. 82 81 * </p> 83 82 * … … 85 84 */ 86 85 public class TemporalRelationshipRuleManager { 87 88 /** 89 * <p> 90 * the task factory to be used during rule application 91 * </p> 92 */ 93 private ITaskFactory taskFactory; 94 95 /** 96 * <p> 97 * the task builder to be used during rule application 98 * </p> 99 */ 100 private ITaskBuilder taskBuilder; 101 102 /** 103 * <p> 104 * the temporal relationship rules known to the manager that are executed on whole sessions. 105 * The rules are applied in the order they occur in this list. 106 * </p> 107 */ 108 private ISessionScopeRule[] sessionScopeRules; 109 110 /** 111 * <p> 112 * the temporal relationship rules known to the manager that are executed on whole sub trees. 113 * The rules are applied in the order they occur in this list. 114 * </p> 115 */ 116 private ITaskInstanceScopeRule[] taskScopeRules; 117 118 /** 119 * <p> 120 * initialize the manager 121 * </p> 122 * 123 * @param taskFactory the task factory to be used for instantiating new task tree 124 * tasks during rule application 125 * @param taskBuilder the task builder to be used for linking tasks 126 * with each other during rule application 127 */ 128 public TemporalRelationshipRuleManager(ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 129 super(); 130 this.taskFactory = taskFactory; 131 this.taskBuilder = taskBuilder; 132 } 133 134 /** 135 * <p> 136 * initialized the temporal relationship rule manager by instantiating the known rules and 137 * providing them with a reference to the task equality manager or other information they need. 138 * </p> 139 */ 140 public void init() { 141 List<Class<? extends IGUIElement>> frameFilter = 142 new ArrayList<Class<? extends IGUIElement>>(); 143 frameFilter.add(IFrame.class); 144 frameFilter.add(IDialog.class); 145 //frameFilter.add(ICanvas.class); 146 147 sessionScopeRules = new ISessionScopeRule[] { 148 new SequenceForTaskDetectionRuleAlignment 149 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder), 150 /*new DefaultTaskSequenceDetectionRule 151 (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder), 152 new DefaultTaskSequenceDetectionRule 153 (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder),*/ 154 /*new TreeScopeWrapperRule 155 (new DefaultIterationDetectionRule 156 (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder)), 157 new TreeScopeWrapperRule 158 (new DefaultIterationDetectionRule 159 (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder)), 160 new TreeScopeWrapperRule 161 (new DefaultIterationDetectionRule 162 (NodeEquality.SEMANTICALLY_EQUAL, taskFactory, taskTreeBuilder))*/ 163 }; 164 165 //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 166 167 taskScopeRules = new ITaskInstanceScopeRule[] { 168 //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 169 //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder), 170 //new TrackBarSelectionDetectionRule(taskFactory, taskBuilder), 171 //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder), 172 }; 173 174 } 175 176 /** 177 * <p> 178 * applies the known rules to the provided sessions. For the creation of further tasks, 179 * the provided builder and task factory are utilized. The method expects, that no more data 180 * is available and, therefore, finalizes the rule application. 181 * </p> 182 * 183 * @param taskFactory the task factory to be used for instantiating new tasks. 184 */ 185 public void applyRules(List<IUserSession> sessions) { 186 applyRules(sessionScopeRules, sessions, ""); 187 } 188 189 /** 190 * <p> 191 * applies the known rules to the provided parent task. For the creation of further tasks, 192 * the provided builder and task factory are utilized. If the finalize parameter is true, the 193 * rule application is finalized as far as possible without waiting for further data. If it is 194 * false, the rule application is broken up at the first rule returning, that its application 195 * would be feasible. The method calls itself for each parent task created through the rule 196 * application. In this case, the finalize parameter is always true. 197 * </p> 198 * 199 * @param parent the parent task to apply the rules on 200 * @param finalize used to indicate, if the rule application shall break up if a rule would 201 * be feasible if further data was available, or not. 202 * @param logIndent simply used for logging purposes to indent the log messages depending 203 * on the recursion depth of calling this method. 204 */ 205 private int applyRules(ISessionScopeRule[] rules, 206 List<IUserSession> sessions, 207 String logIndent) 208 { 209 Console.traceln 210 (Level.FINER, logIndent + "applying rules for " + sessions.size() + " sessions"); 211 212 int noOfRuleApplications = 0; 213 214 for (ISessionScopeRule rule : rules) { 215 RuleApplicationResult result; 216 do { 217 Console.traceln(Level.FINER, logIndent + "trying rule " + rule); 218 result = rule.apply(sessions); 219 220 if ((result != null) && 221 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 222 { 223 Console.traceln(Level.FINE, logIndent + "applied rule " + rule); 224 noOfRuleApplications++; 225 226 //dumpTask(parent, ""); 227 228 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 229 noOfRuleApplications += 230 applyRules(taskScopeRules, newParent, logIndent + " "); 231 } 232 } 233 } 234 while ((result != null) && 235 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 236 237 } 238 239 if (noOfRuleApplications <= 0) { 240 Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 241 "relationship generated"); 242 } 243 244 return noOfRuleApplications; 245 } 246 247 /** 248 * <p> 249 * applies the known rules to the provided parent task. For the creation of further tasks, 250 * the provided builder and task factory are utilized. If the finalize parameter is true, the 251 * rule application is finalized as far as possible without waiting for further data. If it is 252 * false, the rule application is broken up at the first rule returning, that its application 253 * would be feasible. The method calls itself for each parent task created through the rule 254 * application. In this case, the finalize parameter is always true. 255 * </p> 256 * 257 * @param parent the parent task to apply the rules on 258 * @param finalize used to indicate, if the rule application shall break up if a rule would 259 * be feasible if further data was available, or not. 260 * @param logIndent simply used for logging purposes to indent the log messages depending 261 * on the recursion depth of calling this method. 262 */ 263 private int applyRules(ITaskInstanceScopeRule[] rules, 264 ITaskInstance taskInstance, 265 String logIndent) 266 { 267 Console.traceln(Level.FINER, logIndent + "applying rules on " + taskInstance); 268 269 int noOfRuleApplications = 0; 270 271 for (ITaskInstanceScopeRule rule : rules) { 272 RuleApplicationResult result; 273 do { 274 Console.traceln 275 (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstance); 276 result = rule.apply(taskInstance); 277 278 if ((result != null) && 279 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 280 { 281 Console.traceln 282 (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstance); 283 noOfRuleApplications++; 284 285 //dumpTask(parent, ""); 286 287 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 288 noOfRuleApplications += 289 applyRules(taskScopeRules, newParent, logIndent + " "); 290 } 291 } 292 } 293 while ((result != null) && 294 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 295 } 296 297 if (noOfRuleApplications <= 0) { 298 Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 299 "relationship generated"); 300 } 301 302 return noOfRuleApplications; 303 } 304 305 /** 306 * 307 */ 308 /*private void dumpTask(ITask task, String indent) { 309 StringBuffer message = new StringBuffer(); 310 message.append(indent); 311 message.append(task); 312 if (task.getDescription() != null) { 313 message.append('('); 314 message.append(task.getDescription()); 315 message.append(')'); 316 } 317 318 Console.traceln(Level.FINER, message.toString()); 319 320 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 321 for (ITask child : task.getChildren()) { 322 dumpTask(child, indent + " "); 323 } 324 } 325 }*/ 86 87 /** 88 * <p> 89 * the task factory to be used during rule application 90 * </p> 91 */ 92 private final ITaskFactory taskFactory; 93 94 /** 95 * <p> 96 * the task builder to be used during rule application 97 * </p> 98 */ 99 private final ITaskBuilder taskBuilder; 100 101 /** 102 * <p> 103 * the temporal relationship rules known to the manager that are executed on 104 * whole sessions. The rules are applied in the order they occur in this 105 * list. 106 * </p> 107 */ 108 private ISessionScopeRule[] sessionScopeRules; 109 110 /** 111 * <p> 112 * the temporal relationship rules known to the manager that are executed on 113 * whole sub trees. The rules are applied in the order they occur in this 114 * list. 115 * </p> 116 */ 117 private ITaskInstanceScopeRule[] taskScopeRules; 118 119 /** 120 * <p> 121 * initialize the manager 122 * </p> 123 * 124 * @param taskFactory 125 * the task factory to be used for instantiating new task tree 126 * tasks during rule application 127 * @param taskBuilder 128 * the task builder to be used for linking tasks with each other 129 * during rule application 130 */ 131 public TemporalRelationshipRuleManager(ITaskFactory taskFactory, 132 ITaskBuilder taskBuilder) { 133 super(); 134 this.taskFactory = taskFactory; 135 this.taskBuilder = taskBuilder; 136 } 137 138 /** 139 * <p> 140 * applies the known rules to the provided parent task. For the creation of 141 * further tasks, the provided builder and task factory are utilized. If the 142 * finalize parameter is true, the rule application is finalized as far as 143 * possible without waiting for further data. If it is false, the rule 144 * application is broken up at the first rule returning, that its 145 * application would be feasible. The method calls itself for each parent 146 * task created through the rule application. In this case, the finalize 147 * parameter is always true. 148 * </p> 149 * 150 * @param parent 151 * the parent task to apply the rules on 152 * @param finalize 153 * used to indicate, if the rule application shall break up if a 154 * rule would be feasible if further data was available, or not. 155 * @param logIndent 156 * simply used for logging purposes to indent the log messages 157 * depending on the recursion depth of calling this method. 158 */ 159 private int applyRules(ISessionScopeRule[] rules, 160 List<IUserSession> sessions, String logIndent) { 161 Console.traceln(Level.FINER, logIndent + "applying rules for " 162 + sessions.size() + " sessions"); 163 164 int noOfRuleApplications = 0; 165 166 for (final ISessionScopeRule rule : rules) { 167 RuleApplicationResult result; 168 do { 169 Console.traceln(Level.FINER, logIndent + "trying rule " + rule); 170 result = rule.apply(sessions); 171 172 if ((result != null) 173 && (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) { 174 Console.traceln(Level.FINE, logIndent + "applied rule " 175 + rule); 176 noOfRuleApplications++; 177 178 // dumpTask(parent, ""); 179 180 for (final ITaskInstance newParent : result 181 .getNewlyCreatedTaskInstances()) { 182 noOfRuleApplications += applyRules(taskScopeRules, 183 newParent, logIndent + " "); 184 } 185 } 186 } while ((result != null) 187 && (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 188 189 } 190 191 if (noOfRuleApplications <= 0) { 192 Console.traceln(Level.FINE, logIndent 193 + "no rules applied --> no temporal " 194 + "relationship generated"); 195 } 196 197 return noOfRuleApplications; 198 } 199 200 /** 201 * <p> 202 * applies the known rules to the provided parent task. For the creation of 203 * further tasks, the provided builder and task factory are utilized. If the 204 * finalize parameter is true, the rule application is finalized as far as 205 * possible without waiting for further data. If it is false, the rule 206 * application is broken up at the first rule returning, that its 207 * application would be feasible. The method calls itself for each parent 208 * task created through the rule application. In this case, the finalize 209 * parameter is always true. 210 * </p> 211 * 212 * @param parent 213 * the parent task to apply the rules on 214 * @param finalize 215 * used to indicate, if the rule application shall break up if a 216 * rule would be feasible if further data was available, or not. 217 * @param logIndent 218 * simply used for logging purposes to indent the log messages 219 * depending on the recursion depth of calling this method. 220 */ 221 private int applyRules(ITaskInstanceScopeRule[] rules, 222 ITaskInstance taskInstance, String logIndent) { 223 Console.traceln(Level.FINER, logIndent + "applying rules on " 224 + taskInstance); 225 226 int noOfRuleApplications = 0; 227 228 for (final ITaskInstanceScopeRule rule : rules) { 229 RuleApplicationResult result; 230 do { 231 Console.traceln(Level.FINER, logIndent + "trying rule " + rule 232 + " on " + taskInstance); 233 result = rule.apply(taskInstance); 234 235 if ((result != null) 236 && (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) { 237 Console.traceln(Level.FINE, logIndent + "applied rule " 238 + rule + " on " + taskInstance); 239 noOfRuleApplications++; 240 241 // dumpTask(parent, ""); 242 243 for (final ITaskInstance newParent : result 244 .getNewlyCreatedTaskInstances()) { 245 noOfRuleApplications += applyRules(taskScopeRules, 246 newParent, logIndent + " "); 247 } 248 } 249 } while ((result != null) 250 && (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 251 } 252 253 if (noOfRuleApplications <= 0) { 254 Console.traceln(Level.FINE, logIndent 255 + "no rules applied --> no temporal " 256 + "relationship generated"); 257 } 258 259 return noOfRuleApplications; 260 } 261 262 /** 263 * <p> 264 * applies the known rules to the provided sessions. For the creation of 265 * further tasks, the provided builder and task factory are utilized. The 266 * method expects, that no more data is available and, therefore, finalizes 267 * the rule application. 268 * </p> 269 * 270 * @param taskFactory 271 * the task factory to be used for instantiating new tasks. 272 */ 273 public void applyRules(List<IUserSession> sessions) { 274 applyRules(sessionScopeRules, sessions, ""); 275 } 276 277 /** 278 * <p> 279 * initialized the temporal relationship rule manager by instantiating the 280 * known rules and providing them with a reference to the task equality 281 * manager or other information they need. 282 * </p> 283 */ 284 public void init() { 285 final List<Class<? extends IGUIElement>> frameFilter = new ArrayList<Class<? extends IGUIElement>>(); 286 frameFilter.add(IFrame.class); 287 frameFilter.add(IDialog.class); 288 // frameFilter.add(ICanvas.class); 289 290 sessionScopeRules = new ISessionScopeRule[] { new SequenceForTaskDetectionRuleAlignment( 291 TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder), 292 /* 293 * new DefaultTaskSequenceDetectionRule 294 * (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder), new 295 * DefaultTaskSequenceDetectionRule (NodeEquality.LEXICALLY_EQUAL, 296 * taskFactory, taskTreeBuilder), 297 */ 298 /* 299 * new TreeScopeWrapperRule (new DefaultIterationDetectionRule 300 * (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder)), new 301 * TreeScopeWrapperRule (new DefaultIterationDetectionRule 302 * (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder)), 303 * new TreeScopeWrapperRule (new DefaultIterationDetectionRule 304 * (NodeEquality.SEMANTICALLY_EQUAL, taskFactory, taskTreeBuilder)) 305 */ 306 }; 307 308 // treeScopeRules.add(new 309 // DefaultGuiElementSequenceDetectionRule(frameFilter)); 310 311 taskScopeRules = new ITaskInstanceScopeRule[] { 312 // new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 313 // new EventSequenceOnSameTargetDetectionRule(taskFactory, 314 // taskTreeBuilder), 315 // new TrackBarSelectionDetectionRule(taskFactory, taskBuilder), 316 // new DefaultGuiEventSequenceDetectionRule(taskFactory, 317 // taskTreeBuilder), 318 }; 319 320 } 321 322 /** 323 * 324 */ 325 /* 326 * private void dumpTask(ITask task, String indent) { StringBuffer message = 327 * new StringBuffer(); message.append(indent); message.append(task); if 328 * (task.getDescription() != null) { message.append('('); 329 * message.append(task.getDescription()); message.append(')'); } 330 * 331 * Console.traceln(Level.FINER, message.toString()); 332 * 333 * if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 334 * for (ITask child : task.getChildren()) { dumpTask(child, indent + " "); 335 * } } } 336 */ 326 337 327 338 }
Note: See TracChangeset
for help on using the changeset viewer.