- Timestamp:
- 09/11/14 14:03:20 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
r1734 r1738 28 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 29 29 30 31 30 /** 32 31 * <p> 33 32 * provides some convenience methods for rule application 34 * </p>. 33 * </p> 34 * . 35 35 * 36 * @author Patrick Harms 36 * @author Patrick Harms, Ralph Krimmel 37 37 */ 38 38 class RuleUtils { … … 42 42 * replaces a sub sequence for a specified range of elements in the provided 43 43 * task instances list by a sub task instance 44 * </p>. 45 * 46 * @param parent the list of which the range shall be replaced 47 * @param startIndex the start index of the range 48 * @param endIndex the end index of the range (inclusive) 49 * @param model the task model (required for instantiating the sub sequence) 50 * @param taskFactory the task factory used for instantiating the sub sequence 51 * @param taskBuilder the task builder to perform changes in the task structure 44 * </p> 45 * . 46 * 47 * @param parent 48 * the list of which the range shall be replaced 49 * @param startIndex 50 * the start index of the range 51 * @param endIndex 52 * the end index of the range (inclusive) 53 * @param model 54 * the task model (required for instantiating the sub sequence) 55 * @param taskFactory 56 * the task factory used for instantiating the sub sequence 57 * @param taskBuilder 58 * the task builder to perform changes in the task structure 52 59 * @return the replacement for the range 53 60 */ … … 57 64 final ISequenceInstance subsequence = taskFactory 58 65 .createNewTaskInstance(model); 59 60 61 // TODO: This is dirty, return this in addition with the sequence instance instead 66 @SuppressWarnings("unused") 67 int modelid = model.getId(); 68 if(modelid == 5412) { 69 System.out.println("Printing session: "); 70 for (int i = 0; i < parent.size();i++) { 71 System.out.println(parent.get(i)); 72 } 73 System.out.println("startIndex: " + startIndex + " endIndex: " + endIndex + "\n"); 74 System.out.println("Printing model: "); 75 for(int i = 0; i < ((ISequence)model).getChildren().size();i++) { 76 System.out.println((ISequence)model.getChildren().get(i)); 77 } 78 79 } 80 // TODO: This is dirty, return this in addition with the sequence 81 // instance instead 62 82 missedOptionals = 0; 63 83 int modelindex = 0; … … 89 109 continue; 90 110 } 91 } else if (tempTask.getType() == "selection") { 92 final ISelectionInstance selection = taskFactory 93 .createNewTaskInstance((ISelection) tempTask); 111 } else if (tempTask instanceof ISelection) { 112 final ISelectionInstance selection = taskFactory.createNewTaskInstance((ISelection) tempTask); 94 113 final ISelection tmpSel = (ISelection) tempTask; 95 if ((tmpSel.getChildren().get(0).getType() == "sequence")96 && (tmpSel.getChildren().get(1).getType() == "sequence")) {114 //Check if the selection has 2 sequences as children 115 if ((tmpSel.getChildren().get(0) instanceof ISequence) && (tmpSel.getChildren().get(1) instanceof ISequence)) { 97 116 ISequenceInstance selseq = null; 98 // The selection I create can just have 2 children 99 if (parent.get(startIndex).getTask().getId() == ((ISequence) tmpSel 100 .getChildren().get(0)).getChildren().get(0).getId()) { 101 selseq = taskFactory 102 .createNewTaskInstance((ISequence) tmpSel 103 .getChildren().get(0)); 104 } else if (parent.get(startIndex).getTask().getId() == ((ISequence) tmpSel 105 .getChildren().get(1)).getChildren().get(0).getId()) { 106 selseq = taskFactory 107 .createNewTaskInstance((ISequence) tmpSel 108 .getChildren().get(1)); 109 } else if ((parent.get(startIndex).getTask().getId() == tmpSel 110 .getChildren().get(0).getId()) 111 || (parent.get(startIndex).getTask().getId() == tmpSel 112 .getChildren().get(1).getId())) { 117 // The selection I create can just have 2 children, we need to check here, to which sequence of the model this occurence belongs 118 //This if checks of the occurrence is equal to the first element of the first sequence in the model 119 if (parent.get(startIndex).getTask().equals(((ISequence) tmpSel.getChildren().get(0)).getChildren().get(0))) { 120 selseq = taskFactory.createNewTaskInstance((ISequence) tmpSel.getChildren().get(0)); 121 //This if checks of the occurrence is equal to the first element of the second sequence in the model 122 } else if (parent.get(startIndex).getTask().equals(((ISequence) tmpSel.getChildren().get(1)).getChildren().get(0))) { 123 selseq = taskFactory.createNewTaskInstance((ISequence) tmpSel.getChildren().get(1)); 124 //If the occurence is already a sequence we don't need to do anything, the next iteration will detect this as a sequence and add it 125 } else if ((parent.get(startIndex).getTask().equals(tmpSel.getChildren().get(0).getId())) 126 || (parent.get(startIndex).getTask().equals(tmpSel.getChildren().get(1).getId()))) { 127 //taskBuilder.setChild(selection, parent.get(startIndex)); 128 //taskBuilder.addChild(subsequence, selection); 129 //taskBuilder.removeTaskInstance(parent, startIndex); 130 //modelindex++; 113 131 continue; 132 114 133 } 115 116 for (int k = 0; k < selseq.getSequence().getChildren() 117 .size(); k++) { 134 //TODO: Sometimes nullpointer exception here :( 135 for (int k = 0; k < ((ISequence)tmpSel.getChildren().get(0)).getChildren().size(); k++) { 118 136 taskBuilder.addChild(selseq, parent.get(startIndex)); 119 137 taskBuilder.removeTaskInstance(parent, startIndex); … … 124 142 modelindex++; 125 143 continue; 144 //It is just a plain selection 126 145 } else { 127 146 taskBuilder.setChild(selection, parent.get(startIndex)); … … 140 159 141 160 taskBuilder.addTaskInstance(parent, startIndex, subsequence); 161 142 162 143 163 return subsequence; … … 147 167 * <p> 148 168 * returns the next available id (uses the id counter) 149 * </p>. 169 * </p> 170 * . 150 171 * 151 172 * @return the next available id … … 192 213 * Prints the progress percentage. 193 214 * 194 * @param message the message 195 * @param count the count 196 * @param size the size 215 * @param message 216 * the message 217 * @param count 218 * the count 219 * @param size 220 * the size 197 221 */ 198 222 static void printProgressPercentage(String message, int count, int size) { … … 202 226 // Thread.currentThread().getName() + ": " + Math.round((float) 203 227 // count/size*100))+ "%"); 204 System.out.println(message + " in thread"205 206 228 // System.out.println(message + " in thread" 229 // + Thread.currentThread().getName() + ": " 230 // + Math.round(((float) count / size) * 100) + "%"); 207 231 } 208 232 } else { … … 210 234 // Thread.currentThread().getName() + ": " +Math.round((float) 211 235 // count/size*100))+ "%"); 212 System.out.println(message + " in thread"213 214 236 // System.out.println(message + " in thread" 237 // + Thread.currentThread().getName() + ": " 238 // + Math.round(((float) count / size) * 100) + "%"); 215 239 216 240 } … … 230 254 * <p> 231 255 * prevent instantiation 232 * </p>. 256 * </p> 257 * . 233 258 */ 234 259 private RuleUtils() { -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1735 r1738 54 54 import de.ugoe.cs.util.console.Console; 55 55 56 57 56 /** 58 57 * <p> … … 60 59 * of recorded user sessions. For this, it first harmonizes all tasks. This 61 60 * eases later comparison. Then it searches the sessions for iterations and 62 * replaces them accordingly. Then it searches for sub sequences using alignment algorithms63 * For each found sub sequence, it replaces64 * the occurrences by creating appropriate {@link ISequence}s. Afterwards, again65 * searches for iterations and then again for sub sequences until no more66 * replacements aredone.61 * replaces them accordingly. Then it searches for sub sequences using alignment 62 * algorithms For each found sub sequence, it replaces the occurrences by 63 * creating appropriate {@link ISequence}s. Afterwards, again searches for 64 * iterations and then again for sub sequences until no more replacements are 65 * done. 67 66 * </p> 68 67 * <p> … … 73 72 public class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 74 73 75 76 74 /** 77 75 * The Class RuleApplicationData. … … 82 80 private static final long serialVersionUID = -7559657686755522960L; 83 81 84 /** The number2task HashMap. Since we align the tasks just by their integer id, 85 * we need this to convert them back to Tasks again*/ 82 /** 83 * The number2task HashMap. Since we align the tasks just by their 84 * integer id, we need this to convert them back to Tasks again 85 */ 86 86 private final HashMap<Integer, ITask> number2task; 87 87 88 89 /** The unique tasks, keeps track about all unique tasks 90 * TODO: We Actually just need number2task here, this structure can be 91 * removed in the future.*/ 88 /** 89 * The unique tasks, keeps track about all unique tasks TODO: We 90 * Actually just need number2task here, this structure can be removed in 91 * the future. 92 */ 92 93 private final HashSet<ITask> uniqueTasks; 93 94 94 /** The substitution matrix used by the alignment algorithm to be able to compare 95 * distances of tasks */ 95 /** 96 * The substitution matrix used by the alignment algorithm to be able to 97 * compare distances of tasks 98 */ 96 99 private final ObjectDistanceSubstitionMatrix submat; 97 100 98 /** HashMap for keeping track in which sequence which replacement has been performed. 99 * Neccessary for updating the indices of other occurrences accordingly */ 101 /** 102 * HashMap for keeping track in which sequence which replacement has 103 * been performed. Neccessary for updating the indices of other 104 * occurrences accordingly 105 */ 100 106 private HashMap<Integer, List<MatchOccurence>> replacedOccurences; 101 107 … … 103 109 private LinkedList<Match> matchseqs; 104 110 105 /** The generated NumberSequences. 106 * This is the integer representation of the user sessions */ 111 /** 112 * The generated NumberSequences. This is the integer representation of 113 * the user sessions 114 */ 107 115 private ArrayList<NumberSequence> numberseqs; 108 116 … … 125 133 * Instantiates a new rule application data. 126 134 * 127 * @param sessions The user sessions 135 * @param sessions 136 * The user sessions 128 137 */ 129 138 private RuleApplicationData(List<IUserSession> sessions) { … … 241 250 * New task created. 242 251 * 243 * @param task the task 252 * @param task 253 * the task 244 254 */ 245 255 private void newTaskCreated(ITask task) { … … 259 269 * Sets the number sequences. 260 270 * 261 * @param numberseqs the new number sequences 271 * @param numberseqs 272 * the new number sequences 262 273 */ 263 274 private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { … … 268 279 * Sets the replaced occurences. 269 280 * 270 * @param replacedOccurences the replaced occurences 281 * @param replacedOccurences 282 * the replaced occurences 271 283 */ 272 284 public void setReplacedOccurences( … … 291 303 private int iteration = 0; 292 304 293 /** <p> the task factory to be used for creating substructures for the temporal relationships identified during rul application </p>. */ 305 /** 306 * <p> 307 * the task factory to be used for creating substructures for the temporal 308 * relationships identified during rul application 309 * </p> 310 * . 311 */ 294 312 private final ITaskFactory taskFactory; 295 313 296 /** <p> the task builder to be used for creating substructures for the temporal relationships identified during rule application </p>. */ 314 /** 315 * <p> 316 * the task builder to be used for creating substructures for the temporal 317 * relationships identified during rule application 318 * </p> 319 * . 320 */ 297 321 private final ITaskBuilder taskBuilder; 298 322 … … 339 363 public RuleApplicationResult apply(List<IUserSession> sessions) { 340 364 final RuleApplicationData appData = new RuleApplicationData(sessions); 341 365 342 366 harmonizeEventTaskInstancesModel(appData); 343 344 367 345 368 Console.traceln(Level.INFO, "generating substitution matrix from " … … 362 385 appData.getStopWatch().stop("whole loop"); 363 386 appData.getStopWatch().dumpStatistics(System.out); 387 new TaskTreeValidator().validate(appData.getSessions()); 364 388 appData.getStopWatch().reset(); 365 389 … … 384 408 * Creates the number sequences. 385 409 * 386 * @param appData the app data 410 * @param appData 411 * the app data 387 412 * @return the array list 388 413 */ … … 438 463 * Detect and replace tasks. 439 464 * 440 * @param appData the rule application data combining all data used for applying 465 * @param appData 466 * the rule application data combining all data used for applying 441 467 * this rule 442 468 */ … … 451 477 // appData.setMatchseqs(generatePairwiseAlignments(appData)); 452 478 generatePairwiseAlignments(appData); 479 Console.traceln(Level.FINE, "Found " + appData.getMatchseqs().size() 480 + " results"); 453 481 454 482 // Searching each match in all other sessions, counting its occurences … … 475 503 } 476 504 477 478 505 /** 479 506 * Generate pairwise alignments. 480 507 * 481 * @param appData the app data 508 * @param appData 509 * the app data 482 510 */ 483 511 private void generatePairwiseAlignments(RuleApplicationData appData) { … … 496 524 final int interval = numberSeqSize / newThreads; 497 525 int rest = numberSeqSize % newThreads; 498 499 for (int i = 0; i < (numberSeqSize - interval); i += interval) {526 Console.traceln(Level.FINE, "Interval: " + interval + " Rest: " + rest); 527 for (int i = 0; i <= (numberSeqSize - interval); i += interval) { 500 528 int offset = 0; 501 529 if (rest != 0) { … … 503 531 rest--; 504 532 } 533 505 534 final int from = i; 506 final int to = i + interval + offset; 507 System.out.println("Creating thread for sessions " + from 508 + " till " + to); 535 final int to = i + interval+offset-1; 536 Console.traceln(Level.FINE, "Aligning: Creating thread for sessions " + from + " till " + to); 509 537 final ParallelPairwiseAligner aligner = new ParallelPairwiseAligner( 510 538 appData, from, to); 511 539 executor.execute(aligner); 540 i+=offset; 512 541 } 513 542 executor.shutdown(); … … 578 607 * <p> 579 608 * TODO clarify why this is done (in fact, ask Patrick Harms) 580 * </p>. 609 * </p> 610 * . 581 611 * 582 * @param iteration the iteration 583 * @param iterationInstances the iteration instances 612 * @param iteration 613 * the iteration 614 * @param iterationInstances 615 * the iteration instances 584 616 */ 585 617 private void harmonizeIterationInstancesModel(IIteration iteration, … … 641 673 } 642 674 643 644 675 /** 645 676 * Match as sequence. 646 677 * 647 * @param appData RuleApplicationData needed to keep track of all created tasks 648 * @param m The match to be converted into a Task 649 * @return The task of the match with an ISequence as its root 678 * @param appData 679 * RuleApplicationData needed to keep track of all created tasks 680 * @param m 681 * The match to be converted into a Task 682 * @return The task of the match with an ISequence as its root 650 683 */ 651 684 synchronized public ISequence matchAsSequence(RuleApplicationData appData, … … 690 723 } 691 724 // Both tasks are not equal, we need to insert a selection here. 692 // Now things get complicated. We first need to check 693 // if the next position is not a selection. Then we can just create a selection 725 // Now things get complicated. We first need to check 726 // if the next position is not a selection. Then we can just create 727 // a selection 694 728 // of the both Tasks 695 // In the other case (more than one selection following this selection), we want to 696 // create a selection of sequences where each sequence gets the corresponding task of 729 // In the other case (more than one selection following this 730 // selection), we want to 731 // create a selection of sequences where each sequence gets the 732 // corresponding task of 697 733 // the its sequence in the pattern. 698 734 // … … 728 764 taskBuilder.addChild(selection, subsequence2); 729 765 taskBuilder.addChild(sequence, selection); 766 // TODO: We run not till the end! 730 767 while ((i < (first.length - 1)) && selectionfound) { 731 768 selectionfound = false; … … 743 780 i++; 744 781 } 745 if ((i == (first.length - 1)) && selectionfound) {746 747 748 749 750 }782 if ((i == (first.length - 1)) && selectionfound) { 783 taskBuilder.addChild(subsequence1, appData 784 .getNumber2Task().get(first[i])); 785 taskBuilder.addChild(subsequence2, appData 786 .getNumber2Task().get(second[i])); 787 } 751 788 } 752 789 } else { 790 // i = length-1 753 791 if ((first[i] != second[i])) { 754 792 … … 771 809 * <p> 772 810 * replaces all occurrences of all tasks provided in the set with iterations 773 * </p>. 811 * </p> 812 * . 774 813 * 775 * @param iteratedTasks the tasks to be replaced with iterations 776 * @param sessions the sessions in which the tasks are to be replaced 777 * @param appData the rule application data combining all data used for applying 814 * @param iteratedTasks 815 * the tasks to be replaced with iterations 816 * @param sessions 817 * the sessions in which the tasks are to be replaced 818 * @param appData 819 * the rule application data combining all data used for applying 778 820 * this rule 779 821 */ … … 841 883 * Replace matches. 842 884 * 843 * @param appData the app data 885 * @param appData 886 * the app data 844 887 */ 845 888 private void replaceMatches(RuleApplicationData appData) { … … 847 890 848 891 final int matchSeqSize = appData.getMatchseqs().size(); 849 int newThreads = nThreads; 850 if (matchSeqSize < nThreads) { 851 newThreads = matchSeqSize; 852 } 853 final ExecutorService executor = Executors 854 .newFixedThreadPool(newThreads); 855 final int interval = matchSeqSize / newThreads; 856 int rest = matchSeqSize % newThreads; 857 858 for (int i = 0; i < (matchSeqSize - interval); i += interval) { 859 int offset = 0; 860 if (rest != 0) { 861 offset = 1; 862 rest--; 863 } 864 final int from = i; 865 final int to = i + interval + offset; 866 System.out 867 .println("Replacement: Creating thread with matches from " 868 + from + " to " + to); 869 // search each match in every other sequence 870 final ParallelMatchReplacer replacer = new ParallelMatchReplacer( 871 appData, from, to); 872 executor.execute(replacer); 873 } 874 executor.shutdown(); 875 try { 876 executor.awaitTermination(2, TimeUnit.HOURS); 877 } catch (final InterruptedException e) { 878 // TODO Auto-generated catch block 879 e.printStackTrace(); 880 } 881 } 882 892 893 for (int i = 0; i < matchSeqSize; i++) { 894 895 // Every pattern consists of 2 sequences, therefore the minimum 896 // occurrences here is 2. 897 // We just need the sequences also occurring in other sequences 898 // as well 899 if (appData.getMatchseqs().get(i).occurenceCount() > 2) { 900 901 final ISequence task = matchAsSequence(appData, appData 902 .getMatchseqs().get(i)); 903 invalidOccurence: for (final Iterator<MatchOccurence> it = appData 904 .getMatchseqs().get(i).getOccurences().iterator(); it 905 .hasNext();) { 906 final MatchOccurence oc = it.next(); 907 908 // Check if nothing has been replaced in the sequence we 909 // want to replace now 910 if (appData.getReplacedOccurrences() 911 .get(oc.getSequenceId()) == null) { 912 appData.getReplacedOccurrences().put( 913 oc.getSequenceId(), 914 new LinkedList<MatchOccurence>()); 915 } else { 916 // check if we have any replaced occurence with 917 // indexes 918 // smaller than ours. If so, we need to adjust 919 // our start 920 // and endpoints 921 // of the replacement. 922 // Also do a check if we have replaced this 923 // specific 924 // MatchOccurence in this sequence already. Jump 925 // to the 926 // next occurence if this is the case. 927 // This is no more neccessary once the matches 928 // are 929 // harmonized. 930 931 for (final Iterator<MatchOccurence> jt = appData 932 .getReplacedOccurrences() 933 .get(oc.getSequenceId()).iterator(); jt 934 .hasNext();) { 935 final MatchOccurence tmpOC = jt.next(); 936 937 if ((oc.getStartindex() >= tmpOC.getStartindex()) 938 && (oc.getStartindex() <= tmpOC 939 .getEndindex())) { 940 continue invalidOccurence; 941 } 942 if (oc.getEndindex() >= tmpOC.getStartindex()) { 943 continue invalidOccurence; 944 945 } else if (oc.getStartindex() > tmpOC.getEndindex()) { 946 final int diff = tmpOC.getEndindex() 947 - tmpOC.getStartindex(); 948 // Just to be sure. 949 if (diff > 0) { 950 oc.setStartindex((oc.getStartindex() - diff) + 1); 951 oc.setEndindex((oc.getEndindex() - diff) + 1); 952 } else { 953 Console.traceln(Level.WARNING, 954 "End index of a Match before start. This should never happen"); 955 } 956 } 957 } 958 } 959 appData.detectedAndReplacedTasks = true; 960 final ISequenceInstance sequenceInstances = RuleUtils 961 .createNewSubSequenceInRange(appData.getSessions() 962 .get(oc.getSequenceId()), oc 963 .getStartindex(), oc.getEndindex(), task, 964 taskFactory, taskBuilder); 965 oc.setEndindex((oc.getStartindex() + sequenceInstances 966 .size()) - RuleUtils.missedOptionals); 967 968 // Adjust the length of the match regarding to the 969 // length of 970 // instance. (OptionalInstances may be shorter) 971 972 appData.getReplacedOccurrences().get(oc.getSequenceId()) 973 .add(oc); 974 } 975 } 976 } 977 } 883 978 884 979 /** … … 888 983 * </p> 889 984 * 890 * @param sessions the sessions 985 * @param sessions 986 * the sessions 891 987 * @return a set of tasks being iterated somewhere 892 988 */ … … 911 1007 * Search matches in all sessions. 912 1008 * 913 * @param appData the app data 1009 * @param appData 1010 * the app data 914 1011 */ 915 1012 private void searchMatchesInAllSessions(RuleApplicationData appData) { 916 Console.traceln(Level.INFO, 917 "searching for patterns occuring most with " + nThreads 918 + " threads"); 1013 919 1014 // Prepare parallel search of matchseqs 920 1015 final int matchSeqSize = appData.getMatchseqs().size(); 1016 Console.traceln(Level.INFO, 1017 "searching for patterns ("+ matchSeqSize+") occuring most with " + nThreads 1018 + " threads"); 921 1019 int newThreads = nThreads; 922 1020 if (matchSeqSize < nThreads) { … … 926 1024 int rest = matchSeqSize % newThreads; 927 1025 final ExecutorService executor = Executors.newFixedThreadPool(nThreads); 928 929 for (int i = 0; i < (matchSeqSize -interval); i += interval) {1026 Console.traceln(Level.FINE, "Interval: " + interval + " Rest: " + rest); 1027 for (int i = 0; i <= (matchSeqSize-interval); i += interval) { 930 1028 int offset = 0; 931 1029 if (rest != 0) { … … 934 1032 } 935 1033 final int from = i; 936 final int to = i + interval + offset; 937 System.out 938 .println("Match finding: Creating thread with matches from " 939 + from + " to " + to); 1034 final int to = i + interval + offset-1; 1035 Console.traceln(Level.FINE, "Match finding: Creating thread with matches from " 1036 + from + " to " + to); 940 1037 // search each match in every other sequence 941 1038 final ParallelMatchOcurrencesFinder finder = new ParallelMatchOcurrencesFinder( 942 1039 appData, from, to); 943 1040 executor.execute(finder); 1041 i+=offset; 944 1042 } 945 1043 executor.shutdown(); … … 947 1045 executor.awaitTermination(2, TimeUnit.HOURS); 948 1046 } catch (final InterruptedException e) { 949 // TODO Auto-generated catch block950 1047 e.printStackTrace(); 951 1048 } … … 967 1064 */ 968 1065 private class ParallelMatchOcurrencesFinder implements Runnable { 969 1066 970 1067 /** The app data. */ 971 1068 private final RuleApplicationData appData; 972 1069 973 1070 /** The from. */ 974 1071 private final int from; 975 1072 976 1073 /** The to. */ 977 1074 private final int to; … … 980 1077 * Instantiates a new parallel match ocurrences finder. 981 1078 * 982 * @param appData the app data 983 * @param from the from 984 * @param to the to 1079 * @param appData 1080 * the app data 1081 * @param from 1082 * the from 1083 * @param to 1084 * the to 985 1085 */ 986 1086 ParallelMatchOcurrencesFinder(RuleApplicationData appData, int from, … … 991 1091 } 992 1092 993 /* (non-Javadoc) 1093 /* 1094 * (non-Javadoc) 1095 * 994 1096 * @see java.lang.Runnable#run() 995 1097 */ … … 1033 1135 1034 1136 /** 1035 * The Class Parallel MatchReplacer.1036 */ 1037 private class Parallel MatchReplacer implements Runnable {1137 * The Class ParallelPairwiseAligner. 1138 */ 1139 private class ParallelPairwiseAligner implements Runnable { 1038 1140 1039 1141 /** The app data. */ 1040 1142 private final RuleApplicationData appData; 1041 1143 1042 1144 /** The from. */ 1043 1145 private final int from; 1044 1146 1045 1147 /** The to. */ 1046 1148 private final int to; 1047 1149 1048 1150 /** 1049 * Instantiates a new parallel match replacer.1050 *1051 * @param appData the app data1052 * @param from the from1053 * @param to the to1054 */1055 ParallelMatchReplacer(RuleApplicationData appData, int from, int to) {1056 this.appData = appData;1057 this.from = from;1058 this.to = to;1059 }1060 1061 /* (non-Javadoc)1062 * @see java.lang.Runnable#run()1063 */1064 @Override1065 public void run() {1066 // TODO Cleanup1067 // int count = 0;1068 // int size = to - from;1069 for (int i = from; i < to; i++) {1070 // count++;1071 // Every pattern consists of 2 sequences, therefore the minimum1072 // occurrences here is 2.1073 // We just need the sequences also occurring in other sequences1074 // as well1075 if (appData.getMatchseqs().get(i).occurenceCount() > 2) {1076 1077 final ISequence task = matchAsSequence(appData, appData1078 .getMatchseqs().get(i));1079 invalidOccurence: for (final Iterator<MatchOccurence> it = appData1080 .getMatchseqs().get(i).getOccurences().iterator(); it1081 .hasNext();) {1082 final MatchOccurence oc = it.next();1083 1084 // Check if nothing has been replaced in the sequence we1085 // want to replace now1086 1087 synchronized (appData.getReplacedOccurrences()) {1088 if (appData.getReplacedOccurrences().get(1089 oc.getSequenceId()) == null) {1090 appData.getReplacedOccurrences().put(1091 oc.getSequenceId(),1092 new LinkedList<MatchOccurence>());1093 } else {1094 // check if we have any replaced occurence with1095 // indexes1096 // smaller than ours. If so, we need to adjust1097 // our start1098 // and endpoints1099 // of the replacement.1100 // Also do a check if we have replaced this1101 // specific1102 // MatchOccurence in this sequence already. Jump1103 // to the1104 // next occurence if this is the case.1105 // This is no more neccessary once the matches1106 // are1107 // harmonized.1108 for (final Iterator<MatchOccurence> jt = appData1109 .getReplacedOccurrences()1110 .get(oc.getSequenceId()).iterator(); jt1111 .hasNext();) {1112 final MatchOccurence tmpOC = jt.next();1113 1114 if ((oc.getStartindex() >= tmpOC1115 .getStartindex())1116 && (oc.getStartindex() <= tmpOC1117 .getEndindex())) {1118 continue invalidOccurence;1119 }1120 if (oc.getEndindex() >= tmpOC1121 .getStartindex()) {1122 continue invalidOccurence;1123 1124 } else if (oc.getStartindex() > tmpOC1125 .getEndindex()) {1126 final int diff = tmpOC.getEndindex()1127 - tmpOC.getStartindex();1128 // Just to be sure.1129 if (diff > 0) {1130 oc.setStartindex((oc1131 .getStartindex() - diff) + 1);1132 oc.setEndindex((oc.getEndindex() - diff) + 1);1133 } else {1134 Console.traceln(Level.WARNING,1135 "End index of a Match before start. This should never happen");1136 }1137 }1138 }1139 }1140 synchronized (appData) {1141 appData.detectedAndReplacedTasks = true;1142 }1143 synchronized (appData.getSessions().get(1144 oc.getSequenceId())) {1145 final ISequenceInstance sequenceInstances = RuleUtils1146 .createNewSubSequenceInRange(1147 appData.getSessions().get(1148 oc.getSequenceId()),1149 oc.getStartindex(),1150 oc.getEndindex(), task,1151 taskFactory, taskBuilder);1152 oc.setEndindex((oc.getStartindex() + sequenceInstances1153 .size()) - RuleUtils.missedOptionals);1154 }1155 }1156 // Adjust the length of the match regarding to the1157 // length of1158 // instance. (OptionalInstances may be shorter)1159 synchronized (appData.getReplacedOccurrences().get(1160 oc.getSequenceId())) {1161 appData.getReplacedOccurrences()1162 .get(oc.getSequenceId()).add(oc);1163 }1164 }1165 }1166 }1167 }1168 }1169 1170 /**1171 * The Class ParallelPairwiseAligner.1172 */1173 private class ParallelPairwiseAligner implements Runnable {1174 1175 /** The app data. */1176 private final RuleApplicationData appData;1177 1178 /** The from. */1179 private final int from;1180 1181 /** The to. */1182 private final int to;1183 1184 /**1185 1151 * Instantiates a new parallel pairwise aligner. 1186 1152 * 1187 * @param appData the app data 1188 * @param from the from 1189 * @param to the to 1153 * @param appData 1154 * the app data 1155 * @param from 1156 * the from 1157 * @param to 1158 * the to 1190 1159 */ 1191 1160 ParallelPairwiseAligner(RuleApplicationData appData, int from, int to) { … … 1195 1164 } 1196 1165 1197 /* (non-Javadoc) 1166 /* 1167 * (non-Javadoc) 1168 * 1198 1169 * @see java.lang.Runnable#run() 1199 1170 */ … … 1201 1172 public void run() { 1202 1173 int count = 0; 1203 final int size = to - from; 1174 final int size = to - from; 1204 1175 1205 1176 for (int i = from; i < to; i++) { … … 1223 1194 } 1224 1195 } 1225 1196 1226 1197 }
Note: See TracChangeset
for help on using the changeset viewer.