Ignore:
Timestamp:
07/30/14 17:06:47 (10 years ago)
Author:
rkrimmel
Message:

Generated Model of matches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java

    r1621 r1630  
    2727import java.util.logging.Level; 
    2828 
    29 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 
    3029import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 
    3130import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; 
     
    3433import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage; 
    3534import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 
    36 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.tree.UPGMAAligningTree; 
    3735import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
    3836import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    3937import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
     38import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    4039import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    4140import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
     
    4948import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    5049import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; 
    51 import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor; 
    5250import de.ugoe.cs.util.StopWatch; 
    5351import de.ugoe.cs.util.console.Console; 
     
    9795         * <p> 
    9896         * the task handling strategy to be used for comparing tasks during 
    99          * iteration detection an trie generation, i.e., after the tasks are 
     97         * iteration detection i.e., after the tasks are 
    10098         * harmonized 
    10199         * </p> 
    102100         */ 
    103         private TaskHandlingStrategy identityTaskHandlingStrategy;; 
    104  
    105         private ArrayList<NumberSequence> numberseqs; 
     101        private TaskHandlingStrategy identityTaskHandlingStrategy; 
     102 
     103 
    106104 
    107105        /** 
     
    129127                this.identityTaskHandlingStrategy = new TaskHandlingStrategy( 
    130128                                TaskEquality.IDENTICAL); 
    131                 numberseqs = new ArrayList<NumberSequence>(); 
    132129 
    133130        } 
     
    157154                SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 
    158155 
    159                 // Generate a substitution matrix between all occuring events. 
     156                // Generate a substitution matrix between all occurring events. 
    160157                Console.traceln(Level.INFO, "generating substitution matrix"); 
    161158                ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 
     
    167164                LinkedList<Match> matchseqs = new LinkedList<Match>(); 
    168165                PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 
    169                                 .generate(numberseqs, submat, 9); 
     166                                .generate(appData.getNumberSequences(), submat, 9); 
    170167 
    171168                // Retrieve all matches reached a specific threshold 
    172169                Console.traceln(Level.INFO, "retrieving significant sequence pieces"); 
    173                 for (int i = 0; i < numberseqs.size(); i++) { 
     170                for (int i = 0; i < appData.getNumberSequences().size(); i++) { 
    174171                        Console.traceln( 
    175172                                        Level.FINEST, 
    176173                                        "retrieving significant sequence pieces:  " 
    177                                                         + Math.round((float) i / (float) numberseqs.size() 
     174                                                        + Math.round((float) i / (float) appData.getNumberSequences().size() 
    178175                                                                        * 100) + "%"); 
    179                         for (int j = 0; j < numberseqs.size(); j++) { 
     176                        for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
    180177                                if (i != j) { 
    181178                                        matchseqs.addAll(alignments.get(i, j).getMatches()); 
     
    189186                // search each match in every other sequence 
    190187                for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 
    191                         int sequencecount = 0; 
    192                         int totalcount = 0; 
    193188                        Match pattern = it.next(); 
    194189 
     
    202197                                continue; 
    203198         
    204                         for (int j = 0; j < numberseqs.size(); j++) { 
    205                                 LinkedList<Integer> startpositions = numberseqs.get(j) 
     199                        for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
     200                                LinkedList<Integer> startpositions = appData.getNumberSequences().get(j) 
    206201                                                .containsPattern(pattern); 
    207202                                if (startpositions.size() > 0) { 
    208                                         sequencecount++; 
    209                                         totalcount += startpositions.size(); 
     203                                         
    210204                                        for (Iterator<Integer> jt = startpositions.iterator(); jt 
    211205                                                        .hasNext();) { 
     
    219213 
    220214                Console.traceln(Level.INFO, "sorting results"); 
    221                 // Sort results to get the most occuring results 
     215                // Sort results to get the most occurring results 
    222216                Comparator<Match> comparator = new Comparator<Match>() { 
    223217                        public int compare(Match m1, Match m2) { 
     
    229223                 
    230224 
    231                  
    232                  
    233                 // Harmonize matches: finding double matches and merge them 
     225                // TODO: Harmonize matches: finding double matches and merge them 
    234226                /* 
    235227                Console.traceln(Level.INFO, "harmonizing matches"); 
     
    241233                                if(i!=j) { 
    242234                                        if(matchseqs.get(i).equals(matchseqs.get(j))) { 
    243                                                 matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 
     235                                                //matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 
    244236                                                matchseqs.remove(j); 
    245237                                         
     
    258250                } 
    259251                Collections.sort(matchseqs, comparator); 
    260                 */  
    261          
    262                                          
    263                          
    264                  
    265                  
     252                */ 
    266253                 
    267254                 
     
    269256                for (int i = 0; i < matchseqs.size(); i++) { 
    270257                        // Every pattern consists of 2 sequences, therefore the minimum 
    271                         // occurences here is 2. 
    272                         // We just need the sequences also occuring in other sequences as 
     258                        // occurrences here is 2. 
     259                        // We just need the sequences also occurring in other sequences as 
    273260                        // well 
    274261                        if (matchseqs.get(i).occurenceCount() > 2) { 
    275                                 matchseqs.get(i).getFirstSequence().printSequence(); 
    276                                 matchseqs.get(i).getSecondSequence().printSequence(); 
    277                                 System.out.println("Found pattern " 
    278                                                 + matchseqs.get(i).occurenceCount() + " times"); 
     262                                 
     263                                ITask task = matchAsTask(appData,matchseqs.get(i)); 
     264                                System.out.println(task); 
     265                                //matchseqs.get(i).getFirstSequence().printSequence(); 
     266                                //matchseqs.get(i).getSecondSequence().printSequence(); 
     267                                //System.out.println("Found pattern " 
     268                                //              + matchseqs.get(i).occurenceCount() + " times"); 
    279269                                System.out.println(); 
    280270                        } 
     
    284274                alignments = null; 
    285275 
    286                 /* 
    287                  * do { 
    288                  *  
    289                  * // appData.getStopWatch().start("whole loop"); // 
    290                  * detectAndReplaceIterations(appData); 
    291                  *  
    292                  * // appData.getStopWatch().start("task replacement"); // 
    293                  * detectAndReplaceTasks(appData); // 
    294                  * appData.getStopWatch().stop("task replacement"); // 
    295                  * appData.getStopWatch().stop("whole loop"); 
    296                  *  
    297                  * // appData.getStopWatch().dumpStatistics(System.out); // 
    298                  * appData.getStopWatch().reset(); 
    299                  *  
    300                  * } while (appData.detectedAndReplacedTasks()); 
    301                  */ 
     276                do { 
     277                   
     278                  appData.getStopWatch().start("whole loop"); // 
     279                  detectAndReplaceIterations(appData); 
     280                  
     281                  appData.getStopWatch().start("task replacement"); // 
     282                  //detectAndReplaceTasks(appData); // 
     283                  appData.getStopWatch().stop("task replacement"); // 
     284                  appData.getStopWatch().stop("whole loop"); 
     285                   
     286                  appData.getStopWatch().dumpStatistics(System.out); // 
     287                  appData.getStopWatch().reset(); 
     288                   
     289                  } while (appData.detectedAndReplacedTasks()); 
     290                  
    302291 
    303292                Console.println("created " 
     
    316305        } 
    317306 
     307         
     308         
    318309        /** 
    319310         * <p> 
     
    344335                List<IUserSession> sessions = appData.getSessions(); 
    345336                int sessionNo = 0; 
    346                 numberseqs = new ArrayList<NumberSequence>(); 
    347337                for (IUserSession session : sessions) { 
    348338                        Console.traceln(Level.FINE, "handling " + (++sessionNo) + ". " 
     
    357347                                        uniqueTasks.addSymbol(taskInstance, taskInstance.getTask()); 
    358348                                        templist.getSequence()[i] = taskInstance.getTask().getId(); 
     349                 
    359350                                } else { 
    360351                                        taskBuilder.setTask(taskInstance, task); 
     
    362353                                        unifiedTasks++; 
    363354                                } 
    364                         } 
    365                         templist.setId(numberseqs.size()); 
    366                         numberseqs.add(templist); 
     355                                appData.getNumber2Task().put(templist.getSequence()[i], taskInstance.getTask()); 
     356                        } 
     357                        templist.setId(appData.getNumberSequences().size()); 
     358                        appData.getNumberSequences().add(templist); 
    367359                        comparator.clearBuffers(); 
    368360                } 
     
    505497        } 
    506498 
     499         
     500         ITask matchAsTask(RuleApplicationData appData,Match m) { 
     501                 
     502                ISequence sequence = taskFactory.createNewSequence(); 
     503                 
     504                int[] first = m.getFirstSequence().getSequence(); 
     505                int[] second = m.getSecondSequence().getSequence(); 
     506                System.out.println("Number2Task size: " +appData.getNumber2Task().size()); 
     507                 
     508                //Both sequences of a match are equally long 
     509                for(int i=0;i<m.getFirstSequence().size();i++) { 
     510                        System.out.println("First:" + first[i]); 
     511                        System.out.println("Second:" + second[i]); 
     512                        System.out.println(); 
     513                        //Two gaps aligned to each other: Have not seen it happening so far, just to handle it 
     514                        if(first[i]==-1 && second[i]==-1) { 
     515                                //TODO: Do nothing? 
     516                        } 
     517                        //Both events are equal, we can simply add the task referring to the number 
     518                        else if(first[i]==second[i]) { 
     519                                taskBuilder.addChild(sequence, appData.getNumber2Task().get(first[i])); 
     520                        } 
     521                        //We have a gap in the first sequence, we need to add the task of the second sequence as optional 
     522                        else if(first[i]==-1 && second[i]!=-1) { 
     523                                IOptional optional = taskFactory.createNewOptional(); 
     524                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(second[i])); 
     525                                taskBuilder.addChild(sequence,optional); 
     526                        } 
     527                        //We have a gap in the second sequence, we need to add the task of the first sequence as optional 
     528                        else if(first[i]!=-1 && second[i]==-1) { 
     529                                IOptional optional = taskFactory.createNewOptional(); 
     530                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(first[i])); 
     531                                taskBuilder.addChild(sequence,optional); 
     532                        } 
     533                        //Both tasks are unequal, we need to insert a selection here 
     534                        else { 
     535                                ISelection selection = taskFactory.createNewSelection(); 
     536                                taskBuilder.addChild(selection, appData.getNumber2Task().get(first[i])); 
     537                                taskBuilder.addChild(selection, appData.getNumber2Task().get(second[i])); 
     538                                taskBuilder.addChild(sequence,selection); 
     539                        } 
     540                } 
     541                        return sequence; 
     542                } 
     543         
     544         
    507545        /** 
    508546         * <p> 
     
    579617                appData.getStopWatch().start("detecting tasks"); 
    580618 
    581                 getSequencesOccuringMostOften(appData); 
     619                //getSequencesOccuringMostOften(appData); 
    582620 
    583621                appData.getStopWatch().stop("detecting tasks"); 
     
    587625 
    588626                appData.getStopWatch().stop("replacing tasks"); 
    589                 Console.traceln(Level.INFO, "detected and replaced " 
    590                                 + appData.getLastFoundTasks().size() + " tasks occuring " 
    591                                 + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
    592         } 
     627                 
     628                //Console.traceln(Level.INFO, "detected and replaced " 
     629                //              + appData.getLastFoundTasks().size() + " tasks occuring " 
     630                //              + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
     631        } 
     632 
     633         
     634 
    593635 
    594636        /** 
     
    597639         *            this rule 
    598640         */ 
    599         private void getSequencesOccuringMostOften(RuleApplicationData appData) { 
    600                 Console.traceln(Level.FINE, "determining most prominent tasks"); 
    601  
    602                 Tasks tasks; 
    603                 boolean createNewTrie = (appData.getLastTrie() == null) 
    604                                 || appData.detectedAndReplacedTasks(); // tree has changed 
    605  
    606                 do { 
    607                         if (createNewTrie) { 
    608                                 createNewTrie(appData); 
    609                         } 
    610  
    611                         MaxCountAndLongestTasksFinder finder = new MaxCountAndLongestTasksFinder(); 
    612                         appData.getLastTrie().process(finder); 
    613  
    614                         tasks = finder.getFoundTasks(); 
    615  
    616                         createNewTrie = false; 
    617  
    618                         for (List<ITaskInstance> task : tasks) { 
    619                                 if (task.size() >= appData.getTrainedSequenceLength()) { 
    620                                         // Trie must be recreated with a longer sequence length to 
    621                                         // be sure that 
    622                                         // the found sequences occurring most often are found in 
    623                                         // their whole length 
    624                                         appData.setTrainedSequenceLength(appData 
    625                                                         .getTrainedSequenceLength() + 1); 
    626                                         createNewTrie = true; 
    627                                         break; 
    628                                 } 
    629                         } 
    630                 } while (createNewTrie); 
    631  
    632                 // create a normal trie for comparison 
    633                 /* 
    634                  * System.out.println("creating test trie for comparison"); 
    635                  *  
    636                  * appData.getStopWatch().start("testtrie"); Trie<ITaskInstance> trie = 
    637                  * new Trie<ITaskInstance>(identityTaskComparator); 
    638                  *  
    639                  * for (IUserSession session : appData.getSessions()) { 
    640                  * trie.train(session.getExecutedTasks(), 
    641                  * appData.getTrainedSequenceLength()); } 
    642                  *  
    643                  * appData.getStopWatch().stop("testtrie"); 
    644                  *  
    645                  * MaxCountAndLongestTasksFinder finder = new 
    646                  * MaxCountAndLongestTasksFinder(); trie.process(finder); 
    647                  *  
    648                  * boolean allTasksEqual = finder.getFoundTasks().size() == 
    649                  * tasks.size(); 
    650                  *  
    651                  * allTasksEqual &= finder.getFoundTasks().occurrenceCount == 
    652                  * tasks.occurrenceCount; 
    653                  *  
    654                  * for (List<ITaskInstance> task1 : finder.getFoundTasks()) { boolean 
    655                  * foundTask = false; for (List<ITaskInstance> task2 : tasks) { boolean 
    656                  * tasksEqual = false; if (task1.size() == task2.size()) { tasksEqual = 
    657                  * true; for (int i = 0; i < task1.size(); i++) { if 
    658                  * (!identityTaskComparator.equals(task1.get(i).getTask(), 
    659                  * task2.get(i).getTask())) { tasksEqual = false; } } } 
    660                  *  
    661                  * if (tasksEqual) { foundTask = true; break; } } 
    662                  *  
    663                  * if (!foundTask) { System.out.println("different is " + task1); 
    664                  * allTasksEqual = false; break; } } 
    665                  *  
    666                  * if (!allTasksEqual) { System.out.println(finder.getFoundTasks()); 
    667                  * System.out.println(tasks); 
    668                  *  
    669                  * throw new 
    670                  * IllegalArgumentException("both tries calculated different subsequences" 
    671                  * ); } 
    672                  *  
    673                  * /*TrieStatisticsDumper dumper = new TrieStatisticsDumper(); 
    674                  * appData.getLastTrie().process(dumper); dumper.dumpCounters(); 
    675                  */ 
    676  
    677                 appData.setLastFoundTasks(tasks); 
    678  
    679                 Console.traceln(Level.FINE, "found " 
    680                                 + appData.getLastFoundTasks().size() + " tasks " + "occurring " 
    681                                 + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
    682         } 
    683  
    684         /** 
    685          * @param appData 
    686          *            the rule application data combining all data used for applying 
    687          *            this rule 
    688          */ 
    689         private void createNewTrie(RuleApplicationData appData) { 
    690                 Console.traceln( 
    691                                 Level.FINER, 
    692                                 "training trie with a maximum sequence length of " 
    693                                                 + appData.getTrainedSequenceLength()); 
    694  
    695                 appData.getStopWatch().start("training trie"); 
    696  
    697                 // we prepared the task instances to refer to unique tasks, if they are 
    698                 // treated 
    699                 // as equal. Therefore, we just compare the identity of the tasks of the 
    700                 // task 
    701                 // instances 
    702                 appData.setLastTrie(new TaskInstanceTrie(identityTaskHandlingStrategy)); 
    703  
    704                 appData.getLastTrie().trainSessions(appData.getSessions(), 
    705                                 appData.getTrainedSequenceLength()); 
    706  
    707                 appData.getStopWatch().stop("training trie"); 
    708         } 
    709  
    710         /** 
    711          * @param appData 
    712          *            the rule application data combining all data used for applying 
    713          *            this rule 
    714          */ 
    715641        private void replaceSequencesOccurringMostOften(RuleApplicationData appData) { 
    716642                appData.detectedAndReplacedTasks(false); 
    717643 
    718                 if ((appData.getLastFoundTasks().size() > 0) 
    719                                 && (appData.getLastFoundTasks().getOccurrenceCount() > 1)) { 
     644         
    720645                        Console.traceln(Level.FINER, "replacing tasks occurrences"); 
    721  
     646                        /* 
    722647                        for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 
    723648                                ISequence sequence = taskFactory.createNewSequence(); 
     
    746671                                } 
    747672                        } 
    748                 } 
    749  
    750         } 
     673                        */ 
     674        } 
     675 
    751676 
    752677        /** 
     
    880805        } 
    881806 
    882         /** 
    883          * @param trie 
    884          * @param object 
    885          * @return 
    886          */ 
    887         private int getSubListIndex(List<ITaskInstance> list, 
    888                         List<ITaskInstance> subList, int startIndex) { 
    889                 boolean matchFound; 
    890                 int result = -1; 
    891  
    892                 for (int i = startIndex; i <= list.size() - subList.size(); i++) { 
    893                         matchFound = true; 
    894  
    895                         for (int j = 0; j < subList.size(); j++) { 
    896                                 // we prepared the task instances to refer to unique tasks, if 
    897                                 // they are treated 
    898                                 // as equal. Therefore, we just compare the identity of the 
    899                                 // tasks of the task 
    900                                 // instances 
    901                                 if (list.get(i + j) != subList.get(j)) { 
    902                                         matchFound = false; 
    903                                         break; 
    904                                 } 
    905                         } 
    906  
    907                         if (matchFound) { 
    908                                 result = i; 
    909                                 break; 
    910                         } 
    911                 } 
    912  
    913                 return result; 
    914         } 
    915  
    916         /** 
    917          * @author Patrick Harms 
    918          */ 
    919         private class MaxCountAndLongestTasksFinder implements 
    920                         TrieProcessor<ITaskInstance> { 
    921  
    922                 /** 
    923          *  
    924          */ 
    925                 private int currentCount; 
    926  
    927                 /** 
    928          *  
    929          */ 
    930                 private List<List<ITaskInstance>> foundTasks = new LinkedList<List<ITaskInstance>>(); 
    931  
    932                 /** 
    933          * 
    934          */ 
    935                 public MaxCountAndLongestTasksFinder() { 
    936                         super(); 
    937                         this.currentCount = 0; 
    938                 } 
    939  
    940                 /* 
    941                  * (non-Javadoc) 
    942                  *  
    943                  * @see 
    944                  * de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util 
    945                  * .List, int) 
    946                  */ 
    947                 @Override 
    948                 public TrieProcessor.Result process(List<ITaskInstance> foundTask, 
    949                                 int count) { 
    950                         if (foundTask.size() < 2) { 
    951                                 // ignore single tasks 
    952                                 return TrieProcessor.Result.CONTINUE; 
    953                         } 
    954  
    955                         if (count < 2) { 
    956                                 // ignore singular occurrences 
    957                                 return TrieProcessor.Result.SKIP_NODE; 
    958                         } 
    959  
    960                         if (this.currentCount > count) { 
    961                                 // ignore this children of this task, as they may have only 
    962                                 // smaller counts than 
    963                                 // the already found tasks 
    964                                 return TrieProcessor.Result.SKIP_NODE; 
    965                         } 
    966  
    967                         if (this.currentCount < count) { 
    968                                 // the provided task occurs more often that all tasks found so 
    969                                 // far. 
    970                                 // clear all found tasks and use the new count as the one 
    971                                 // searched for 
    972                                 foundTasks.clear(); 
    973                                 this.currentCount = count; 
    974                         } 
    975  
    976                         if (this.currentCount == count) { 
    977                                 // the task is of interest. Sort it into the other found tasks 
    978                                 // so that 
    979                                 // the longest come first 
    980                                 boolean added = false; 
    981                                 for (int i = 0; i < foundTasks.size(); i++) { 
    982                                         if (foundTasks.get(i).size() < foundTask.size()) { 
    983                                                 // defensive copy 
    984                                                 foundTasks.add(i, new LinkedList<ITaskInstance>( 
    985                                                                 foundTask)); // defensive copy 
    986                                                 added = true; 
    987                                                 break; 
    988                                         } 
    989                                 } 
    990  
    991                                 if (!added) { 
    992                                         foundTasks.add(new LinkedList<ITaskInstance>(foundTask)); // defensive 
    993                                                                                                                                                                 // copy 
    994                                 } 
    995                         } 
    996  
    997                         return TrieProcessor.Result.CONTINUE; 
    998                 } 
    999  
    1000                 /** 
    1001                  * @return 
    1002                  */ 
    1003                 public Tasks getFoundTasks() { 
    1004                         removePermutationsOfShorterTasks(); 
    1005                         return new Tasks(currentCount, foundTasks); 
    1006                 } 
    1007  
    1008                 /** 
    1009          * 
    1010          */ 
    1011                 private void removePermutationsOfShorterTasks() { 
    1012                         // now iterate the sorted list and for each task remove all other 
    1013                         // tasks that are shorter 
    1014                         // (i.e. come later in the sorted list) and that represent a subpart 
    1015                         // of the task 
    1016                         for (int i = 0; i < foundTasks.size(); i++) { 
    1017                                 for (int j = i + 1; j < foundTasks.size();) { 
    1018                                         if (foundTasks.get(j).size() < foundTasks.get(i).size()) { 
    1019                                                 // found a task that is a potential subtask. Check for 
    1020                                                 // this and remove the 
    1021                                                 // subtask if needed 
    1022                                                 List<ITaskInstance> longTask = foundTasks.get(i); 
    1023                                                 List<ITaskInstance> shortTask = foundTasks.get(j); 
    1024  
    1025                                                 if (getSubListIndex(longTask, shortTask, 0) > -1) { 
    1026                                                         foundTasks.remove(j); 
    1027                                                 } else { 
    1028                                                         j++; 
    1029                                                 } 
    1030                                         } else { 
    1031                                                 j++; 
    1032                                         } 
    1033                                 } 
    1034                         } 
    1035                 } 
    1036  
    1037         } 
    1038  
    1039         // /** 
    1040         // * @author Patrick Harms 
    1041         // */ 
    1042         // private class TrieStatisticsDumper implements 
    1043         // TrieProcessor<ITaskInstance> { 
    1044         // 
    1045         // /** 
    1046         // * 
    1047         // */ 
    1048         // private Map<Integer, Integer> counters = new HashMap<Integer, Integer>(); 
    1049         // 
    1050         // /* (non-Javadoc) 
    1051         // * @see 
    1052         // de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util.List, 
    1053         // int) 
    1054         // */ 
    1055         // @Override 
    1056         // public TrieProcessor.Result process(List<ITaskInstance> subsequence, int 
    1057         // count) { 
    1058         // if (subsequence.size() == 1) { 
    1059         // Integer value = counters.get(count); 
    1060         // 
    1061         // if (value == null) { 
    1062         // value = 0; 
    1063         // } 
    1064         // 
    1065         // counters.put(count, value + 1); 
    1066         // 
    1067         // return TrieProcessor.Result.CONTINUE; 
    1068         // } 
    1069         // else { 
    1070         // // ignore singular occurrences 
    1071         // return TrieProcessor.Result.SKIP_NODE; 
    1072         // } 
    1073         // } 
    1074         // 
    1075         // /** 
    1076         // * @return 
    1077         // */ 
    1078         // public void dumpCounters() { 
    1079         // int dumpedCounters = 0; 
    1080         // 
    1081         // int count = 1; 
    1082         // while (dumpedCounters < counters.size()) { 
    1083         // Integer value = counters.get(count++); 
    1084         // if (value != null) { 
    1085         // System.out.println(value + " symbols occurred " + count + " times"); 
    1086         // dumpedCounters++; 
    1087         // } 
    1088         // } 
    1089         // } 
    1090         // 
    1091         // } 
    1092807 
    1093808        /** 
     
    1096811        private static class RuleApplicationData { 
    1097812 
     813                 
     814                private HashMap<Integer,ITask> number2task; 
     815                 
     816                 
     817                private ArrayList<NumberSequence> numberseqs; 
     818                 
    1098819                /** 
    1099820         *  
     
    1101822                private List<IUserSession> sessions; 
    1102823 
    1103                 /** 
    1104          *  
    1105          */ 
    1106                 private TaskInstanceTrie lastTrie; 
    1107  
    1108                 /** 
    1109                  * default and minimum trained sequence length is 3 
    1110                  */ 
    1111                 private int trainedSequenceLength = 3; 
    1112  
    1113                 /** 
    1114          *  
    1115          */ 
    1116                 private Tasks lastFoundTasks = new Tasks(Integer.MAX_VALUE, null); 
     824 
    1117825 
    1118826                /** 
     
    1124832         *  
    1125833         */ 
    1126                 private RuleApplicationResult result = new RuleApplicationResult(); 
     834                private RuleApplicationResult result; 
    1127835 
    1128836                /** 
    1129837         *  
    1130838         */ 
    1131                 private StopWatch stopWatch = new StopWatch(); 
     839                private StopWatch stopWatch; 
    1132840 
    1133841                /** 
     
    1136844                private RuleApplicationData(List<IUserSession> sessions) { 
    1137845                        this.sessions = sessions; 
     846                        numberseqs = new ArrayList<NumberSequence>(); 
     847                        number2task = new HashMap<Integer,ITask>(); 
     848                        stopWatch= new StopWatch(); 
     849                        result =  new RuleApplicationResult(); 
    1138850                } 
    1139851 
     
    1145857                } 
    1146858 
    1147                 /** 
    1148                  * @param lastTrie 
    1149                  *            the lastTrie to set 
    1150                  */ 
    1151                 private void setLastTrie(TaskInstanceTrie lastTrie) { 
    1152                         this.lastTrie = lastTrie; 
    1153                 } 
    1154  
    1155                 /** 
    1156                  * @return the lastTrie 
    1157                  */ 
    1158                 private TaskInstanceTrie getLastTrie() { 
    1159                         return lastTrie; 
    1160                 } 
    1161  
    1162                 /** 
    1163                  * @param trainedSequenceLength 
    1164                  *            the trainedSequenceLength to set 
    1165                  */ 
    1166                 private void setTrainedSequenceLength(int trainedSequenceLength) { 
    1167                         this.trainedSequenceLength = trainedSequenceLength; 
    1168                 } 
    1169  
    1170                 /** 
    1171                  * @return the trainedSequenceLength 
    1172                  */ 
    1173                 private int getTrainedSequenceLength() { 
    1174                         return trainedSequenceLength; 
    1175                 } 
    1176  
    1177                 /** 
    1178                  * @param lastFoundSequences 
    1179                  *            the lastFoundSequences to set 
    1180                  */ 
    1181                 private void setLastFoundTasks(Tasks lastFoundSequences) { 
    1182                         this.lastFoundTasks = lastFoundSequences; 
    1183                 } 
    1184  
    1185                 /** 
    1186                  * @return the lastFoundSequences 
    1187                  */ 
    1188                 private Tasks getLastFoundTasks() { 
    1189                         return lastFoundTasks; 
    1190                 } 
     859                 
     860                private ArrayList<NumberSequence> getNumberSequences() { 
     861                        return numberseqs; 
     862                } 
     863 
     864         
    1191865 
    1192866                /** 
     
    1218892                } 
    1219893 
    1220         } 
    1221  
    1222         /** 
    1223          * @author Patrick Harms 
    1224          */ 
    1225         private static class Tasks implements Iterable<List<ITaskInstance>> { 
    1226  
    1227                 /** 
    1228          *  
    1229          */ 
    1230                 private int occurrenceCount; 
    1231  
    1232                 /** 
    1233          *  
    1234          */ 
    1235                 private List<List<ITaskInstance>> sequences; 
    1236  
    1237                 /** 
    1238                  * @param occurrenceCount 
    1239                  * @param sequences 
    1240                  */ 
    1241                 private Tasks(int occurrenceCount, List<List<ITaskInstance>> sequences) { 
    1242                         super(); 
    1243                         this.occurrenceCount = occurrenceCount; 
    1244                         this.sequences = sequences; 
    1245                 } 
    1246  
    1247                 /** 
    1248                  * @return 
    1249                  */ 
    1250                 private int getOccurrenceCount() { 
    1251                         return occurrenceCount; 
    1252                 } 
    1253  
    1254                 /** 
    1255                  * @return 
    1256                  */ 
    1257                 private int size() { 
    1258                         return this.sequences.size(); 
    1259                 } 
    1260  
    1261                 /** 
    1262          *  
    1263          */ 
    1264  
    1265                 /* 
    1266                  * (non-Javadoc) 
    1267                  *  
    1268                  * @see java.lang.Iterable#iterator() 
    1269                  */ 
    1270                 @Override 
    1271                 public Iterator<List<ITaskInstance>> iterator() { 
    1272                         return this.sequences.iterator(); 
    1273                 } 
    1274  
    1275                 /* 
    1276                  * (non-Javadoc) 
    1277                  *  
    1278                  * @see java.lang.Object#toString() 
    1279                  */ 
    1280                 @Override 
    1281                 public String toString() { 
    1282                         StringBuffer result = new StringBuffer(); 
    1283                         result.append(this.occurrenceCount); 
    1284                         result.append(" occurrences:\n"); 
    1285  
    1286                         for (List<ITaskInstance> task : sequences) { 
    1287                                 result.append(task); 
    1288                                 result.append("\n"); 
    1289                         } 
    1290  
    1291                         return result.toString(); 
    1292                 } 
    1293  
    1294         } 
    1295  
    1296         // methods for internal testing 
    1297         // private void checkMatchingOfSessions(List<List<Event>> flattenedSessions, 
    1298         // List<IUserSession> sessions, 
    1299         // String when) 
    1300         // { 
    1301         // List<List<Event>> currentFlattenedSessions = flattenSessions(sessions); 
    1302         // if (flattenedSessions.size() != currentFlattenedSessions.size()) { 
    1303         // System.out.println("################## number of sessions changed after " 
    1304         // + when); 
    1305         // } 
    1306         // else { 
    1307         // for (int i = 0; i < flattenedSessions.size(); i++) { 
    1308         // List<Event> expected = flattenedSessions.get(i); 
    1309         // List<Event> current = currentFlattenedSessions.get(i); 
    1310         // 
    1311         // if (expected.size() != current.size()) { 
    1312         // System.out.println 
    1313         // ("################## length of session " + i + " changed after " + when); 
    1314         // } 
    1315         // else { 
    1316         // for (int j = 0; j < expected.size(); j++) { 
    1317         // if (!expected.get(j).equals(current.get(j))) { 
    1318         // System.out.println("################## event " + j + " of session " + 
    1319         // i + " changed after " + when); 
    1320         // } 
    1321         // } 
    1322         // } 
    1323         // } 
    1324         // } 
    1325         // } 
    1326         // 
    1327         // private List<List<Event>> flattenSessions(List<IUserSession> sessions) { 
    1328         // List<List<Event>> flattenedSessions = new ArrayList<List<Event>>(); 
    1329         // for (IUserSession session : sessions) { 
    1330         // List<Event> flattenedUserSession = new ArrayList<Event>(); 
    1331         // flatten(session, flattenedUserSession); 
    1332         // flattenedSessions.add(flattenedUserSession); 
    1333         // } 
    1334         // 
    1335         // return flattenedSessions; 
    1336         // } 
    1337         // 
    1338         // private void flatten(IUserSession iUserSession, List<Event> 
    1339         // flattenedUserSession) { 
    1340         // for (ITaskInstance instance : iUserSession) { 
    1341         // flatten(instance, flattenedUserSession); 
    1342         // } 
    1343         // } 
    1344         // 
    1345         // private void flatten(ITaskInstance instance, List<Event> 
    1346         // flattenedUserSession) { 
    1347         // if (instance instanceof ITaskInstanceList) { 
    1348         // for (ITaskInstance child : (ITaskInstanceList) instance) { 
    1349         // flatten(child, flattenedUserSession); 
    1350         // } 
    1351         // } 
    1352         // else if (instance instanceof ISelectionInstance) { 
    1353         // flatten(((ISelectionInstance) instance).getChild(), 
    1354         // flattenedUserSession); 
    1355         // } 
    1356         // else if (instance instanceof IOptionalInstance) { 
    1357         // flatten(((IOptionalInstance) instance).getChild(), flattenedUserSession); 
    1358         // } 
    1359         // else if (instance instanceof IEventTaskInstance) { 
    1360         // flattenedUserSession.add(((IEventTaskInstance) instance).getEvent()); 
    1361         // } 
    1362         // } 
     894                private HashMap<Integer,ITask> getNumber2Task() { 
     895                        return number2task; 
     896                } 
     897 
     898        } 
     899 
     900         
     901 
    1363902 
    1364903} 
Note: See TracChangeset for help on using the changeset viewer.