Changeset 2132 for trunk/autoquest-core-tasktrees
- Timestamp:
- 08/24/16 10:17:41 (8 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java
r1889 r2132 16 16 17 17 import java.util.Collection; 18 import java.util.HashMap; 18 19 import java.util.LinkedList; 19 20 import java.util.List; 21 import java.util.Map; 20 22 import java.util.logging.Level; 21 23 22 24 import de.ugoe.cs.autoquest.eventcore.Event; 25 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 23 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 24 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; … … 72 75 /** 73 76 * <p> 77 * The default task equality considered when comparing task instances initially 78 * </p> 79 */ 80 private TaskEquality minimalTaskEquality = TaskEquality.SEMANTICALLY_EQUAL; 81 82 /** 83 * <p> 84 * If this flag is set, then the task tree manager will not create new event tasks for any 85 * events. Instead, it will check using the hashcode and equal methods of the provided events 86 * if a certain event has already occurred, and if so, the corresponding event task will be 87 * reused. 88 * </p> 89 */ 90 private boolean useEventEqualityForTaskComparison; 91 92 /** 93 * <p> 94 * the minimum number of event task instances a sequence must cover to still detect it as a 95 * representative task 96 * </p> 97 */ 98 private int minimumSequenceCoverage;; 99 100 /** 101 * <p> 102 * If the flag {@link #useEventEqualityForTaskComparison} is set, then here the task tree 103 * manager stores the already created event tasks. 104 * </p> 105 */ 106 private Map<Event, IEventTask> eventTasks = new HashMap<>(); 107 108 /** 109 * <p> 74 110 * initializes the task tree manager 75 111 * </p> 76 112 */ 77 113 public TaskTreeManager() { 78 sessions = new LinkedList<IUserSession>();114 this.sessions = new LinkedList<IUserSession>(); 79 115 } 80 116 … … 96 132 * single events 97 133 */ 98 public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 134 public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions, 135 boolean useEventEqualityForTaskComparison, 136 int minimumSequenceCoverage) 137 { 99 138 if ((currentSession != null) || (sessions.size() > 0)) { 100 139 throw new IllegalStateException("do not mix calls to this method with calls to the " + … … 102 141 "variant instead."); 103 142 } 143 144 this.useEventEqualityForTaskComparison = useEventEqualityForTaskComparison; 145 146 if (useEventEqualityForTaskComparison) { 147 // if we do this, we also need to consider identity of event tasks afterwards 148 minimalTaskEquality = TaskEquality.IDENTICAL; 149 } 150 151 this.minimumSequenceCoverage = minimumSequenceCoverage; 104 152 105 153 for (List<Event> newSession : newSessions) { … … 117 165 /** 118 166 * <p> 167 * call {@link #createTaskModel(Collection, boolean, int)} with false for use event equality 168 * for comparison and 0 for the minimum number of covered events per sequence 169 * </p> 170 * 171 * @param newSessions the user sessions of which the task model shall be created 172 * 173 * @return the task model created from the user sessions 174 * 175 * @throws IllegalStateException if the task manager is already used by providing it with 176 * single events 177 */ 178 public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 179 return createTaskModel(newSessions, false, 0); 180 } 181 182 /** 183 * <p> 119 184 * handles a single event that occurred in a user session. 120 185 * </p> … … 124 189 public void handleNewEvent(Event event) { 125 190 assertSessionSequence(); 126 String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 127 IEventTask eventTask = taskFactory.createNewEventTask(description); 128 taskBuilder.addExecutedTask 129 (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 191 192 if (!useEventEqualityForTaskComparison) { 193 String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 194 IEventTask eventTask = taskFactory.createNewEventTask(description); 195 taskBuilder.addExecutedTask 196 (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 197 } 198 else { 199 IEventTask eventTask = eventTasks.get(event); 200 if (eventTask == null) { 201 String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 202 eventTask = taskFactory.createNewEventTask(description); 203 eventTasks.put(event, eventTask); 204 } 205 206 taskBuilder.addExecutedTask 207 (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 208 } 130 209 } 131 210 … … 157 236 (Level.INFO, "applying temporal relationship generation rules for detecting tasks"); 158 237 159 ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule(sessions); 238 ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule 239 (sessions, minimalTaskEquality, minimumSequenceCoverage); 160 240 161 241 return taskFactory.createTaskModel(sessions); -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/CondenseSimilarTasksRule.java
r1982 r2132 444 444 445 445 new SequenceForTaskDetectionRule 446 (TaskEquality.IDENTICAL, taskFactory, taskBuilder ).apply(flattenedSessionList);446 (TaskEquality.IDENTICAL, taskFactory, taskBuilder, 0).apply(flattenedSessionList); 447 447 448 448 Map<ITaskInstance, ITaskInstance> replacements = new HashMap<ITaskInstance, ITaskInstance>(); -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r1889 r2132 25 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 26 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;28 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 29 28 import de.ugoe.cs.util.console.Console; … … 102 101 /** 103 102 * <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 103 * initialize the manager 121 104 * </p> … … 144 127 frameFilter.add(IDialog.class); 145 128 //frameFilter.add(ICanvas.class); 146 147 sessionScopeRules = new ISessionScopeRule[] {148 new SequenceForTaskDetectionRule149 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder),150 new CondenseSimilarTasksRule151 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder),152 /*new DefaultTaskSequenceDetectionRule153 (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder),154 new DefaultTaskSequenceDetectionRule155 (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder),*/156 /*new TreeScopeWrapperRule157 (new DefaultIterationDetectionRule158 (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder)),159 new TreeScopeWrapperRule160 (new DefaultIterationDetectionRule161 (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder)),162 new TreeScopeWrapperRule163 (new DefaultIterationDetectionRule164 (NodeEquality.SEMANTICALLY_EQUAL, taskFactory, taskTreeBuilder))*/165 };166 167 //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter));168 169 taskScopeRules = new ITaskInstanceScopeRule[] {170 //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder),171 //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder),172 //new TrackBarSelectionDetectionRule(taskFactory, taskBuilder),173 //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder),174 };175 176 }177 178 /**179 * <p>180 * applies the known rules to the provided sessions. For the creation of further tasks,181 * the provided builder and task factory are utilized. The method expects, that no more data182 * is available and, therefore, finalizes the rule application.183 * </p>184 *185 * @param sessions the sessions to be processed186 */187 public void applyRules(List<IUserSession> sessions) {188 applyRules(sessionScopeRules, sessions, "");189 129 } 190 130 … … 197 137 * @param sessions the sessions to be processed 198 138 */ 199 public void applyTaskDetectionRule(List<IUserSession> sessions) { 139 public void applyTaskDetectionRule(List<IUserSession> sessions, 140 TaskEquality minimalTaskEquality, 141 int minimumSequenceCoverage) 142 { 200 143 ISessionScopeRule[] rules = new ISessionScopeRule[] { 201 new SequenceForTaskDetectionRule 202 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder)144 new SequenceForTaskDetectionRule(minimalTaskEquality, taskFactory, taskBuilder, 145 minimumSequenceCoverage) 203 146 }; 204 147 … … 261 204 262 205 //dumpTask(parent, ""); 263 264 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) {265 noOfRuleApplications +=266 applyRules(taskScopeRules, newParent, logIndent + " ");267 }268 206 } 269 207 } … … 271 209 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 272 210 273 }274 275 if (noOfRuleApplications <= 0) {276 Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " +277 "relationship generated");278 }279 280 return noOfRuleApplications;281 }282 283 /**284 * <p>285 * applies the known rules to the provided parent task. For the creation of further tasks,286 * the provided builder and task factory are utilized. If the finalize parameter is true, the287 * rule application is finalized as far as possible without waiting for further data. If it is288 * false, the rule application is broken up at the first rule returning, that its application289 * would be feasible. The method calls itself for each parent task created through the rule290 * application. In this case, the finalize parameter is always true.291 * </p>292 *293 * @param parent the parent task to apply the rules on294 * @param finalize used to indicate, if the rule application shall break up if a rule would295 * be feasible if further data was available, or not.296 * @param logIndent simply used for logging purposes to indent the log messages depending297 * on the recursion depth of calling this method.298 */299 private int applyRules(ITaskInstanceScopeRule[] rules,300 ITaskInstance taskInstance,301 String logIndent)302 {303 Console.traceln(Level.FINER, logIndent + "applying rules on " + taskInstance);304 305 int noOfRuleApplications = 0;306 307 for (ITaskInstanceScopeRule rule : rules) {308 RuleApplicationResult result;309 do {310 Console.traceln311 (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstance);312 result = rule.apply(taskInstance);313 314 if ((result != null) &&315 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED))316 {317 Console.traceln318 (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstance);319 noOfRuleApplications++;320 321 //dumpTask(parent, "");322 323 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) {324 noOfRuleApplications +=325 applyRules(taskScopeRules, newParent, logIndent + " ");326 }327 }328 }329 while ((result != null) &&330 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED));331 211 } 332 212
Note: See TracChangeset
for help on using the changeset viewer.