Changeset 1630
- Timestamp:
- 07/30/14 17:06:47 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/GenerateTask.java
r1620 r1630 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; 2 2 3 /* 3 4 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 5 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 4 6 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 5 7 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 6 8 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 7 9 */ 8 10 public class GenerateTask { 9 11 10 12 11 private ITaskFactory taskFactory;13 //private ITaskFactory taskFactory; 12 14 /** 13 15 * <p> … … 16 18 * </p> 17 19 */ 20 /* 18 21 private ITaskBuilder taskBuilder; 19 22 … … 30 33 } 31 34 35 void optional() { 36 IOptional optional = taskFactory.createNewOptional(); 37 //taskBuilder.setChild(optional, child); 38 39 } 32 40 41 */ 33 42 34 43 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java
r1621 r1630 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator;5 4 import java.util.LinkedList; 5 6 6 7 7 8 public class Match { … … 64 65 occurences.addAll(occ); 65 66 } 67 68 66 69 67 70 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java
r1620 r1630 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator;5 4 import java.util.logging.Level; 6 5 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java
r1620 r1630 56 56 57 57 this.numberseqs = numberseqs; 58 this.alignments = alignments;59 58 this.submat = submat; 60 59 init(alignments.getDistanceMatrix()); … … 82 81 // 83 82 private ArrayList<NumberSequence> numberseqs; 84 private PairwiseAlignmentStorage alignments;85 83 private ObjectDistanceSubstitionMatrix submat; 86 84 private int numClusters; -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1621 r1630 27 27 import java.util.logging.Level; 28 28 29 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory;30 29 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 31 30 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; … … 34 33 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage; 35 34 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 36 import de.ugoe.cs.autoquest.tasktrees.alignment.pal.tree.UPGMAAligningTree;37 35 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 38 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 39 37 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 38 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 40 39 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 41 40 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; … … 49 48 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 50 49 import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; 51 import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor;52 50 import de.ugoe.cs.util.StopWatch; 53 51 import de.ugoe.cs.util.console.Console; … … 97 95 * <p> 98 96 * the task handling strategy to be used for comparing tasks during 99 * iteration detection an trie generation,i.e., after the tasks are97 * iteration detection i.e., after the tasks are 100 98 * harmonized 101 99 * </p> 102 100 */ 103 private TaskHandlingStrategy identityTaskHandlingStrategy; ;104 105 private ArrayList<NumberSequence> numberseqs; 101 private TaskHandlingStrategy identityTaskHandlingStrategy; 102 103 106 104 107 105 /** … … 129 127 this.identityTaskHandlingStrategy = new TaskHandlingStrategy( 130 128 TaskEquality.IDENTICAL); 131 numberseqs = new ArrayList<NumberSequence>();132 129 133 130 } … … 157 154 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 158 155 159 // Generate a substitution matrix between all occur ing events.156 // Generate a substitution matrix between all occurring events. 160 157 Console.traceln(Level.INFO, "generating substitution matrix"); 161 158 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( … … 167 164 LinkedList<Match> matchseqs = new LinkedList<Match>(); 168 165 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 169 .generate( numberseqs, submat, 9);166 .generate(appData.getNumberSequences(), submat, 9); 170 167 171 168 // Retrieve all matches reached a specific threshold 172 169 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++) { 174 171 Console.traceln( 175 172 Level.FINEST, 176 173 "retrieving significant sequence pieces: " 177 + Math.round((float) i / (float) numberseqs.size()174 + Math.round((float) i / (float) appData.getNumberSequences().size() 178 175 * 100) + "%"); 179 for (int j = 0; j < numberseqs.size(); j++) {176 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 180 177 if (i != j) { 181 178 matchseqs.addAll(alignments.get(i, j).getMatches()); … … 189 186 // search each match in every other sequence 190 187 for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 191 int sequencecount = 0;192 int totalcount = 0;193 188 Match pattern = it.next(); 194 189 … … 202 197 continue; 203 198 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) 206 201 .containsPattern(pattern); 207 202 if (startpositions.size() > 0) { 208 sequencecount++; 209 totalcount += startpositions.size(); 203 210 204 for (Iterator<Integer> jt = startpositions.iterator(); jt 211 205 .hasNext();) { … … 219 213 220 214 Console.traceln(Level.INFO, "sorting results"); 221 // Sort results to get the most occur ing results215 // Sort results to get the most occurring results 222 216 Comparator<Match> comparator = new Comparator<Match>() { 223 217 public int compare(Match m1, Match m2) { … … 229 223 230 224 231 232 233 // Harmonize matches: finding double matches and merge them 225 // TODO: Harmonize matches: finding double matches and merge them 234 226 /* 235 227 Console.traceln(Level.INFO, "harmonizing matches"); … … 241 233 if(i!=j) { 242 234 if(matchseqs.get(i).equals(matchseqs.get(j))) { 243 matchseqs.get(i).addOccurencesOf(matchseqs.get(j));235 //matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 244 236 matchseqs.remove(j); 245 237 … … 258 250 } 259 251 Collections.sort(matchseqs, comparator); 260 */ 261 262 263 264 265 252 */ 266 253 267 254 … … 269 256 for (int i = 0; i < matchseqs.size(); i++) { 270 257 // Every pattern consists of 2 sequences, therefore the minimum 271 // occur ences here is 2.272 // We just need the sequences also occur ing in other sequences as258 // occurrences here is 2. 259 // We just need the sequences also occurring in other sequences as 273 260 // well 274 261 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"); 279 269 System.out.println(); 280 270 } … … 284 274 alignments = null; 285 275 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 302 291 303 292 Console.println("created " … … 316 305 } 317 306 307 308 318 309 /** 319 310 * <p> … … 344 335 List<IUserSession> sessions = appData.getSessions(); 345 336 int sessionNo = 0; 346 numberseqs = new ArrayList<NumberSequence>();347 337 for (IUserSession session : sessions) { 348 338 Console.traceln(Level.FINE, "handling " + (++sessionNo) + ". " … … 357 347 uniqueTasks.addSymbol(taskInstance, taskInstance.getTask()); 358 348 templist.getSequence()[i] = taskInstance.getTask().getId(); 349 359 350 } else { 360 351 taskBuilder.setTask(taskInstance, task); … … 362 353 unifiedTasks++; 363 354 } 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); 367 359 comparator.clearBuffers(); 368 360 } … … 505 497 } 506 498 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 507 545 /** 508 546 * <p> … … 579 617 appData.getStopWatch().start("detecting tasks"); 580 618 581 getSequencesOccuringMostOften(appData);619 //getSequencesOccuringMostOften(appData); 582 620 583 621 appData.getStopWatch().stop("detecting tasks"); … … 587 625 588 626 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 593 635 594 636 /** … … 597 639 * this rule 598 640 */ 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 changed605 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 to621 // be sure that622 // the found sequences occurring most often are found in623 // their whole length624 appData.setTrainedSequenceLength(appData625 .getTrainedSequenceLength() + 1);626 createNewTrie = true;627 break;628 }629 }630 } while (createNewTrie);631 632 // create a normal trie for comparison633 /*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 = new646 * 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()) { boolean655 * foundTask = false; for (List<ITaskInstance> task2 : tasks) { boolean656 * tasksEqual = false; if (task1.size() == task2.size()) { tasksEqual =657 * true; for (int i = 0; i < task1.size(); i++) { if658 * (!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 new670 * 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 appData686 * the rule application data combining all data used for applying687 * this rule688 */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 are698 // treated699 // as equal. Therefore, we just compare the identity of the tasks of the700 // task701 // instances702 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 appData712 * the rule application data combining all data used for applying713 * this rule714 */715 641 private void replaceSequencesOccurringMostOften(RuleApplicationData appData) { 716 642 appData.detectedAndReplacedTasks(false); 717 643 718 if ((appData.getLastFoundTasks().size() > 0) 719 && (appData.getLastFoundTasks().getOccurrenceCount() > 1)) { 644 720 645 Console.traceln(Level.FINER, "replacing tasks occurrences"); 721 646 /* 722 647 for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 723 648 ISequence sequence = taskFactory.createNewSequence(); … … 746 671 } 747 672 } 748 }749 750 } 673 */ 674 } 675 751 676 752 677 /** … … 880 805 } 881 806 882 /**883 * @param trie884 * @param object885 * @return886 */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, if897 // they are treated898 // as equal. Therefore, we just compare the identity of the899 // tasks of the task900 // instances901 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 Harms918 */919 private class MaxCountAndLongestTasksFinder implements920 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 * @see944 * de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util945 * .List, int)946 */947 @Override948 public TrieProcessor.Result process(List<ITaskInstance> foundTask,949 int count) {950 if (foundTask.size() < 2) {951 // ignore single tasks952 return TrieProcessor.Result.CONTINUE;953 }954 955 if (count < 2) {956 // ignore singular occurrences957 return TrieProcessor.Result.SKIP_NODE;958 }959 960 if (this.currentCount > count) {961 // ignore this children of this task, as they may have only962 // smaller counts than963 // the already found tasks964 return TrieProcessor.Result.SKIP_NODE;965 }966 967 if (this.currentCount < count) {968 // the provided task occurs more often that all tasks found so969 // far.970 // clear all found tasks and use the new count as the one971 // searched for972 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 tasks978 // so that979 // the longest come first980 boolean added = false;981 for (int i = 0; i < foundTasks.size(); i++) {982 if (foundTasks.get(i).size() < foundTask.size()) {983 // defensive copy984 foundTasks.add(i, new LinkedList<ITaskInstance>(985 foundTask)); // defensive copy986 added = true;987 break;988 }989 }990 991 if (!added) {992 foundTasks.add(new LinkedList<ITaskInstance>(foundTask)); // defensive993 // copy994 }995 }996 997 return TrieProcessor.Result.CONTINUE;998 }999 1000 /**1001 * @return1002 */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 other1013 // tasks that are shorter1014 // (i.e. come later in the sorted list) and that represent a subpart1015 // of the task1016 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 for1020 // this and remove the1021 // subtask if needed1022 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 Harms1041 // */1042 // private class TrieStatisticsDumper implements1043 // TrieProcessor<ITaskInstance> {1044 //1045 // /**1046 // *1047 // */1048 // private Map<Integer, Integer> counters = new HashMap<Integer, Integer>();1049 //1050 // /* (non-Javadoc)1051 // * @see1052 // de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util.List,1053 // int)1054 // */1055 // @Override1056 // public TrieProcessor.Result process(List<ITaskInstance> subsequence, int1057 // 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 occurrences1071 // return TrieProcessor.Result.SKIP_NODE;1072 // }1073 // }1074 //1075 // /**1076 // * @return1077 // */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 // }1092 807 1093 808 /** … … 1096 811 private static class RuleApplicationData { 1097 812 813 814 private HashMap<Integer,ITask> number2task; 815 816 817 private ArrayList<NumberSequence> numberseqs; 818 1098 819 /** 1099 820 * … … 1101 822 private List<IUserSession> sessions; 1102 823 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 1117 825 1118 826 /** … … 1124 832 * 1125 833 */ 1126 private RuleApplicationResult result = new RuleApplicationResult();834 private RuleApplicationResult result; 1127 835 1128 836 /** 1129 837 * 1130 838 */ 1131 private StopWatch stopWatch = new StopWatch();839 private StopWatch stopWatch; 1132 840 1133 841 /** … … 1136 844 private RuleApplicationData(List<IUserSession> sessions) { 1137 845 this.sessions = sessions; 846 numberseqs = new ArrayList<NumberSequence>(); 847 number2task = new HashMap<Integer,ITask>(); 848 stopWatch= new StopWatch(); 849 result = new RuleApplicationResult(); 1138 850 } 1139 851 … … 1145 857 } 1146 858 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 1191 865 1192 866 /** … … 1218 892 } 1219 893 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 1363 902 1364 903 }
Note: See TracChangeset
for help on using the changeset viewer.