source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java @ 1127

Last change on this file since 1127 was 1127, checked in by pharms, 11 years ago
  • complete refactoring of task detection
  • many performance improvements in task detection
  • improved merging of sequences using Myers diff algorithm
File size: 30.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.Iterator;
18import java.util.LinkedList;
19import java.util.List;
20
21import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality;
22import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
29import de.ugoe.cs.autoquest.usageprofiles.Trie;
30import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor;
31import de.ugoe.cs.util.console.Console;
32
33/**
34 * <p>
35 * TODO comment
36 * </p>
37 *
38 * @author Patrick Harms
39 */
40class SequenceForTaskDetectionRule implements TemporalRelationshipRule {
41   
42    /**
43     * <p>
44     * the task tree node factory to be used for creating substructures for the temporal
45     * relationships identified during rule
46     * </p>
47     */
48    private ITaskTreeNodeFactory taskTreeNodeFactory;
49    /**
50     * <p>
51     * the task tree builder to be used for creating substructures for the temporal relationships
52     * identified during rule application
53     * </p>
54     */
55    private ITaskTreeBuilder taskTreeBuilder;
56
57    /**
58     * <p>
59     * the node comparator to be used for comparing task tree nodes
60     * </p>
61     */
62    private TaskTreeNodeComparator nodeComparator;
63
64    /**
65     * <p>
66     * instantiates the rule and initializes it with a node equality rule manager and the minimal
67     * node equality identified sublist must have to consider them as iterated.
68     * </p>
69     */
70    SequenceForTaskDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager,
71                                 NodeEquality            minimalNodeEquality,
72                                 ITaskTreeNodeFactory    taskTreeNodeFactory,
73                                 ITaskTreeBuilder        taskTreeBuilder)
74    {
75        this.taskTreeNodeFactory = taskTreeNodeFactory;
76        this.taskTreeBuilder = taskTreeBuilder;
77       
78        this.nodeComparator =
79            new TaskTreeNodeComparator(nodeEqualityRuleManager, minimalNodeEquality);
80    }
81
82    /* (non-Javadoc)
83     * @see java.lang.Object#toString()
84     */
85    @Override
86    public String toString() {
87        return "SequenceForTaskDetectionRule";
88    }
89
90    /*
91     * (non-Javadoc)
92     *
93     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
94     * boolean)
95     */
96    @Override
97    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
98        if (!(parent instanceof ISequence)) {
99            return null;
100        }
101
102        if (!finalize) {
103            // the rule is always feasible as tasks may occur at any time
104            RuleApplicationResult result = new RuleApplicationResult();
105            result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE);
106            return result;
107        }
108
109        List<ITaskTreeNode> children = parent.getChildren();
110        List<ISequence> sessions = new LinkedList<ISequence>();
111       
112        for (ITaskTreeNode child : children) {
113            if (child instanceof ISequence) {
114                sessions.add((ISequence) child);
115            }
116            else {
117                Console.println("provided parent is no parent of sessions");
118                return null;
119            }
120        }
121       
122        RuleApplicationData appData = new RuleApplicationData(sessions);
123
124        boolean finished = false;
125       
126        // this is the real rule application. Loop while something is replaced.
127        do {
128            System.out.println();
129           
130            appData.getStopWatch().start("whole loop");
131            detectAndReplaceIterations(appData);
132            //mergeEqualTasks(appData);
133            appData.getStopWatch().start("task replacement");
134            detectAndReplaceTasks(appData);
135            appData.getStopWatch().stop("task replacement");
136            appData.getStopWatch().stop("whole loop");
137           
138            //((TaskTreeNodeComparator) nodeComparator).getStopWatch().dumpStatistics(System.out);
139            //((TaskTreeNodeComparator) nodeComparator).getStopWatch().reset();
140           
141            appData.getStopWatch().dumpStatistics(System.out);
142            appData.getStopWatch().reset();
143           
144            finished = (appData.getReplacementCounter() == 0);
145        }
146        while (!finished);
147       
148        System.out.println("created " + appData.getResult().getNewlyCreatedParentNodes().size() +
149                           " new parent nodes\n");
150       
151        if (appData.getResult().getNewlyCreatedParentNodes().size() > 0) {
152            appData.getResult().setRuleApplicationStatus(RuleApplicationStatus.FINISHED);
153        }
154       
155        return appData.getResult();
156    }
157
158    /**
159     * <p>
160     * TODO: comment
161     * </p>
162     *
163     * @param appData
164     */
165    private void detectAndReplaceIterations(RuleApplicationData appData) {
166        System.out.print("detecting iterations");
167        appData.getStopWatch().start("detecting iterations");
168       
169        List<ISequence> sessions = appData.getSessions();
170        int foundIterations = 0;
171       
172        for (ISequence session : sessions) {
173            foundIterations += detectAndReplaceIterations(session, appData);
174        }
175       
176        appData.getStopWatch().stop("detecting iterations");
177        System.out.println(" --> found " + foundIterations);
178    }
179
180    /**
181     * <p>
182     * TODO: comment
183     * </p>
184     *
185     * @param appData
186     */
187    private int detectAndReplaceIterations(ISequence           session,
188                                           RuleApplicationData appData)
189    {
190        int count = 0;
191       
192        TemporalRelationshipRule rule = new SimpleIterationDetectionRule
193            (nodeComparator, taskTreeNodeFactory, taskTreeBuilder);
194
195        RuleApplicationResult result = rule.apply(session, true);
196           
197        if ((result != null) && (result.getNewlyCreatedParentNodes() != null)) {
198            for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) {
199                appData.getResult().addNewlyCreatedParentNode(newParent);
200                if (newParent instanceof IIteration) {
201                    count++;
202                }
203            }
204        }
205       
206        return count;
207    }
208
209//    /**
210//     * <p>
211//     * TODO: comment
212//     * </p>
213//     *
214//     * @param appData
215//     */
216//    private void mergeEqualTasks(RuleApplicationData appData) {
217//        System.out.println("merging equal tasks");
218//        appData.getStopWatch().start("merging equal tasks");
219//       
220//        int replacements = 0;
221//        List<ISequence> sessions = appData.getSessions();
222//       
223//        IdentityHashMap<ITaskTreeNode, ITaskTreeNode> replacedChildren =
224//            new IdentityHashMap<ITaskTreeNode, ITaskTreeNode>();
225//       
226//        for (int sessionIdx1 = 0; sessionIdx1 < sessions.size(); sessionIdx1++) {
227//            List<ITaskTreeNode> children1 = appData.getSessions().get(sessionIdx1).getChildren();
228//            for (int childIdx1 = 0; childIdx1 < children1.size(); childIdx1++) {
229//                // this is the child of which we search equal other children to merge and to
230//                // replace with one single unique node
231//                ITaskTreeNode child1 = children1.get(childIdx1);
232//               
233//                if (replacedChildren.containsKey(child1)) {
234//                    continue;
235//                }
236//               
237//                // now search for all other children that are equal. Also record the session they
238//                // belong to as well as the index in that session
239//                List<ITaskTreeNode> equalChildren = new LinkedList<ITaskTreeNode>();
240//                List<Integer> sessionIndexes = new LinkedList<Integer>();
241//                List<Integer> childIndexes = new LinkedList<Integer>();
242//
243//                // add all information about the current child
244//                equalChildren.add(child1);
245//                sessionIndexes.add(sessionIdx1);
246//                childIndexes.add(childIdx1);
247//               
248//                for (int sessionIdx2 = sessionIdx1; sessionIdx2 < sessions.size(); sessionIdx2++) {
249//                    List<ITaskTreeNode> children2 =
250//                          appData.getSessions().get(sessionIdx2).getChildren();
251//                   
252//                    int startIndex = (sessionIdx1 == sessionIdx2) ? childIdx1 + 1 : 0;
253//                   
254//                    for (int childIdx2 = startIndex; childIdx2 < children2.size(); childIdx2++) {
255//                        ITaskTreeNode child2 = children2.get(childIdx2);
256//                       
257//                        if ((child1 != child2) && (nodeComparator.equals(child1, child2))) {
258//                            // this is an equal child --> record its occurrence
259//                            equalChildren.add(child2);
260//                            sessionIndexes.add(sessionIdx2);
261//                            childIndexes.add(childIdx2);
262//                        }
263//                    }
264//                }
265//               
266//                // now merge the found children
267//                if (equalChildren.size() > 1) {
268//                    ITaskTreeNode replacement =
269//                        mergeVariantsOfTasks(child1.toString(), equalChildren);
270//
271//                    for (int i = 0; i < sessionIndexes.size(); i++) {
272//                        taskTreeBuilder.setChild(appData.getSessions().get(sessionIndexes.get(i)),
273//                                                 childIndexes.get(i), replacement);
274//                   
275//                        replacements++;
276//                    }
277//                   
278//                    // remember the replacement to prevent comparison of merged nodes
279//                    replacedChildren.put(replacement, replacement);
280//                   
281//                    System.out.println
282//                        ("replaced " + sessionIndexes.size() + " occurrences of " + child1);
283//                }
284//            }
285//        }
286//
287//        appData.getStopWatch().stop("merging equal tasks");
288//       
289//        System.out.println("replaced " + replacements + " equal tasks with unique replacements");
290//    }
291//
292    /**
293     * <p>
294     * TODO: comment
295     * </p>
296     *
297     * @param appData
298     */
299    private void detectAndReplaceTasks(RuleApplicationData appData) {
300        System.out.println("detecting and replacing tasks");
301        appData.getStopWatch().start("detecting tasks");
302       
303        getSequencesOccuringMostOften(appData);
304
305        appData.getStopWatch().stop("detecting tasks");
306        appData.getStopWatch().start("replacing tasks");
307       
308        replaceSequencesOccurringMostOften(appData);
309       
310        appData.getStopWatch().stop("replacing tasks");
311        System.out.println("detected and replaced " + appData.getLastFoundTasks().size() + " tasks");
312    }
313
314    /**
315     * <p>
316     * TODO: comment
317     * </p>
318     *
319     * @param i
320     * @return
321     */
322    private void getSequencesOccuringMostOften(RuleApplicationData appData) {
323        System.out.println("determining most prominent tasks");
324
325        Tasks tasks;
326        boolean createNewTrie = (appData.getLastTrie() == null) ||
327            appData.getReplacementCounter() > 0; // tree has changed
328       
329        do {
330            if (createNewTrie) {
331                createNewTrie(appData);
332            }
333           
334            MaxCountAndLongestTasksFinder finder = new MaxCountAndLongestTasksFinder();
335            appData.getLastTrie().process(finder);
336       
337            tasks = finder.getFoundTasks();
338           
339            createNewTrie = false;
340           
341            for (List<ITaskTreeNode> task : tasks) {
342                if (task.size() >= appData.getTrainedSequenceLength()) {
343                    // Trie must be recreated with a longer sequence length to be sure that
344                    // the found sequences occurring most often are found in their whole length
345                    appData.setTrainedSequenceLength(appData.getTrainedSequenceLength() + 1);
346                    createNewTrie = true;
347                    break;
348                }
349            }
350        }
351        while (createNewTrie);
352       
353        appData.setLastFoundTasks(tasks);
354
355        System.out.println("found " + appData.getLastFoundTasks().size() + " tasks occurring " +
356                           appData.getLastFoundTasks().getOccurrenceCount() + " times");
357    }
358
359    /**
360     * <p>
361     * TODO: comment
362     * </p>
363     *
364     * @param parent
365     * @return
366     */
367    private void createNewTrie(RuleApplicationData appData) {
368        System.out.println("training trie with a maximum sequence length of " +
369                           appData.getTrainedSequenceLength());
370
371        appData.getStopWatch().start("training trie");
372        appData.setLastTrie(new Trie<ITaskTreeNode>(nodeComparator));
373   
374        List<ISequence> sessions = appData.getSessions();
375       
376        for (ISequence session : sessions) {
377            trainTrie(session, appData);
378        }
379       
380        appData.getStopWatch().stop("training trie");
381    }
382
383    /**
384     * <p>
385     * TODO: comment
386     * </p>
387     *
388     * @param trie
389     * @param parent
390     */
391    private void trainTrie(ISequence session, RuleApplicationData appData) {
392        List<ITaskTreeNode> children = session.getChildren();
393       
394        if ((children != null) && (children.size() > 0)) {
395            appData.getLastTrie().train(children, appData.getTrainedSequenceLength());
396        }
397    }
398
399    /**
400     * <p>
401     * TODO: comment
402     * </p>
403     *
404     * @param appData
405     */
406    private void replaceSequencesOccurringMostOften(RuleApplicationData appData) {
407        appData.resetReplacementCounter();
408
409        if ((appData.getLastFoundTasks().size() > 0) &&
410            (appData.getLastFoundTasks().getOccurrenceCount() > 1))
411        {
412            System.out.println("replacing tasks occurrences with merged variants of all versions");
413
414            for (List<ITaskTreeNode> task : appData.getLastFoundTasks()) {
415                String taskId = "task " + RuleUtils.getNewId();
416                System.out.println("replacing " + taskId + ": " + task);
417
418                appData.clearTaskOccurrences();
419                determineVariantsOfTaskOccurrences(task, appData.getSessions(), appData);
420               
421                appData.getStopWatch().start("merging task nodes");
422                ITaskTreeNode taskReplacement = mergeVariantsOfTaskOccurrence(taskId, appData);
423                appData.getStopWatch().stop("merging task nodes");
424
425                appData.resetReplacementCounter();
426                replaceTaskOccurrences(task, taskReplacement, appData.getSessions(), appData);
427
428                if (appData.getReplacementCounter() > 0) {
429                    appData.getResult().addNewlyCreatedParentNode(taskReplacement);
430                }
431
432                if (appData.getReplacementCounter() <
433                    appData.getLastFoundTasks().getOccurrenceCount())
434                {
435                    System.out.println(taskId + ": replaced task only " +
436                                       appData.getReplacementCounter() +
437                                       " times instead of expected " +
438                                       appData.getLastFoundTasks().getOccurrenceCount());
439                }
440            }
441        }
442       
443    }
444
445    /**
446     * <p>
447     * TODO: comment
448     * </p>
449     *
450     * @param tree
451     */
452    private void determineVariantsOfTaskOccurrences(List<ITaskTreeNode> task,
453                                                    List<ISequence>     sessions,
454                                                    RuleApplicationData appData)
455    {
456        for (ISequence session : sessions) {
457            int index = -1;
458               
459            List<ITaskTreeNode> children = session.getChildren();
460
461            do {
462                index = getSubListIndex(children, task, ++index);
463
464                if (index > -1) {
465                    ISequence taskOccurrence = RuleUtils.getSubSequenceInRange
466                            (session, index, index + task.size() - 1, null,
467                             taskTreeNodeFactory, taskTreeBuilder);
468
469                    appData.addTaskOccurrence(taskOccurrence);
470
471                    // let the index point to the last element the belongs the identified occurrence
472                    index += task.size() - 1;
473                }
474            }
475            while (index > -1);
476        }
477    }
478
479    /**
480     * <p>
481     * TODO: comment
482     * </p>
483     *
484     * @param appData
485     * @return
486     */
487    private ITaskTreeNode mergeVariantsOfTaskOccurrence(String              taskId,
488                                                        RuleApplicationData appData)
489    {
490        return mergeVariantsOfTasks(taskId, appData.getTaskOccurrences());
491    }
492
493    /**
494     * <p>
495     * TODO: comment
496     * </p>
497     *
498     * @param appData
499     * @return
500     */
501    private ITaskTreeNode mergeVariantsOfTasks(String description, List<ITaskTreeNode> variants) {
502        // merge but preserve lexically distinct variants
503        TaskTreeNodeMerger merger = new TaskTreeNodeMerger
504            (taskTreeNodeFactory, taskTreeBuilder, nodeComparator);
505       
506        merger.mergeTaskNodes(variants);
507       
508        if (variants.size() == 1) {
509            ITaskTreeNode replacement = variants.get(0);
510            taskTreeBuilder.setDescription(replacement, description);
511            return replacement;
512        }
513        else {
514            ISelection selection = taskTreeNodeFactory.createNewSelection();
515            taskTreeBuilder.setDescription(selection, "variants of task " + description);
516           
517            for (ITaskTreeNode variant : variants) {
518                taskTreeBuilder.addChild(selection, variant);
519            }
520           
521            return selection;
522        }
523    }
524
525    /**
526     * <p>
527     * TODO: comment
528     * </p>
529     *
530     * @param task
531     * @param parent
532     * @param treeBuilder
533     * @param nodeFactory
534     * @param result
535     */
536    private void replaceTaskOccurrences(List<ITaskTreeNode> task,
537                                        ITaskTreeNode       replacement,
538                                        List<ISequence>     sessions,
539                                        RuleApplicationData appData)
540    {
541        // now check the children themselves for an occurrence of the task
542        for (int i = 0; i < sessions.size(); i++) {
543            ISequence session = sessions.get(i);
544           
545            int index = -1;
546       
547            List<ITaskTreeNode> children = session.getChildren();
548
549            do {
550                index = getSubListIndex(children, task, ++index);
551
552                if (index > -1) {
553                    if ((!(replacement instanceof ISequence)) ||
554                        (task.size() < children.size()))
555                    {
556                        for (int j = index; j < index + task.size(); j++) {
557                            taskTreeBuilder.removeChild(session, index);
558                        }
559
560                        taskTreeBuilder.addChild(session, index, replacement);
561                        appData.incrementReplacementCounter();
562
563                        children = session.getChildren();
564                    }
565                    else {
566                        // the whole list of children is an occurrence of this task. So ask the
567                        // caller of the method to replace the whole node
568                        sessions.set(i, (ISequence) replacement);
569                        appData.incrementReplacementCounter();
570                        break;
571                    }
572                }
573            }
574            while (index > -1);
575        }
576    }
577
578    /**
579     * <p>
580     * TODO: comment
581     * </p>
582     *
583     * @param trie
584     * @param object
585     * @return
586     */
587    private int getSubListIndex(List<ITaskTreeNode> list,
588                                List<ITaskTreeNode> subList,
589                                int                 startIndex)
590    {
591        boolean matchFound;
592        int result = -1;
593       
594        for (int i = startIndex; i <= list.size() - subList.size(); i++) {
595            matchFound = true;
596           
597            for (int j = 0; j < subList.size(); j++) {
598                if (!nodeComparator.equals(list.get(i + j), subList.get(j))) {
599                    matchFound = false;
600                    break;
601                }
602            }
603           
604            if (matchFound) {
605                result = i;
606                break;
607            }
608        }
609       
610        return result;
611    }
612   
613    /**
614     * <p>
615     * TODO comment
616     * </p>
617     *
618     * @author Patrick Harms
619     */
620    private class MaxCountAndLongestTasksFinder implements TrieProcessor<ITaskTreeNode> {
621       
622        /**
623         *
624         */
625        private int currentCount;
626       
627        /**
628         *
629         */
630        private List<List<ITaskTreeNode>> foundTasks = new LinkedList<List<ITaskTreeNode>>();
631
632        /**
633         * <p>
634         * TODO: comment
635         * </p>
636         *
637         * @param maxCount
638         */
639        public MaxCountAndLongestTasksFinder() {
640            super();
641            this.currentCount = 0;
642        }
643
644        /* (non-Javadoc)
645         * @see de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util.List, int)
646         */
647        @Override
648        public TrieProcessor.Result process(List<ITaskTreeNode> task, int count) {
649            if (task.size() < 2) {
650                // ignore single nodes
651                return TrieProcessor.Result.CONTINUE;
652            }
653           
654            if (count < 2) {
655                // ignore singular occurrences
656                return TrieProcessor.Result.SKIP_NODE;
657            }
658
659            if (this.currentCount > count) {
660                // ignore this children of this node, as they may have only smaller counts than
661                // the already found tasks
662                return TrieProcessor.Result.SKIP_NODE;
663            }
664           
665            if (this.currentCount < count) {
666                // the provided task occurs more often that all tasks found so far.
667                // clear all found tasks and use the new count as the one searched for
668                foundTasks.clear();
669                this.currentCount = count;
670            }
671           
672            if (this.currentCount == count) {
673                // the task is of interest. Sort it into the other found tasks so that
674                // the longest come first
675                boolean added = false;
676                for (int i = 0; i < foundTasks.size(); i++) {
677                    if (foundTasks.get(i).size() < task.size()) {
678                        // defensive copy
679                        foundTasks.add(i, new LinkedList<ITaskTreeNode>(task)); // defensive copy
680                        added = true;
681                        break;
682                    }
683                }
684               
685                if (!added) {
686                    foundTasks.add(new LinkedList<ITaskTreeNode>(task)); // defensive copy
687                }
688            }
689           
690            return TrieProcessor.Result.CONTINUE;
691        }
692
693        /**
694         * <p>
695         * TODO: comment
696         * </p>
697         *
698         * @return
699         */
700        public Tasks getFoundTasks() {
701            removePermutationsOfShorterTasks();
702            return new Tasks(currentCount, foundTasks);
703        }
704
705        /**
706         * <p>
707         * TODO: comment
708         * </p>
709         *
710         */
711        private void removePermutationsOfShorterTasks() {
712            // now iterate the sorted list and for each task remove all other tasks that are shorter
713            // (i.e. come later in the sorted list) and that represent a subpart of the task
714            for (int i = 0; i < foundTasks.size(); i++) {
715                for (int j = i + 1; j < foundTasks.size();) {
716                    if (foundTasks.get(j).size() < foundTasks.get(i).size()) {
717                        // found a task that is a potential subtask. Check for this and remove the
718                        // subtask if needed
719                        List<ITaskTreeNode> longTask = foundTasks.get(i);
720                        List<ITaskTreeNode> shortTask = foundTasks.get(j);
721                       
722                        if (getSubListIndex(longTask, shortTask, 0) > -1) {
723                            foundTasks.remove(j);
724                        }
725                        else {
726                            j++;
727                        }
728                    }
729                    else {
730                        j++;
731                    }
732                }
733            }
734        }
735
736    }
737   
738    /**
739     *
740     */
741    private class RuleApplicationData {
742       
743        /**
744         *
745         */
746        private List<ISequence> sessions;
747       
748        /**
749         *
750         */
751        private Trie<ITaskTreeNode> lastTrie;
752       
753        /**
754         * default and minimum trained sequence length is 3
755         */
756        private int trainedSequenceLength = 3;
757       
758        /**
759         *
760         */
761        private Tasks lastFoundTasks = new Tasks(Integer.MAX_VALUE, null);
762       
763        /**
764         *
765         */
766        private List<ITaskTreeNode> taskOccurrences = new LinkedList<ITaskTreeNode>();
767       
768        /**
769         *
770         */
771        private int replacementCounter;
772       
773        /**
774         *
775         */
776        private RuleApplicationResult result = new RuleApplicationResult();
777       
778        /**
779         *
780         */
781        private StopWatch stopWatch = new StopWatch();
782       
783        /**
784         *
785         */
786        private RuleApplicationData(List<ISequence> sessions) {
787            this.sessions = sessions;
788        }
789
790        /**
791         * @return the tree
792         */
793        private List<ISequence> getSessions() {
794            return sessions;
795        }
796
797        /**
798         * @param lastTrie the lastTrie to set
799         */
800        private void setLastTrie(Trie<ITaskTreeNode> lastTrie) {
801            this.lastTrie = lastTrie;
802        }
803
804        /**
805         * @return the lastTrie
806         */
807        private Trie<ITaskTreeNode> getLastTrie() {
808            return lastTrie;
809        }
810
811        /**
812         * @param trainedSequenceLength the trainedSequenceLength to set
813         */
814        private void setTrainedSequenceLength(int trainedSequenceLength) {
815            this.trainedSequenceLength = trainedSequenceLength;
816        }
817
818        /**
819         * @return the trainedSequenceLength
820         */
821        private int getTrainedSequenceLength() {
822            return trainedSequenceLength;
823        }
824
825        /**
826         * @param lastFoundSequences the lastFoundSequences to set
827         */
828        private void setLastFoundTasks(Tasks lastFoundSequences) {
829            this.lastFoundTasks = lastFoundSequences;
830        }
831
832        /**
833         * @return the lastFoundSequences
834         */
835        private Tasks getLastFoundTasks() {
836            return lastFoundTasks;
837        }
838
839        /**
840         * @return the taskOccurrences
841         */
842        private void clearTaskOccurrences() {
843            taskOccurrences.clear();
844        }
845
846        /**
847         * @return the taskOccurrences
848         */
849        private void addTaskOccurrence(ITaskTreeNode taskOccurrence) {
850            taskOccurrences.add(taskOccurrence);
851        }
852
853        /**
854         * @return the taskOccurrences
855         */
856        private List<ITaskTreeNode> getTaskOccurrences() {
857            return taskOccurrences;
858        }
859
860        /**
861         *
862         */
863        private void resetReplacementCounter() {
864            replacementCounter = 0;
865        }
866
867        /**
868         *
869         */
870        private void incrementReplacementCounter() {
871            replacementCounter++;
872        }
873
874        /**
875         *
876         */
877        private int getReplacementCounter() {
878            return replacementCounter;
879        }
880       
881        /**
882         * @return the result
883         */
884        private RuleApplicationResult getResult() {
885            return result;
886        }
887
888        /**
889         * @return the stopWatch
890         */
891        private StopWatch getStopWatch() {
892            return stopWatch;
893        }
894
895    }
896   
897
898    /**
899     * <p>
900     * TODO comment
901     * </p>
902     *
903     * @author Patrick Harms
904     */
905    private class Tasks implements Iterable<List<ITaskTreeNode>> {
906       
907        /**
908         *
909         */
910        private int occurrenceCount;
911       
912        /**
913         *
914         */
915        private List<List<ITaskTreeNode>> sequences;
916
917        /**
918         * <p>
919         * TODO: comment
920         * </p>
921         *
922         * @param occurrenceCount
923         * @param sequences
924         */
925        private Tasks(int occurrenceCount, List<List<ITaskTreeNode>> sequences) {
926            super();
927            this.occurrenceCount = occurrenceCount;
928            this.sequences = sequences;
929        }
930
931        /**
932         * <p>
933         * TODO: comment
934         * </p>
935         *
936         * @return
937         */
938        private int getOccurrenceCount() {
939            return occurrenceCount;
940        }
941
942        /**
943         * <p>
944         * TODO: comment
945         * </p>
946         *
947         * @return
948         */
949        private int size() {
950            return this.sequences.size();
951        }
952
953        /**
954         *
955         */
956
957        /* (non-Javadoc)
958         * @see java.lang.Iterable#iterator()
959         */
960        @Override
961        public Iterator<List<ITaskTreeNode>> iterator() {
962            return this.sequences.iterator();
963        }
964
965    }
966
967}
Note: See TracBrowser for help on using the repository browser.