[1552] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.tasktrees.temporalrelation; |
---|
| 16 | |
---|
[1718] | 17 | import java.io.File; |
---|
[1707] | 18 | import java.io.FileInputStream; |
---|
| 19 | import java.io.FileOutputStream; |
---|
| 20 | import java.io.IOException; |
---|
| 21 | import java.io.ObjectInputStream; |
---|
| 22 | import java.io.ObjectOutputStream; |
---|
| 23 | import java.io.Serializable; |
---|
[1552] | 24 | import java.util.ArrayList; |
---|
[1621] | 25 | import java.util.Collections; |
---|
| 26 | import java.util.Comparator; |
---|
[1552] | 27 | import java.util.HashMap; |
---|
| 28 | import java.util.HashSet; |
---|
| 29 | import java.util.Iterator; |
---|
| 30 | import java.util.LinkedList; |
---|
| 31 | import java.util.List; |
---|
| 32 | import java.util.Map; |
---|
| 33 | import java.util.Set; |
---|
| 34 | import java.util.logging.Level; |
---|
| 35 | |
---|
[1707] | 36 | import de.ugoe.cs.autoquest.CommandHelpers; |
---|
[1711] | 37 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; |
---|
| 38 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; |
---|
[1620] | 39 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; |
---|
[1621] | 40 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; |
---|
[1553] | 41 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; |
---|
[1572] | 42 | import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; |
---|
[1552] | 43 | import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; |
---|
| 44 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
| 45 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
[1630] | 46 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
[1552] | 47 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
[1692] | 48 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
[1552] | 49 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
| 50 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; |
---|
| 51 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 52 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
| 53 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
| 54 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 55 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
| 56 | import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; |
---|
| 57 | import de.ugoe.cs.util.StopWatch; |
---|
| 58 | import de.ugoe.cs.util.console.Console; |
---|
[1707] | 59 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
[1552] | 60 | |
---|
| 61 | /** |
---|
| 62 | * <p> |
---|
[1559] | 63 | * This class implements the major rule for creating task trees based on a set |
---|
| 64 | * of recorded user sessions. For this, it first harmonizes all tasks. This |
---|
| 65 | * eases later comparison. Then it searches the sessions for iterations and |
---|
| 66 | * replaces them accordingly. Then it searches for sub sequences being the |
---|
| 67 | * longest and occurring most often. For each found sub sequence, it replaces |
---|
| 68 | * the occurrences by creating appropriate {@link ISequence}s. Afterwards, again |
---|
| 69 | * searches for iterations and then again for sub sequences until no more |
---|
| 70 | * replacements are done. |
---|
[1552] | 71 | * </p> |
---|
| 72 | * <p> |
---|
| 73 | * |
---|
[1612] | 74 | * |
---|
[1552] | 75 | * @author Patrick Harms |
---|
| 76 | */ |
---|
[1707] | 77 | public class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { |
---|
| 78 | |
---|
| 79 | |
---|
[1552] | 80 | |
---|
[1700] | 81 | private int iteration = 0; |
---|
[1559] | 82 | /** |
---|
| 83 | * <p> |
---|
| 84 | * the task factory to be used for creating substructures for the temporal |
---|
| 85 | * relationships identified during rul application |
---|
| 86 | * </p> |
---|
| 87 | */ |
---|
| 88 | private ITaskFactory taskFactory; |
---|
| 89 | /** |
---|
| 90 | * <p> |
---|
| 91 | * the task builder to be used for creating substructures for the temporal |
---|
| 92 | * relationships identified during rule application |
---|
| 93 | * </p> |
---|
| 94 | */ |
---|
| 95 | private ITaskBuilder taskBuilder; |
---|
[1552] | 96 | |
---|
[1559] | 97 | /** |
---|
| 98 | * <p> |
---|
| 99 | * the task handling strategy to be used for comparing tasks for |
---|
| 100 | * preparation, i.e., before the tasks are harmonized |
---|
| 101 | * </p> |
---|
| 102 | */ |
---|
| 103 | private TaskHandlingStrategy preparationTaskHandlingStrategy; |
---|
[1552] | 104 | |
---|
[1559] | 105 | /** |
---|
| 106 | * <p> |
---|
| 107 | * instantiates the rule and initializes it with a task equality to be |
---|
| 108 | * considered when comparing tasks as well as a task factory and builder to |
---|
| 109 | * be used for creating task structures. |
---|
| 110 | * </p> |
---|
| 111 | * |
---|
| 112 | * @param minimalTaskEquality |
---|
| 113 | * the task equality to be considered when comparing tasks |
---|
| 114 | * @param taskFactory |
---|
| 115 | * the task factory to be used for creating substructures |
---|
| 116 | * @param taskBuilder |
---|
| 117 | * the task builder to be used for creating substructures |
---|
| 118 | */ |
---|
[1552] | 119 | |
---|
[1559] | 120 | SequenceForTaskDetectionRuleAlignment(TaskEquality minimalTaskEquality, |
---|
| 121 | ITaskFactory taskFactory, ITaskBuilder taskBuilder) { |
---|
| 122 | this.taskFactory = taskFactory; |
---|
| 123 | this.taskBuilder = taskBuilder; |
---|
[1552] | 124 | |
---|
[1559] | 125 | this.preparationTaskHandlingStrategy = new TaskHandlingStrategy( |
---|
| 126 | minimalTaskEquality); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /* |
---|
| 130 | * (non-Javadoc) |
---|
| 131 | * |
---|
| 132 | * @see java.lang.Object#toString() |
---|
| 133 | */ |
---|
| 134 | @Override |
---|
| 135 | public String toString() { |
---|
| 136 | return "SequenceForTaskDetectionRuleAlignment"; |
---|
| 137 | } |
---|
| 138 | |
---|
[1710] | 139 | public void saveAppData(String name) { |
---|
| 140 | String objectName = name; |
---|
| 141 | String filename = name + ".dat"; |
---|
| 142 | Object dataObject = GlobalDataContainer.getInstance().getData( |
---|
| 143 | objectName); |
---|
| 144 | if (dataObject == null) { |
---|
| 145 | CommandHelpers.objectNotFoundMessage(objectName); |
---|
| 146 | } |
---|
| 147 | FileOutputStream fos = null; |
---|
| 148 | ObjectOutputStream out = null; |
---|
| 149 | try { |
---|
| 150 | fos = new FileOutputStream(filename); |
---|
| 151 | out = new ObjectOutputStream(fos); |
---|
| 152 | out.writeObject(dataObject); |
---|
| 153 | out.close(); |
---|
| 154 | } catch (IOException ex) { |
---|
| 155 | Console.logException(ex); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | public RuleApplicationData loadAppData(String name) { |
---|
| 160 | String objectName = name; |
---|
| 161 | String filename = name + ".dat"; |
---|
| 162 | |
---|
| 163 | Object data = null; |
---|
| 164 | FileInputStream fis = null; |
---|
| 165 | ObjectInputStream in = null; |
---|
| 166 | try { |
---|
| 167 | fis = new FileInputStream(filename); |
---|
| 168 | in = new ObjectInputStream(fis); |
---|
| 169 | data = in.readObject(); |
---|
| 170 | in.close(); |
---|
| 171 | } catch (IOException ex) { |
---|
| 172 | Console.logException(ex); |
---|
| 173 | } catch (ClassNotFoundException ex) { |
---|
| 174 | Console.logException(ex); |
---|
| 175 | } |
---|
| 176 | if (GlobalDataContainer.getInstance().addData(objectName, data)) { |
---|
| 177 | CommandHelpers.dataOverwritten(objectName); |
---|
| 178 | } |
---|
| 179 | return (RuleApplicationData) GlobalDataContainer.getInstance().getData(name); |
---|
| 180 | } |
---|
| 181 | |
---|
[1559] | 182 | /* |
---|
| 183 | * (non-Javadoc) |
---|
| 184 | * |
---|
| 185 | * @see |
---|
| 186 | * de.ugoe.cs.autoquest.tasktrees.temporalrelation.ISessionScopeRule#apply |
---|
| 187 | * (java.util.List) |
---|
| 188 | */ |
---|
| 189 | @Override |
---|
| 190 | public RuleApplicationResult apply(List<IUserSession> sessions) { |
---|
| 191 | RuleApplicationData appData = new RuleApplicationData(sessions); |
---|
[1718] | 192 | File harmonized = new File("harmonized.dat"); |
---|
| 193 | if(harmonized.exists() && !harmonized.isDirectory()) { |
---|
| 194 | Console.traceln(Level.INFO,"loading harmonized sessions from file"); |
---|
| 195 | appData = loadAppData("harmonized"); |
---|
| 196 | } |
---|
| 197 | else { |
---|
[1710] | 198 | //appData.getStopWatch().start("harmonization"); |
---|
[1707] | 199 | harmonizeEventTaskInstancesModel(appData); |
---|
[1710] | 200 | //appData.getStopWatch().stop("harmonization"); |
---|
| 201 | GlobalDataContainer.getInstance().addData("harmonized", appData); |
---|
[1707] | 202 | //Saving intermediate results to file |
---|
| 203 | Console.traceln(Level.INFO,"saving substitution matrix to file"); |
---|
[1710] | 204 | saveAppData("harmonized"); |
---|
[1707] | 205 | } |
---|
[1718] | 206 | |
---|
| 207 | File substitution = new File("substitution.dat"); |
---|
| 208 | if(!(substitution.exists() && !substitution.isDirectory())) { |
---|
[1710] | 209 | Console.traceln(Level.INFO, "generating substitution matrix from " + appData.getUniqueTasks().size() + " unique tasks"); |
---|
| 210 | appData.getStopWatch().start("substitution matrix"); |
---|
| 211 | appData.getSubmat().generate(appData.getUniqueTasks()); |
---|
| 212 | appData.getStopWatch().stop("substitution matrix"); |
---|
| 213 | GlobalDataContainer.getInstance().addData("substitution", appData); |
---|
| 214 | saveAppData("substitution"); |
---|
| 215 | } |
---|
| 216 | else { |
---|
[1711] | 217 | Console.traceln(Level.INFO,"loading substitution matrix from file"); |
---|
[1710] | 218 | appData = loadAppData("substitution"); |
---|
| 219 | } |
---|
[1698] | 220 | |
---|
[1702] | 221 | |
---|
| 222 | Console.traceln(Level.INFO, "Starting main loop"); |
---|
[1630] | 223 | do { |
---|
[1702] | 224 | Console.traceln(Level.INFO, "Iteration Number: " + iteration); |
---|
[1700] | 225 | iteration++; |
---|
[1710] | 226 | |
---|
[1680] | 227 | appData.detectedAndReplacedTasks = false; |
---|
[1693] | 228 | appData.getStopWatch().start("whole loop"); |
---|
[1680] | 229 | detectAndReplaceIterations(appData); |
---|
[1693] | 230 | appData.getStopWatch().start("task replacement"); |
---|
[1698] | 231 | appData.updateSubstitutionMatrix(); |
---|
[1668] | 232 | detectAndReplaceTasks(appData); // |
---|
[1693] | 233 | appData.getStopWatch().stop("task replacement"); |
---|
[1657] | 234 | appData.getStopWatch().stop("whole loop"); |
---|
[1693] | 235 | appData.getStopWatch().dumpStatistics(System.out); |
---|
[1657] | 236 | appData.getStopWatch().reset(); |
---|
| 237 | |
---|
| 238 | } while (appData.detectedAndReplacedTasks()); |
---|
| 239 | |
---|
[1559] | 240 | Console.println("created " |
---|
| 241 | + appData.getResult().getNewlyCreatedTasks().size() |
---|
| 242 | + " new tasks and " |
---|
| 243 | + appData.getResult().getNewlyCreatedTaskInstances().size() |
---|
| 244 | + " appropriate instances\n"); |
---|
| 245 | |
---|
| 246 | if ((appData.getResult().getNewlyCreatedTasks().size() > 0) |
---|
| 247 | || (appData.getResult().getNewlyCreatedTaskInstances().size() > 0)) { |
---|
| 248 | appData.getResult().setRuleApplicationStatus( |
---|
| 249 | RuleApplicationStatus.FINISHED); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | return appData.getResult(); |
---|
| 253 | } |
---|
| 254 | |
---|
[1698] | 255 | |
---|
[1675] | 256 | private ArrayList<NumberSequence> createNumberSequences( |
---|
| 257 | RuleApplicationData appData) { |
---|
| 258 | ArrayList<NumberSequence> result = new ArrayList<NumberSequence>(); |
---|
| 259 | for (int i = 0; i < appData.getSessions().size(); i++) { |
---|
| 260 | IUserSession session = appData.getSessions().get(i); |
---|
| 261 | NumberSequence templist = new NumberSequence(session.size()); |
---|
| 262 | for (int j = 0; j < session.size(); j++) { |
---|
| 263 | ITaskInstance taskInstance = session.get(j); |
---|
| 264 | templist.getSequence()[j] = taskInstance.getTask().getId(); |
---|
| 265 | } |
---|
| 266 | // Each NumberSequence is identified by its id, beginning to count |
---|
| 267 | // at zero |
---|
| 268 | templist.setId(i); |
---|
| 269 | result.add(templist); |
---|
| 270 | } |
---|
| 271 | return result; |
---|
| 272 | } |
---|
| 273 | |
---|
[1559] | 274 | /** |
---|
| 275 | * <p> |
---|
| 276 | * harmonizes the event task instances by unifying tasks. This is done, as |
---|
| 277 | * initially the event tasks being equal with respect to the considered task |
---|
| 278 | * equality are distinct objects. The comparison of these distinct objects |
---|
| 279 | * is more time consuming than comparing the object references. |
---|
| 280 | * </p> |
---|
| 281 | * |
---|
| 282 | * @param appData |
---|
| 283 | * the rule application data combining all data used for applying |
---|
| 284 | * this rule |
---|
| 285 | * @return Returns the unique tasks symbol map |
---|
| 286 | */ |
---|
[1675] | 287 | private void harmonizeEventTaskInstancesModel(RuleApplicationData appData) { |
---|
[1559] | 288 | Console.traceln(Level.INFO, |
---|
| 289 | "harmonizing task model of event task instances"); |
---|
| 290 | appData.getStopWatch().start("harmonizing event tasks"); |
---|
[1693] | 291 | SymbolMap<ITaskInstance, ITask> uniqueTasks = preparationTaskHandlingStrategy |
---|
| 292 | .createSymbolMap(); |
---|
[1675] | 293 | |
---|
[1559] | 294 | TaskInstanceComparator comparator = preparationTaskHandlingStrategy |
---|
| 295 | .getTaskComparator(); |
---|
| 296 | |
---|
| 297 | int unifiedTasks = 0; |
---|
| 298 | ITask task; |
---|
| 299 | List<IUserSession> sessions = appData.getSessions(); |
---|
[1657] | 300 | for (int j = 0; j < sessions.size(); j++) { |
---|
[1654] | 301 | IUserSession session = sessions.get(j); |
---|
[1657] | 302 | |
---|
[1559] | 303 | for (int i = 0; i < session.size(); i++) { |
---|
| 304 | ITaskInstance taskInstance = session.get(i); |
---|
[1690] | 305 | task = uniqueTasks.getValue(taskInstance); |
---|
[1559] | 306 | |
---|
| 307 | if (task == null) { |
---|
[1693] | 308 | uniqueTasks.addSymbol(taskInstance, taskInstance.getTask()); |
---|
| 309 | appData.getUniqueTasks().add(taskInstance.getTask()); |
---|
| 310 | appData.getNumber2Task().put( |
---|
| 311 | taskInstance.getTask().getId(), |
---|
[1675] | 312 | taskInstance.getTask()); |
---|
[1559] | 313 | } else { |
---|
| 314 | taskBuilder.setTask(taskInstance, task); |
---|
| 315 | unifiedTasks++; |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | comparator.clearBuffers(); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | appData.getStopWatch().stop("harmonizing event tasks"); |
---|
| 322 | Console.traceln(Level.INFO, "harmonized " + unifiedTasks |
---|
[1668] | 323 | + " task occurrences (still " + appData.getUniqueTasks().size() |
---|
[1559] | 324 | + " different tasks)"); |
---|
| 325 | |
---|
| 326 | appData.getStopWatch().dumpStatistics(System.out); |
---|
| 327 | appData.getStopWatch().reset(); |
---|
| 328 | } |
---|
[1552] | 329 | |
---|
[1559] | 330 | /** |
---|
| 331 | * <p> |
---|
| 332 | * searches for direct iterations of single tasks in all sequences and |
---|
| 333 | * replaces them with {@link IIteration}s, respectively appropriate |
---|
| 334 | * instances. Also all single occurrences of a task that is iterated |
---|
| 335 | * somewhen are replaced with iterations to have again an efficient way for |
---|
| 336 | * task comparisons. |
---|
| 337 | * </p> |
---|
| 338 | * |
---|
| 339 | * @param appData |
---|
| 340 | * the rule application data combining all data used for applying |
---|
| 341 | * this rule |
---|
| 342 | */ |
---|
| 343 | private void detectAndReplaceIterations(RuleApplicationData appData) { |
---|
| 344 | Console.traceln(Level.FINE, "detecting iterations"); |
---|
| 345 | appData.getStopWatch().start("detecting iterations"); |
---|
[1552] | 346 | |
---|
[1559] | 347 | List<IUserSession> sessions = appData.getSessions(); |
---|
[1552] | 348 | |
---|
[1559] | 349 | Set<ITask> iteratedTasks = searchIteratedTasks(sessions); |
---|
[1552] | 350 | |
---|
[1559] | 351 | if (iteratedTasks.size() > 0) { |
---|
| 352 | replaceIterationsOf(iteratedTasks, sessions, appData); |
---|
| 353 | } |
---|
[1552] | 354 | |
---|
[1559] | 355 | appData.getStopWatch().stop("detecting iterations"); |
---|
| 356 | Console.traceln(Level.INFO, "replaced " + iteratedTasks.size() |
---|
| 357 | + " iterated tasks"); |
---|
| 358 | } |
---|
[1552] | 359 | |
---|
[1559] | 360 | /** |
---|
| 361 | * <p> |
---|
| 362 | * searches the provided sessions for task iterations. If a task is |
---|
| 363 | * iterated, it is added to the returned set. |
---|
| 364 | * </p> |
---|
| 365 | * |
---|
| 366 | * @param the |
---|
| 367 | * session to search for iterations in |
---|
| 368 | * |
---|
| 369 | * @return a set of tasks being iterated somewhere |
---|
| 370 | */ |
---|
| 371 | private Set<ITask> searchIteratedTasks(List<IUserSession> sessions) { |
---|
| 372 | Set<ITask> iteratedTasks = new HashSet<ITask>(); |
---|
| 373 | for (IUserSession session : sessions) { |
---|
| 374 | for (int i = 0; i < (session.size() - 1); i++) { |
---|
| 375 | // we prepared the task instances to refer to unique tasks, if |
---|
| 376 | // they are treated |
---|
| 377 | // as equal. Therefore, we just compare the identity of the |
---|
| 378 | // tasks of the task |
---|
| 379 | // instances |
---|
| 380 | if (session.get(i).getTask() == session.get(i + 1).getTask()) { |
---|
| 381 | iteratedTasks.add(session.get(i).getTask()); |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | return iteratedTasks; |
---|
| 386 | } |
---|
[1552] | 387 | |
---|
[1559] | 388 | /** |
---|
| 389 | * <p> |
---|
| 390 | * replaces all occurrences of all tasks provided in the set with iterations |
---|
| 391 | * </p> |
---|
| 392 | * |
---|
| 393 | * @param iteratedTasks |
---|
| 394 | * the tasks to be replaced with iterations |
---|
| 395 | * @param sessions |
---|
| 396 | * the sessions in which the tasks are to be replaced |
---|
| 397 | * @param appData |
---|
| 398 | * the rule application data combining all data used for applying |
---|
| 399 | * this rule |
---|
| 400 | */ |
---|
| 401 | private void replaceIterationsOf(Set<ITask> iteratedTasks, |
---|
| 402 | List<IUserSession> sessions, RuleApplicationData appData) { |
---|
| 403 | Map<ITask, IIteration> iterations = new HashMap<ITask, IIteration>(); |
---|
| 404 | Map<IIteration, List<IIterationInstance>> iterationInstances = new HashMap<IIteration, List<IIterationInstance>>(); |
---|
[1552] | 405 | |
---|
[1559] | 406 | for (ITask iteratedTask : iteratedTasks) { |
---|
[1675] | 407 | |
---|
[1559] | 408 | IIteration iteration = taskFactory.createNewIteration(); |
---|
[1698] | 409 | appData.newTaskCreated(iteration); |
---|
[1559] | 410 | iterations.put(iteratedTask, iteration); |
---|
| 411 | iterationInstances.put(iteration, |
---|
| 412 | new LinkedList<IIterationInstance>()); |
---|
| 413 | } |
---|
[1552] | 414 | |
---|
[1559] | 415 | IIterationInstance iterationInstance; |
---|
[1552] | 416 | |
---|
[1559] | 417 | for (IUserSession session : sessions) { |
---|
| 418 | int index = 0; |
---|
| 419 | iterationInstance = null; |
---|
[1552] | 420 | |
---|
[1559] | 421 | while (index < session.size()) { |
---|
| 422 | // we prepared the task instances to refer to unique tasks, if |
---|
| 423 | // they are treated |
---|
| 424 | // as equal. Therefore, we just compare the identity of the |
---|
| 425 | // tasks of the task |
---|
| 426 | // instances |
---|
| 427 | ITask currentTask = session.get(index).getTask(); |
---|
| 428 | IIteration iteration = iterations.get(currentTask); |
---|
| 429 | if (iteration != null) { |
---|
| 430 | if ((iterationInstance == null) |
---|
| 431 | || (iterationInstance.getTask() != iteration)) { |
---|
| 432 | iterationInstance = taskFactory |
---|
| 433 | .createNewTaskInstance(iteration); |
---|
| 434 | iterationInstances.get(iteration) |
---|
[1693] | 435 | .add(iterationInstance);// TODO:: Don't create |
---|
| 436 | // TaskInstances here, |
---|
| 437 | // use a set of tasks |
---|
| 438 | // instead |
---|
[1559] | 439 | taskBuilder.addTaskInstance(session, index, |
---|
| 440 | iterationInstance); |
---|
| 441 | index++; |
---|
| 442 | } |
---|
[1552] | 443 | |
---|
[1559] | 444 | taskBuilder.addChild(iterationInstance, session.get(index)); |
---|
| 445 | taskBuilder.removeTaskInstance(session, index); |
---|
| 446 | } else { |
---|
| 447 | if (iterationInstance != null) { |
---|
| 448 | iterationInstance = null; |
---|
| 449 | } |
---|
| 450 | index++; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | } |
---|
[1693] | 454 | |
---|
| 455 | for (Map.Entry<IIteration, List<IIterationInstance>> entry : iterationInstances |
---|
| 456 | .entrySet()) { |
---|
| 457 | harmonizeIterationInstancesModel(entry.getKey(), entry.getValue()); |
---|
| 458 | } |
---|
[1559] | 459 | } |
---|
[1552] | 460 | |
---|
[1692] | 461 | /** |
---|
[1693] | 462 | * <p> |
---|
| 463 | * TODO clarify why this is done |
---|
| 464 | * </p> |
---|
| 465 | */ |
---|
| 466 | private void harmonizeIterationInstancesModel(IIteration iteration, |
---|
| 467 | List<IIterationInstance> iterationInstances) { |
---|
| 468 | List<ITask> iteratedTaskVariants = new LinkedList<ITask>(); |
---|
| 469 | TaskInstanceComparator comparator = preparationTaskHandlingStrategy |
---|
| 470 | .getTaskComparator(); |
---|
[1692] | 471 | |
---|
[1693] | 472 | // merge the lexically different variants of iterated task to a unique |
---|
| 473 | // list |
---|
| 474 | for (IIterationInstance iterationInstance : iterationInstances) { |
---|
| 475 | for (ITaskInstance executionVariant : iterationInstance) { |
---|
| 476 | ITask candidate = executionVariant.getTask(); |
---|
[1692] | 477 | |
---|
[1693] | 478 | boolean found = false; |
---|
| 479 | for (ITask taskVariant : iteratedTaskVariants) { |
---|
| 480 | if (comparator.areLexicallyEqual(taskVariant, candidate)) { |
---|
| 481 | taskBuilder.setTask(executionVariant, taskVariant); |
---|
| 482 | found = true; |
---|
| 483 | break; |
---|
| 484 | } |
---|
| 485 | } |
---|
[1645] | 486 | |
---|
[1693] | 487 | if (!found) { |
---|
| 488 | iteratedTaskVariants.add(candidate); |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | // if there are more than one lexically different variant of iterated |
---|
| 494 | // tasks, adapt the |
---|
| 495 | // iteration model to be a selection of different variants. In this case |
---|
| 496 | // also adapt |
---|
| 497 | // the generated iteration instances to correctly contain selection |
---|
| 498 | // instances. If there |
---|
| 499 | // is only one variant of an iterated task, simply set this as the |
---|
| 500 | // marked task of the |
---|
| 501 | // iteration. In this case, the instances can be preserved as is |
---|
| 502 | if (iteratedTaskVariants.size() > 1) { |
---|
| 503 | ISelection selection = taskFactory.createNewSelection(); |
---|
| 504 | |
---|
| 505 | for (ITask variant : iteratedTaskVariants) { |
---|
| 506 | taskBuilder.addChild(selection, variant); |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | taskBuilder.setMarkedTask(iteration, selection); |
---|
| 510 | |
---|
| 511 | for (IIterationInstance instance : iterationInstances) { |
---|
| 512 | for (int i = 0; i < instance.size(); i++) { |
---|
| 513 | ISelectionInstance selectionInstance = taskFactory |
---|
| 514 | .createNewTaskInstance(selection); |
---|
| 515 | taskBuilder.setChild(selectionInstance, instance.get(i)); |
---|
| 516 | taskBuilder.setTaskInstance(instance, i, selectionInstance); |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | } else { |
---|
| 520 | taskBuilder.setMarkedTask(iteration, iteratedTaskVariants.get(0)); |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | /** |
---|
| 525 | * @param appData |
---|
| 526 | * @param m |
---|
| 527 | * @return |
---|
| 528 | */ |
---|
[1696] | 529 | public ISequence matchAsSequence(RuleApplicationData appData, Match m) { |
---|
[1657] | 530 | ISequence sequence = taskFactory.createNewSequence(); |
---|
[1698] | 531 | appData.newTaskCreated(sequence); |
---|
[1657] | 532 | |
---|
| 533 | int[] first = m.getFirstSequence().getSequence(); |
---|
| 534 | int[] second = m.getSecondSequence().getSequence(); |
---|
| 535 | |
---|
| 536 | // Both sequences of a match are equally long |
---|
| 537 | for (int i = 0; i < m.getFirstSequence().size(); i++) { |
---|
| 538 | |
---|
| 539 | // Two gaps aligned to each other: Have not seen it happening so |
---|
| 540 | // far, just to handle it |
---|
| 541 | if (first[i] == -1 && second[i] == -1) { |
---|
[1693] | 542 | // Do nothing here. |
---|
[1657] | 543 | } |
---|
| 544 | // Both events are equal, we can simply add the task referring to |
---|
| 545 | // the number |
---|
| 546 | else if (first[i] == second[i]) { |
---|
| 547 | taskBuilder.addChild(sequence, |
---|
| 548 | appData.getNumber2Task().get(first[i])); |
---|
| 549 | } |
---|
| 550 | // We have a gap in the first sequence, we need to add the task of |
---|
| 551 | // the second sequence as optional |
---|
| 552 | else if (first[i] == -1 && second[i] != -1) { |
---|
| 553 | IOptional optional = taskFactory.createNewOptional(); |
---|
[1698] | 554 | appData.newTaskCreated(optional); |
---|
[1657] | 555 | taskBuilder.setMarkedTask(optional, appData.getNumber2Task() |
---|
| 556 | .get(second[i])); |
---|
| 557 | taskBuilder.addChild(sequence, optional); |
---|
| 558 | } |
---|
| 559 | // We have a gap in the second sequence, we need to add the task of |
---|
| 560 | // the first sequence as optional |
---|
| 561 | else if (first[i] != -1 && second[i] == -1) { |
---|
| 562 | IOptional optional = taskFactory.createNewOptional(); |
---|
[1698] | 563 | appData.newTaskCreated(optional); |
---|
[1657] | 564 | taskBuilder.setMarkedTask(optional, appData.getNumber2Task() |
---|
| 565 | .get(first[i])); |
---|
| 566 | taskBuilder.addChild(sequence, optional); |
---|
| 567 | } |
---|
[1693] | 568 | // Both tasks are not equal, we need to insert a selection here. |
---|
| 569 | // Check if the next position is not a selection |
---|
| 570 | else if (i < first.length - 1) { |
---|
| 571 | |
---|
| 572 | if ((first[i] != second[i]) |
---|
| 573 | && ((first[i + 1] == second[i + 1] |
---|
| 574 | || first[i + 1] == -1 || second[i + 1] == -1))) { |
---|
| 575 | |
---|
| 576 | ISelection selection = taskFactory.createNewSelection(); |
---|
[1698] | 577 | appData.newTaskCreated(selection); |
---|
[1693] | 578 | taskBuilder.addChild(selection, appData.getNumber2Task() |
---|
| 579 | .get(first[i])); |
---|
| 580 | taskBuilder.addChild(selection, appData.getNumber2Task() |
---|
| 581 | .get(second[i])); |
---|
| 582 | taskBuilder.addChild(sequence, selection); |
---|
| 583 | } else { |
---|
| 584 | boolean selectionfound = true; |
---|
| 585 | ISelection selection = taskFactory.createNewSelection(); |
---|
[1698] | 586 | appData.newTaskCreated(selection); |
---|
[1693] | 587 | |
---|
| 588 | ISequence subsequence1 = taskFactory.createNewSequence(); |
---|
[1698] | 589 | appData.newTaskCreated(subsequence1); |
---|
[1693] | 590 | |
---|
| 591 | ISequence subsequence2 = taskFactory.createNewSequence(); |
---|
[1698] | 592 | appData.newTaskCreated(subsequence2); |
---|
[1693] | 593 | |
---|
| 594 | taskBuilder.addChild(selection, subsequence1); |
---|
| 595 | taskBuilder.addChild(selection, subsequence2); |
---|
| 596 | taskBuilder.addChild(sequence,selection); |
---|
| 597 | while (i < first.length - 1 && selectionfound) { |
---|
| 598 | selectionfound = false; |
---|
| 599 | taskBuilder.addChild(subsequence1, appData |
---|
| 600 | .getNumber2Task().get(first[i])); |
---|
| 601 | taskBuilder.addChild(subsequence2, appData |
---|
| 602 | .getNumber2Task().get(second[i])); |
---|
| 603 | if (first[i + 1] != second[i + 1] && first[i + 1] != -1 |
---|
| 604 | && second[i + 1] != -1) { |
---|
| 605 | selectionfound = true; |
---|
| 606 | } |
---|
[1700] | 607 | else{ |
---|
| 608 | continue; |
---|
| 609 | } |
---|
[1693] | 610 | i++; |
---|
| 611 | } |
---|
| 612 | if(i==first.length-1 && selectionfound) { |
---|
| 613 | taskBuilder.addChild(subsequence1, appData |
---|
| 614 | .getNumber2Task().get(first[i])); |
---|
| 615 | taskBuilder.addChild(subsequence2, appData |
---|
| 616 | .getNumber2Task().get(second[i])); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | } |
---|
[1657] | 620 | else { |
---|
[1693] | 621 | if ((first[i] != second[i])) { |
---|
| 622 | |
---|
| 623 | ISelection selection = taskFactory.createNewSelection(); |
---|
[1698] | 624 | appData.newTaskCreated(selection); |
---|
[1693] | 625 | taskBuilder.addChild(selection, appData.getNumber2Task() |
---|
| 626 | .get(first[i])); |
---|
| 627 | taskBuilder.addChild(selection, appData.getNumber2Task() |
---|
| 628 | .get(second[i])); |
---|
| 629 | taskBuilder.addChild(sequence, selection); |
---|
| 630 | } |
---|
[1657] | 631 | } |
---|
[1693] | 632 | |
---|
[1630] | 633 | } |
---|
[1657] | 634 | return sequence; |
---|
| 635 | } |
---|
| 636 | |
---|
[1559] | 637 | /** |
---|
| 638 | * |
---|
| 639 | * @param appData |
---|
| 640 | * the rule application data combining all data used for applying |
---|
| 641 | * this rule |
---|
| 642 | */ |
---|
| 643 | private void detectAndReplaceTasks(RuleApplicationData appData) { |
---|
| 644 | Console.traceln(Level.FINE, "detecting and replacing tasks"); |
---|
| 645 | appData.getStopWatch().start("detecting tasks"); |
---|
| 646 | |
---|
[1675] | 647 | // Create NumberSequences |
---|
| 648 | appData.setNumberSequences(this.createNumberSequences(appData)); |
---|
[1698] | 649 | |
---|
[1675] | 650 | // Generate pairwise alignments |
---|
[1711] | 651 | int size = appData.getNumberSequences().size(); |
---|
[1718] | 652 | Console.traceln(Level.INFO, "generating pairwise alignments from " + size + " sessions"); |
---|
[1711] | 653 | int count = 0; |
---|
| 654 | |
---|
[1718] | 655 | //Checking if i have an already calculated file result of this action in the working directory |
---|
| 656 | File aligned = new File("aligned" + iteration + ".dat"); |
---|
| 657 | if(!(aligned.exists() && !aligned.isDirectory())) { |
---|
| 658 | appData.matchseqs = new LinkedList<Match>(); |
---|
| 659 | System.out.println(appData.matchseqs); |
---|
| 660 | for (int i = 0; i < appData.getNumberSequences().size(); i++) { |
---|
| 661 | NumberSequence ns1 = appData.getNumberSequences().get(i); |
---|
| 662 | count++; |
---|
| 663 | |
---|
| 664 | //Print out the progress |
---|
| 665 | if(size>100) { |
---|
| 666 | if((count%(size/100)==0)) { |
---|
| 667 | Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); |
---|
| 668 | } |
---|
[1668] | 669 | } |
---|
[1718] | 670 | else { |
---|
| 671 | Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); |
---|
| 672 | } |
---|
| 673 | for (int j = 0; j < appData.getNumberSequences().size(); j++) { |
---|
| 674 | NumberSequence ns2 = appData.getNumberSequences().get(j); |
---|
| 675 | if (i != j) { |
---|
| 676 | //Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); |
---|
| 677 | AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); |
---|
| 678 | aa.align(ns1, ns2, appData.getSubmat(),9); |
---|
| 679 | appData.getMatchseqs().addAll(aa.getMatches()); |
---|
| 680 | } |
---|
| 681 | } |
---|
[1675] | 682 | } |
---|
[1718] | 683 | GlobalDataContainer.getInstance().addData("aligned" + iteration, appData); |
---|
| 684 | saveAppData("aligned" + iteration); |
---|
[1675] | 685 | } |
---|
[1718] | 686 | else { |
---|
| 687 | Console.traceln(Level.INFO,"loading matches from file"); |
---|
| 688 | appData = loadAppData("aligned"+iteration); |
---|
| 689 | } |
---|
[1693] | 690 | |
---|
[1718] | 691 | |
---|
[1675] | 692 | Console.traceln(Level.INFO, "searching for patterns occuring most"); |
---|
[1559] | 693 | |
---|
[1675] | 694 | // search each match in every other sequence |
---|
[1718] | 695 | for (Iterator<Match> it = appData.getMatchseqs().iterator(); it.hasNext();) { |
---|
[1675] | 696 | Match pattern = it.next(); |
---|
[1718] | 697 | |
---|
[1675] | 698 | // Skip sequences with more 0 events (scrolls) than other events. |
---|
| 699 | // Both of the pattern sequences are equally long, so the zero |
---|
| 700 | // counts just need to be smaller than the length of one sequence |
---|
| 701 | if (pattern.getFirstSequence().eventCount(0) |
---|
| 702 | + pattern.getSecondSequence().eventCount(0) + 1 > pattern |
---|
| 703 | .getFirstSequence().size()) |
---|
| 704 | continue; |
---|
[1559] | 705 | |
---|
[1675] | 706 | for (int j = 0; j < appData.getNumberSequences().size(); j++) { |
---|
| 707 | LinkedList<Integer> startpositions = appData |
---|
| 708 | .getNumberSequences().get(j).containsPattern(pattern); |
---|
| 709 | if (startpositions.size() > 0) { |
---|
| 710 | for (Iterator<Integer> jt = startpositions.iterator(); jt |
---|
| 711 | .hasNext();) { |
---|
| 712 | int start = jt.next(); |
---|
| 713 | pattern.addOccurence(new MatchOccurence(start, start |
---|
| 714 | + pattern.size(), j)); |
---|
| 715 | } |
---|
[1559] | 716 | |
---|
[1668] | 717 | } |
---|
[1675] | 718 | } |
---|
| 719 | } |
---|
[1668] | 720 | |
---|
[1675] | 721 | Console.traceln(Level.INFO, "sorting results"); |
---|
| 722 | // Sort results to get the most occurring results |
---|
| 723 | Comparator<Match> comparator = new Comparator<Match>() { |
---|
| 724 | public int compare(Match m1, Match m2) { |
---|
| 725 | return m2.occurenceCount() - m1.occurenceCount(); |
---|
[1668] | 726 | |
---|
[1675] | 727 | } |
---|
| 728 | }; |
---|
[1718] | 729 | Collections.sort(appData.getMatchseqs(), comparator); |
---|
[1675] | 730 | appData.getStopWatch().stop("detecting tasks"); |
---|
[1668] | 731 | |
---|
[1675] | 732 | appData.getStopWatch().start("replacing tasks"); |
---|
| 733 | HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); |
---|
| 734 | // Replace matches in the sessions |
---|
[1718] | 735 | for (int i = 0; i < appData.getMatchseqs().size(); i++) { |
---|
| 736 | |
---|
[1675] | 737 | // Every pattern consists of 2 sequences, therefore the minimum |
---|
| 738 | // occurrences here is 2. |
---|
| 739 | // We just need the sequences also occurring in other sequences as |
---|
| 740 | // well |
---|
[1718] | 741 | if (appData.getMatchseqs().get(i).occurenceCount() > 2) { |
---|
[1679] | 742 | appData.detectedAndReplacedTasks = true; |
---|
[1718] | 743 | ISequence task = matchAsSequence(appData, appData.getMatchseqs().get(i)); |
---|
| 744 | invalidOccurence: for (Iterator<MatchOccurence> it = appData.getMatchseqs() |
---|
[1675] | 745 | .get(i).getOccurences().iterator(); it.hasNext();) { |
---|
| 746 | MatchOccurence oc = it.next(); |
---|
[1693] | 747 | |
---|
[1702] | 748 | /* |
---|
[1718] | 749 | if (iteration > 0) { |
---|
[1680] | 750 | |
---|
[1693] | 751 | System.out.println("Trying to replace sequence: "); |
---|
[1718] | 752 | appData.getMatchseqs().get(i).getFirstSequence().printSequence(); |
---|
| 753 | appData.getMatchseqs().get(i).getSecondSequence().printSequence(); |
---|
[1693] | 754 | System.out.println(" in session number: " |
---|
| 755 | + (oc.getSequenceId() + 1) + " at position " |
---|
| 756 | + (oc.getStartindex()) + "-" + oc.getEndindex()); |
---|
| 757 | System.out.println(); |
---|
[1675] | 758 | |
---|
[1693] | 759 | System.out.println("Printing session: "); |
---|
| 760 | for (int j = 0; j < appData.getSessions() |
---|
| 761 | .get(oc.getSequenceId()).size(); j++) { |
---|
| 762 | System.out.println(j |
---|
| 763 | + ": " |
---|
| 764 | + appData.getSessions().get(oc.getSequenceId()) |
---|
| 765 | .get(j)); |
---|
[1680] | 766 | } |
---|
[1702] | 767 | }*/ |
---|
[1700] | 768 | |
---|
[1675] | 769 | // Check if nothing has been replaced in the sequence we |
---|
| 770 | // want to replace |
---|
| 771 | if (replacedOccurences.get(oc.getSequenceId()) == null) { |
---|
| 772 | replacedOccurences.put(oc.getSequenceId(), |
---|
| 773 | new LinkedList<MatchOccurence>()); |
---|
| 774 | } else { |
---|
| 775 | // check if we have any replaced occurence with indexes |
---|
| 776 | // smaller than ours. If so, we need to adjust our start |
---|
| 777 | // and endpoints |
---|
| 778 | // of the replacement. |
---|
| 779 | // Also do a check if we have replaced this specific |
---|
| 780 | // MatchOccurence in this sequence already. Jump to the |
---|
| 781 | // next occurence if this is the case. |
---|
| 782 | // This is no more neccessary once the matches are |
---|
| 783 | // harmonized. |
---|
| 784 | for (Iterator<MatchOccurence> jt = replacedOccurences |
---|
| 785 | .get(oc.getSequenceId()).iterator(); jt |
---|
| 786 | .hasNext();) { |
---|
| 787 | MatchOccurence tmpOC = jt.next(); |
---|
| 788 | |
---|
| 789 | if (oc.getStartindex() >= tmpOC.getStartindex() |
---|
| 790 | && oc.getStartindex() <= tmpOC |
---|
| 791 | .getEndindex()) { |
---|
| 792 | continue invalidOccurence; |
---|
| 793 | } |
---|
| 794 | if (oc.getEndindex() >= tmpOC.getStartindex()) { |
---|
| 795 | continue invalidOccurence; |
---|
| 796 | |
---|
| 797 | } else if (oc.getStartindex() > tmpOC.getEndindex()) { |
---|
| 798 | int diff = tmpOC.getEndindex() |
---|
| 799 | - tmpOC.getStartindex(); |
---|
| 800 | // Just to be sure. |
---|
| 801 | if (diff > 0) { |
---|
| 802 | oc.setStartindex(oc.getStartindex() - diff |
---|
| 803 | + 1); |
---|
| 804 | oc.setEndindex(oc.getEndindex() - diff + 1); |
---|
| 805 | } else { |
---|
| 806 | Console.traceln(Level.WARNING, |
---|
| 807 | "End index of a Match before start. This should never happen"); |
---|
[1668] | 808 | } |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | } |
---|
[1675] | 812 | ISequenceInstance sequenceInstances = RuleUtils |
---|
| 813 | .createNewSubSequenceInRange(appData.getSessions() |
---|
| 814 | .get(oc.getSequenceId()), oc |
---|
| 815 | .getStartindex(), oc.getEndindex(), task, |
---|
| 816 | taskFactory, taskBuilder); |
---|
| 817 | // Adjust the length of the match regarding to the length of |
---|
| 818 | // instance. (OptionalInstances may be shorter) |
---|
| 819 | oc.setEndindex(oc.getStartindex() |
---|
| 820 | + sequenceInstances.size() |
---|
| 821 | - RuleUtils.missedOptionals); |
---|
| 822 | replacedOccurences.get(oc.getSequenceId()).add(oc); |
---|
[1668] | 823 | } |
---|
[1675] | 824 | } |
---|
| 825 | } |
---|
[1718] | 826 | appData.setMatchseqs(null); |
---|
[1668] | 827 | appData.getStopWatch().stop("replacing tasks"); |
---|
[1559] | 828 | } |
---|
| 829 | |
---|
| 830 | /** |
---|
[1552] | 831 | * |
---|
| 832 | */ |
---|
[1707] | 833 | private static class RuleApplicationData implements Serializable { |
---|
[1559] | 834 | |
---|
[1707] | 835 | /** |
---|
| 836 | * |
---|
| 837 | */ |
---|
| 838 | private static final long serialVersionUID = -7559657686755522960L; |
---|
| 839 | |
---|
[1657] | 840 | private HashMap<Integer, ITask> number2task; |
---|
| 841 | |
---|
[1698] | 842 | // TODO: We Actually just need number2task here, this structure can be removed in the future. |
---|
[1690] | 843 | private HashSet<ITask> uniqueTasks; |
---|
[1698] | 844 | |
---|
| 845 | ObjectDistanceSubstitionMatrix submat; |
---|
[1718] | 846 | |
---|
| 847 | LinkedList<Match> matchseqs; |
---|
| 848 | |
---|
[1630] | 849 | private ArrayList<NumberSequence> numberseqs; |
---|
[1657] | 850 | |
---|
[1698] | 851 | private LinkedList<ITask> newTasks; |
---|
| 852 | |
---|
[1559] | 853 | /** |
---|
[1552] | 854 | * |
---|
| 855 | */ |
---|
[1559] | 856 | private List<IUserSession> sessions; |
---|
| 857 | |
---|
| 858 | /** |
---|
[1552] | 859 | * |
---|
| 860 | */ |
---|
[1559] | 861 | private boolean detectedAndReplacedTasks; |
---|
| 862 | |
---|
| 863 | /** |
---|
[1552] | 864 | * |
---|
| 865 | */ |
---|
[1630] | 866 | private RuleApplicationResult result; |
---|
[1559] | 867 | |
---|
| 868 | /** |
---|
[1552] | 869 | * |
---|
| 870 | */ |
---|
[1630] | 871 | private StopWatch stopWatch; |
---|
[1559] | 872 | |
---|
| 873 | /** |
---|
[1552] | 874 | * |
---|
| 875 | */ |
---|
[1559] | 876 | private RuleApplicationData(List<IUserSession> sessions) { |
---|
| 877 | this.sessions = sessions; |
---|
[1630] | 878 | numberseqs = new ArrayList<NumberSequence>(); |
---|
[1690] | 879 | uniqueTasks = new HashSet<ITask>(); |
---|
[1657] | 880 | number2task = new HashMap<Integer, ITask>(); |
---|
| 881 | stopWatch = new StopWatch(); |
---|
| 882 | result = new RuleApplicationResult(); |
---|
[1702] | 883 | submat= new ObjectDistanceSubstitionMatrix(6,-3,false); |
---|
[1698] | 884 | newTasks = new LinkedList<ITask>(); |
---|
[1559] | 885 | } |
---|
[1552] | 886 | |
---|
[1718] | 887 | public LinkedList<Match> getMatchseqs() { |
---|
| 888 | return matchseqs; |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | public void setMatchseqs(LinkedList<Match> matchseqs) { |
---|
| 892 | this.matchseqs = matchseqs; |
---|
| 893 | } |
---|
| 894 | |
---|
[1698] | 895 | private ObjectDistanceSubstitionMatrix getSubmat() { |
---|
| 896 | return submat; |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | private void resetNewlyCreatedTasks() { |
---|
| 900 | uniqueTasks.addAll(newTasks); |
---|
| 901 | newTasks.clear(); |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | private void newTaskCreated(ITask task) { |
---|
| 905 | number2task.put(task.getId(), task); |
---|
| 906 | newTasks.add(task); |
---|
| 907 | } |
---|
| 908 | |
---|
[1559] | 909 | /** |
---|
[1696] | 910 | * @return the UserSessions as List. |
---|
[1559] | 911 | */ |
---|
| 912 | private List<IUserSession> getSessions() { |
---|
| 913 | return sessions; |
---|
| 914 | } |
---|
[1552] | 915 | |
---|
[1690] | 916 | private HashSet<ITask> getUniqueTasks() { |
---|
[1668] | 917 | return uniqueTasks; |
---|
| 918 | } |
---|
[1675] | 919 | |
---|
| 920 | private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { |
---|
| 921 | this.numberseqs = numberseqs; |
---|
[1668] | 922 | } |
---|
[1675] | 923 | |
---|
[1630] | 924 | private ArrayList<NumberSequence> getNumberSequences() { |
---|
| 925 | return numberseqs; |
---|
[1559] | 926 | } |
---|
[1552] | 927 | |
---|
[1698] | 928 | private void updateSubstitutionMatrix() { |
---|
| 929 | submat.update(getNewTasks()); |
---|
| 930 | resetNewlyCreatedTasks(); |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | |
---|
[1718] | 934 | |
---|
[1559] | 935 | /** |
---|
[1552] | 936 | * |
---|
| 937 | */ |
---|
[1559] | 938 | private boolean detectedAndReplacedTasks() { |
---|
| 939 | return detectedAndReplacedTasks; |
---|
| 940 | } |
---|
[1552] | 941 | |
---|
[1559] | 942 | /** |
---|
| 943 | * @return the result |
---|
| 944 | */ |
---|
| 945 | private RuleApplicationResult getResult() { |
---|
| 946 | return result; |
---|
| 947 | } |
---|
[1552] | 948 | |
---|
[1698] | 949 | public LinkedList<ITask> getNewTasks() { |
---|
| 950 | return newTasks; |
---|
| 951 | } |
---|
| 952 | |
---|
[1559] | 953 | /** |
---|
| 954 | * @return the stopWatch |
---|
| 955 | */ |
---|
| 956 | private StopWatch getStopWatch() { |
---|
| 957 | return stopWatch; |
---|
| 958 | } |
---|
[1552] | 959 | |
---|
[1657] | 960 | private HashMap<Integer, ITask> getNumber2Task() { |
---|
[1630] | 961 | return number2task; |
---|
[1559] | 962 | } |
---|
[1552] | 963 | |
---|
[1630] | 964 | } |
---|
[1552] | 965 | |
---|
| 966 | } |
---|