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