source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java @ 1690

Last change on this file since 1690 was 1690, checked in by rkrimmel, 10 years ago

Fixed harmonization issues but tasks are created wrong now..

File size: 23.0 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
16
17import java.util.ArrayList;
18import java.util.Collections;
19import java.util.Comparator;
20import java.util.HashMap;
21import java.util.HashSet;
22import java.util.Iterator;
23import java.util.LinkedList;
24import java.util.List;
25import java.util.Map;
26import java.util.Set;
27import java.util.logging.Level;
28
29import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match;
30import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence;
31import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence;
32import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator;
33import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage;
34import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix;
35import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
36import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
37import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
38import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
39import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
40import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
41import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
42import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
43import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
44import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
45import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
46import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
47import de.ugoe.cs.autoquest.usageprofiles.SymbolMap;
48import de.ugoe.cs.util.StopWatch;
49import de.ugoe.cs.util.console.Console;
50
51/**
52 * <p>
53 * This class implements the major rule for creating task trees based on a set
54 * of recorded user sessions. For this, it first harmonizes all tasks. This
55 * eases later comparison. Then it searches the sessions for iterations and
56 * replaces them accordingly. Then it searches for sub sequences being the
57 * longest and occurring most often. For each found sub sequence, it replaces
58 * the occurrences by creating appropriate {@link ISequence}s. Afterwards, again
59 * searches for iterations and then again for sub sequences until no more
60 * replacements are done.
61 * </p>
62 * <p>
63 *
64 *
65 * @author Patrick Harms
66 */
67class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule {
68
69       
70        private int iteration = 0;
71        /**
72         * <p>
73         * the task factory to be used for creating substructures for the temporal
74         * relationships identified during rul application
75         * </p>
76         */
77        private ITaskFactory taskFactory;
78        /**
79         * <p>
80         * the task builder to be used for creating substructures for the temporal
81         * relationships identified during rule application
82         * </p>
83         */
84        private ITaskBuilder taskBuilder;
85
86        /**
87         * <p>
88         * the task handling strategy to be used for comparing tasks for
89         * preparation, i.e., before the tasks are harmonized
90         * </p>
91         */
92        private TaskHandlingStrategy preparationTaskHandlingStrategy;
93
94
95        /**
96         * <p>
97         * instantiates the rule and initializes it with a task equality to be
98         * considered when comparing tasks as well as a task factory and builder to
99         * be used for creating task structures.
100         * </p>
101         *
102         * @param minimalTaskEquality
103         *            the task equality to be considered when comparing tasks
104         * @param taskFactory
105         *            the task factory to be used for creating substructures
106         * @param taskBuilder
107         *            the task builder to be used for creating substructures
108         */
109
110        SequenceForTaskDetectionRuleAlignment(TaskEquality minimalTaskEquality,
111                        ITaskFactory taskFactory, ITaskBuilder taskBuilder) {
112                this.taskFactory = taskFactory;
113                this.taskBuilder = taskBuilder;
114
115                this.preparationTaskHandlingStrategy = new TaskHandlingStrategy(
116                                minimalTaskEquality);
117
118        }
119
120        /*
121         * (non-Javadoc)
122         *
123         * @see java.lang.Object#toString()
124         */
125        @Override
126        public String toString() {
127                return "SequenceForTaskDetectionRuleAlignment";
128        }
129
130        /*
131         * (non-Javadoc)
132         *
133         * @see
134         * de.ugoe.cs.autoquest.tasktrees.temporalrelation.ISessionScopeRule#apply
135         * (java.util.List)
136         */
137        @Override
138        public RuleApplicationResult apply(List<IUserSession> sessions) {
139                RuleApplicationData appData = new RuleApplicationData(sessions);
140                harmonizeEventTaskInstancesModel(appData);
141               
142                do {
143                        iteration++;
144                        appData.detectedAndReplacedTasks = false;
145                        appData.getStopWatch().start("whole loop");
146                        detectAndReplaceIterations(appData);
147                        appData.getStopWatch().start("task replacement");
148                        detectAndReplaceTasks(appData); //
149                        appData.getStopWatch().stop("task replacement");
150                        appData.getStopWatch().stop("whole loop");
151                        appData.getStopWatch().dumpStatistics(System.out);
152                        appData.getStopWatch().reset();
153
154                } while (appData.detectedAndReplacedTasks());
155
156                Console.println("created "
157                                + appData.getResult().getNewlyCreatedTasks().size()
158                                + " new tasks and "
159                                + appData.getResult().getNewlyCreatedTaskInstances().size()
160                                + " appropriate instances\n");
161
162                if ((appData.getResult().getNewlyCreatedTasks().size() > 0)
163                                || (appData.getResult().getNewlyCreatedTaskInstances().size() > 0)) {
164                        appData.getResult().setRuleApplicationStatus(
165                                        RuleApplicationStatus.FINISHED);
166                }
167
168                return appData.getResult();
169        }
170
171        private ArrayList<NumberSequence> createNumberSequences(
172                        RuleApplicationData appData) {
173                ArrayList<NumberSequence> result = new ArrayList<NumberSequence>();
174                for (int i = 0; i < appData.getSessions().size(); i++) {
175                        IUserSession session = appData.getSessions().get(i);
176                        NumberSequence templist = new NumberSequence(session.size());
177                        for (int j = 0; j < session.size(); j++) {
178                                ITaskInstance taskInstance = session.get(j);
179                                templist.getSequence()[j] = taskInstance.getTask().getId();
180                        }
181                        //System.out.println();
182                        // Each NumberSequence is identified by its id, beginning to count
183                        // at zero
184                        templist.setId(i);
185                        result.add(templist);
186                }
187                return result;
188        }
189
190        /**
191         * <p>
192         * harmonizes the event task instances by unifying tasks. This is done, as
193         * initially the event tasks being equal with respect to the considered task
194         * equality are distinct objects. The comparison of these distinct objects
195         * is more time consuming than comparing the object references.
196         * </p>
197         *
198         * @param appData
199         *            the rule application data combining all data used for applying
200         *            this rule
201         * @return Returns the unique tasks symbol map
202         */
203        private void harmonizeEventTaskInstancesModel(RuleApplicationData appData) {
204                Console.traceln(Level.INFO,
205                                "harmonizing task model of event task instances");
206                appData.getStopWatch().start("harmonizing event tasks");
207                SymbolMap<ITaskInstance, ITask> uniqueTasks = preparationTaskHandlingStrategy.createSymbolMap();
208
209                TaskInstanceComparator comparator = preparationTaskHandlingStrategy
210                                .getTaskComparator();
211
212                int unifiedTasks = 0;
213                ITask task;
214                List<IUserSession> sessions = appData.getSessions();
215                for (int j = 0; j < sessions.size(); j++) {
216                        IUserSession session = sessions.get(j);
217
218                        for (int i = 0; i < session.size(); i++) {
219                                ITaskInstance taskInstance = session.get(i);
220                                task = uniqueTasks.getValue(taskInstance);
221
222                                if (task == null) {
223                                        uniqueTasks.addSymbol(taskInstance,
224                                                        taskInstance.getTask());
225                                                        appData.getUniqueTasks().add(taskInstance.getTask());
226                                                        appData.getNumber2Task().put(taskInstance.getTask().getId(),taskInstance.getTask());
227                                } else {
228                                        taskBuilder.setTask(taskInstance, task);
229                                        unifiedTasks++;
230                                }
231                        }
232                        comparator.clearBuffers();
233                }
234
235                appData.getStopWatch().stop("harmonizing event tasks");
236                Console.traceln(Level.INFO, "harmonized " + unifiedTasks
237                                + " task occurrences (still " + appData.getUniqueTasks().size()
238                                + " different tasks)");
239
240                appData.getStopWatch().dumpStatistics(System.out);
241                appData.getStopWatch().reset();
242        }
243
244        /**
245         * <p>
246         * searches for direct iterations of single tasks in all sequences and
247         * replaces them with {@link IIteration}s, respectively appropriate
248         * instances. Also all single occurrences of a task that is iterated
249         * somewhen are replaced with iterations to have again an efficient way for
250         * task comparisons.
251         * </p>
252         *
253         * @param appData
254         *            the rule application data combining all data used for applying
255         *            this rule
256         */
257        private void detectAndReplaceIterations(RuleApplicationData appData) {
258                Console.traceln(Level.FINE, "detecting iterations");
259                appData.getStopWatch().start("detecting iterations");
260
261                List<IUserSession> sessions = appData.getSessions();
262
263                Set<ITask> iteratedTasks = searchIteratedTasks(sessions);
264
265                if (iteratedTasks.size() > 0) {
266                        replaceIterationsOf(iteratedTasks, sessions, appData);
267                }
268
269                appData.getStopWatch().stop("detecting iterations");
270                Console.traceln(Level.INFO, "replaced " + iteratedTasks.size()
271                                + " iterated tasks");
272        }
273
274        /**
275         * <p>
276         * searches the provided sessions for task iterations. If a task is
277         * iterated, it is added to the returned set.
278         * </p>
279         *
280         * @param the
281         *            session to search for iterations in
282         *
283         * @return a set of tasks being iterated somewhere
284         */
285        private Set<ITask> searchIteratedTasks(List<IUserSession> sessions) {
286                Set<ITask> iteratedTasks = new HashSet<ITask>();
287                for (IUserSession session : sessions) {
288                        for (int i = 0; i < (session.size() - 1); i++) {
289                                // we prepared the task instances to refer to unique tasks, if
290                                // they are treated
291                                // as equal. Therefore, we just compare the identity of the
292                                // tasks of the task
293                                // instances
294                                if (session.get(i).getTask() == session.get(i + 1).getTask()) {
295                                        iteratedTasks.add(session.get(i).getTask());
296                                }
297                        }
298                }
299                return iteratedTasks;
300        }
301
302        /**
303         * <p>
304         * replaces all occurrences of all tasks provided in the set with iterations
305         * </p>
306         *
307         * @param iteratedTasks
308         *            the tasks to be replaced with iterations
309         * @param sessions
310         *            the sessions in which the tasks are to be replaced
311         * @param appData
312         *            the rule application data combining all data used for applying
313         *            this rule
314         */
315        private void replaceIterationsOf(Set<ITask> iteratedTasks,
316                        List<IUserSession> sessions, RuleApplicationData appData) {
317                Map<ITask, IIteration> iterations = new HashMap<ITask, IIteration>();
318                Map<IIteration, List<IIterationInstance>> iterationInstances = new HashMap<IIteration, List<IIterationInstance>>();
319
320                for (ITask iteratedTask : iteratedTasks) {
321
322                        IIteration iteration = taskFactory.createNewIteration();
323                        appData.getUniqueTasks().add( iteration);
324                        appData.getNumber2Task().put(iteration.getId(), iteration);
325                        iterations.put(iteratedTask, iteration);
326                        iterationInstances.put(iteration,
327                                        new LinkedList<IIterationInstance>());
328                }
329
330                IIterationInstance iterationInstance;
331
332                for (IUserSession session : sessions) {
333                        int index = 0;
334                        iterationInstance = null;
335
336                        while (index < session.size()) {
337                                // we prepared the task instances to refer to unique tasks, if
338                                // they are treated
339                                // as equal. Therefore, we just compare the identity of the
340                                // tasks of the task
341                                // instances
342                                ITask currentTask = session.get(index).getTask();
343                                IIteration iteration = iterations.get(currentTask);
344                                if (iteration != null) {
345                                        if ((iterationInstance == null)
346                                                        || (iterationInstance.getTask() != iteration)) {
347                                                iterationInstance = taskFactory
348                                                                .createNewTaskInstance(iteration);
349                                                iterationInstances.get(iteration)
350                                                                .add(iterationInstance);//TODO:: Don't create TaskInstances here, use a set of tasks instead
351                                                taskBuilder.addTaskInstance(session, index,
352                                                                iterationInstance);
353                                                index++;
354                                        }
355
356                                        taskBuilder.addChild(iterationInstance, session.get(index));
357                                        taskBuilder.removeTaskInstance(session, index);
358                                } else {
359                                        if (iterationInstance != null) {
360                                                iterationInstance = null;
361                                        }
362                                        index++;
363                                }
364                        }
365                }
366        }
367
368        ISequence matchAsSequence(RuleApplicationData appData, Match m) {
369
370                ISequence sequence = taskFactory.createNewSequence();
371                appData.uniqueTasks.add(sequence);
372                appData.number2task.put(sequence.getId(), sequence);
373               
374
375                int[] first = m.getFirstSequence().getSequence();
376                int[] second = m.getSecondSequence().getSequence();
377
378                // Both sequences of a match are equally long
379                for (int i = 0; i < m.getFirstSequence().size(); i++) {
380
381                        // Two gaps aligned to each other: Have not seen it happening so
382                        // far, just to handle it
383                        if (first[i] == -1 && second[i] == -1) {
384                                // TODO: Do nothing?
385                        }
386                        // Both events are equal, we can simply add the task referring to
387                        // the number
388                        else if (first[i] == second[i]) {
389                                taskBuilder.addChild(sequence,
390                                                appData.getNumber2Task().get(first[i]));
391                        }
392                        // We have a gap in the first sequence, we need to add the task of
393                        // the second sequence as optional
394                        else if (first[i] == -1 && second[i] != -1) {
395                                IOptional optional = taskFactory.createNewOptional();
396                                appData.uniqueTasks.add(optional);
397                                appData.number2task.put(optional.getId(), optional);
398                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task()
399                                                .get(second[i]));
400                                taskBuilder.addChild(sequence, optional);
401                        }
402                        // We have a gap in the second sequence, we need to add the task of
403                        // the first sequence as optional
404                        else if (first[i] != -1 && second[i] == -1) {
405                                IOptional optional = taskFactory.createNewOptional();
406                                appData.uniqueTasks.add(optional);
407                                appData.number2task.put(optional.getId(), optional);
408                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task()
409                                                .get(first[i]));
410                                taskBuilder.addChild(sequence, optional);
411                        }
412                        // Both tasks are not equal, we need to insert a selection here
413                        else {
414                                ISelection selection = taskFactory.createNewSelection();
415                                appData.getUniqueTasks().add(selection);
416                                appData.number2task.put(selection.getId(), selection);
417                                taskBuilder.addChild(selection,
418                                                appData.getNumber2Task().get(first[i]));
419                                taskBuilder.addChild(selection,
420                                                appData.getNumber2Task().get(second[i]));
421                                taskBuilder.addChild(sequence, selection);
422                        }
423                }
424
425                // TODO: Debug output
426                /*
427                 * for (int i =0;i<sequence.getChildren().size();i++) {
428                 * System.out.println(sequence.getChildren().get(i));
429                 *
430                 * if(sequence.getChildren().get(i).getType() == "selection") { for(int
431                 * j=0; j< ((ISelection)
432                 * sequence.getChildren().get(i)).getChildren().size();j++) {
433                 * System.out.println("\t" +((ISelection)
434                 * sequence.getChildren().get(i)).getChildren().get(j)); } } }
435                 */
436                return sequence;
437        }
438
439
440        /**
441         *
442         * @param appData
443         *            the rule application data combining all data used for applying
444         *            this rule
445         */
446        private void detectAndReplaceTasks(RuleApplicationData appData) {
447                Console.traceln(Level.FINE, "detecting and replacing tasks");
448                appData.getStopWatch().start("detecting tasks");
449
450                // Create NumberSequences
451                appData.setNumberSequences(this.createNumberSequences(appData));
452
453                // Generate a substitution matrix between all occurring events.
454                Console.traceln(Level.INFO, "generating substitution matrix");
455                ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix(
456                                appData.getUniqueTasks(), 6, -3);
457                submat.generate();
458
459                // Generate pairwise alignments
460                Console.traceln(Level.INFO, "generating pairwise alignments");
461                LinkedList<Match> matchseqs = new LinkedList<Match>();
462                PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator
463                                .generate(appData.getNumberSequences(), submat, 9);
464
465                // Retrieve all matches reached a specific threshold
466                Console.traceln(Level.INFO, "retrieving significant sequence pieces");
467                for (int i = 0; i < appData.getNumberSequences().size(); i++) {
468                        Console.traceln(
469                                        Level.FINEST,
470                                        "retrieving significant sequence pieces:  "
471                                                        + Math.round((float) i
472                                                                        / (float) appData.getNumberSequences()
473                                                                                        .size() * 100) + "%");
474                        for (int j = 0; j < appData.getNumberSequences().size(); j++) {
475                                if (i != j) {
476                                        matchseqs.addAll(alignments.get(i, j).getMatches());
477                                }
478                        }
479                }
480               
481                Console.traceln(Level.FINEST,
482                                "retrieving significant sequence pieces:  100%");
483                Console.traceln(Level.INFO, "searching for patterns occuring most");
484
485                // search each match in every other sequence
486                for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) {
487                        Match pattern = it.next();
488
489                        // Skip sequences with more 0 events (scrolls) than other events.
490                        // Both of the pattern sequences are equally long, so the zero
491                        // counts just need to be smaller than the length of one sequence
492                        if (pattern.getFirstSequence().eventCount(0)
493                                        + pattern.getSecondSequence().eventCount(0) + 1 > pattern
494                                        .getFirstSequence().size())
495                                continue;
496
497                        for (int j = 0; j < appData.getNumberSequences().size(); j++) {
498                                LinkedList<Integer> startpositions = appData
499                                                .getNumberSequences().get(j).containsPattern(pattern);
500                                if (startpositions.size() > 0) {
501                                        for (Iterator<Integer> jt = startpositions.iterator(); jt
502                                                        .hasNext();) {
503                                                int start = jt.next();
504                                                pattern.addOccurence(new MatchOccurence(start, start
505                                                                + pattern.size(), j));
506                                        }
507
508                                }
509                        }
510                }
511
512                Console.traceln(Level.INFO, "sorting results");
513                // Sort results to get the most occurring results
514                Comparator<Match> comparator = new Comparator<Match>() {
515                        public int compare(Match m1, Match m2) {
516                                return m2.occurenceCount() - m1.occurenceCount();
517
518                        }
519                };
520                Collections.sort(matchseqs, comparator);
521                appData.getStopWatch().stop("detecting tasks");
522
523                appData.getStopWatch().start("replacing tasks");
524                HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>();
525                // Replace matches in the sessions
526                for (int i = 0; i < matchseqs.size(); i++) {
527                        // Every pattern consists of 2 sequences, therefore the minimum
528                        // occurrences here is 2.
529                        // We just need the sequences also occurring in other sequences as
530                        // well
531                        if (matchseqs.get(i).occurenceCount() > 2) {
532                               
533                                appData.detectedAndReplacedTasks = true;
534                                ISequence task = matchAsSequence(appData, matchseqs.get(i));
535                                invalidOccurence: for (Iterator<MatchOccurence> it = matchseqs
536                                                .get(i).getOccurences().iterator(); it.hasNext();) {
537                                        MatchOccurence oc = it.next();
538
539                                        if(iteration==-1) {
540                                          System.out.println("Trying to replace sequence: ");
541                                          matchseqs.get(i).getFirstSequence().printSequence();
542                                          matchseqs.get(i).getSecondSequence().printSequence();
543                                          System.out.println(" in session number: " +
544                                          (oc.getSequenceId() + 1) + " at position " +
545                                          (oc.getStartindex()) + "-" + oc.getEndindex());
546                                          System.out.println();
547                                         
548
549                                          System.out.println("Printing session: ");
550                                         for (int j = 0; j <
551                                        appData.getSessions().get(oc.getSequenceId()).size();
552                                         j++) {
553                                         System.out.println(j + ": "
554                                         + appData.getSessions().get(oc.getSequenceId()).get(j));
555                                         }
556                                        }
557
558                                        // Check if nothing has been replaced in the sequence we
559                                        // want to replace
560                                        if (replacedOccurences.get(oc.getSequenceId()) == null) {
561                                                replacedOccurences.put(oc.getSequenceId(),
562                                                                new LinkedList<MatchOccurence>());
563                                        } else {
564                                                // check if we have any replaced occurence with indexes
565                                                // smaller than ours. If so, we need to adjust our start
566                                                // and endpoints
567                                                // of the replacement.
568                                                // Also do a check if we have replaced this specific
569                                                // MatchOccurence in this sequence already. Jump to the
570                                                // next occurence if this is the case.
571                                                // This is no more neccessary once the matches are
572                                                // harmonized.
573                                                for (Iterator<MatchOccurence> jt = replacedOccurences
574                                                                .get(oc.getSequenceId()).iterator(); jt
575                                                                .hasNext();) {
576                                                        MatchOccurence tmpOC = jt.next();
577
578                                                        if (oc.getStartindex() >= tmpOC.getStartindex()
579                                                                        && oc.getStartindex() <= tmpOC
580                                                                                        .getEndindex()) {
581                                                                continue invalidOccurence;
582                                                        }
583                                                        if (oc.getEndindex() >= tmpOC.getStartindex()) {
584                                                                continue invalidOccurence;
585
586                                                        } else if (oc.getStartindex() > tmpOC.getEndindex()) {
587                                                                int diff = tmpOC.getEndindex()
588                                                                                - tmpOC.getStartindex();
589                                                                // Just to be sure.
590                                                                if (diff > 0) {
591                                                                        oc.setStartindex(oc.getStartindex() - diff
592                                                                                        + 1);
593                                                                        oc.setEndindex(oc.getEndindex() - diff + 1);
594                                                                } else {
595                                                                        Console.traceln(Level.WARNING,
596                                                                                        "End index of a Match before start. This should never happen");
597                                                                }
598                                                        }
599                                                }
600                                        }
601                                        ISequenceInstance sequenceInstances = RuleUtils
602                                                        .createNewSubSequenceInRange(appData.getSessions()
603                                                                        .get(oc.getSequenceId()), oc
604                                                                        .getStartindex(), oc.getEndindex(), task,
605                                                                        taskFactory, taskBuilder);
606                                        // Adjust the length of the match regarding to the length of
607                                        // instance. (OptionalInstances may be shorter)
608                                        oc.setEndindex(oc.getStartindex()
609                                                        + sequenceInstances.size()
610                                                        - RuleUtils.missedOptionals);
611                                        replacedOccurences.get(oc.getSequenceId()).add(oc);
612                                }
613                        }
614                }
615
616                alignments = null;
617                matchseqs = null;
618                appData.getStopWatch().stop("replacing tasks");
619        }
620
621       
622
623        /**
624     *
625     */
626        private static class RuleApplicationData {
627
628                private HashMap<Integer, ITask> number2task;
629
630                //TODO: We Actually just need number2task here
631                private HashSet<ITask> uniqueTasks;
632
633                private ArrayList<NumberSequence> numberseqs;
634
635                /**
636         *
637         */
638                private List<IUserSession> sessions;
639
640                /**
641         *
642         */
643                private boolean detectedAndReplacedTasks;
644
645                /**
646         *
647         */
648                private RuleApplicationResult result;
649
650                /**
651         *
652         */
653                private StopWatch stopWatch;
654
655                /**
656         *
657         */
658                private RuleApplicationData(List<IUserSession> sessions) {
659                        this.sessions = sessions;
660                        numberseqs = new ArrayList<NumberSequence>();
661                        uniqueTasks = new HashSet<ITask>();
662                        number2task = new HashMap<Integer, ITask>();
663                        stopWatch = new StopWatch();
664                        result = new RuleApplicationResult();
665                }
666
667                /**
668                 * @return the tree
669                 */
670                private List<IUserSession> getSessions() {
671                        return sessions;
672                }
673
674                private HashSet<ITask> getUniqueTasks() {
675                        return uniqueTasks;
676                }
677
678                // private void setUniqueTasks(SymbolMap<ITaskInstance, ITask> ut) {
679                // this.uniqueTasks = ut;
680                // }
681
682                private void setNumberSequences(ArrayList<NumberSequence> numberseqs) {
683                        this.numberseqs = numberseqs;
684                }
685
686                private ArrayList<NumberSequence> getNumberSequences() {
687                        return numberseqs;
688                }
689
690                /**
691         *
692         */
693                private boolean detectedAndReplacedTasks() {
694                        return detectedAndReplacedTasks;
695                }
696
697                /**
698                 * @return the result
699                 */
700                private RuleApplicationResult getResult() {
701                        return result;
702                }
703
704                /**
705                 * @return the stopWatch
706                 */
707                private StopWatch getStopWatch() {
708                        return stopWatch;
709                }
710
711                private HashMap<Integer, ITask> getNumber2Task() {
712                        return number2task;
713                }
714
715        }
716
717}
Note: See TracBrowser for help on using the repository browser.