Changeset 1657 for branches/autoquest-core-tasktrees-alignment
- Timestamp:
- 08/11/14 08:22:13 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java
r1655 r1657 41 41 return occurences.size(); 42 42 } 43 44 public int size() { 45 //Both sequences should be equally long 46 return matchseqs.get(0).size(); 47 } 43 48 44 49 public boolean equals(Match m) { -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/MatchOccurence.java
r1620 r1657 3 3 public class MatchOccurence { 4 4 private int startindex; 5 private int endindex; 5 6 private int sequenceId; 6 public MatchOccurence(int startindex, int sequenceId) { 7 8 public MatchOccurence(int startindex, int endindex, int sequenceId) { 7 9 this.startindex = startindex; 10 this.endindex = endindex; 8 11 this.sequenceId = sequenceId; 9 12 } 13 14 public int getEndindex() { 15 return endindex; 16 } 17 18 public void setEndindex(int endindex) { 19 this.endindex = endindex; 20 } 21 22 10 23 public int getStartindex() { 11 24 return startindex; … … 17 30 return sequenceId; 18 31 } 32 33 public void setSequenceId(int sequenceId) { 34 this.sequenceId = sequenceId; 35 } 19 36 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1653 r1657 8 8 private int id; 9 9 10 11 10 public NumberSequence(int size) { 12 11 13 12 sequence = new int[size]; 14 13 } 15 14 16 15 public int[] getSequence() { 17 16 return sequence; … … 45 44 } 46 45 47 // Searching occurrences of46 // Searching occurrences of 48 47 public LinkedList<Integer> containsPattern(Match pattern) { 49 48 LinkedList<Integer> result = new LinkedList<Integer>(); … … 51 50 int[] pat1 = pattern.getFirstSequence().getSequence(); 52 51 int[] pat2 = pattern.getSecondSequence().getSequence(); 53 notmatched: while (i < sequence.length - pat1.length) {52 notmatched: while (i <= sequence.length - pat1.length) { 54 53 if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { 55 int ipat1 = 0;56 int ipat2 = 0;54 int ipat1 = 0; 55 int ipat2 = 0; 57 56 int optcount1 = 0; 58 57 int optcount2 = 0; 59 while(ipat1 < pat1.length && ipat2<pat2.length) { 60 if(pat1[ipat1]==-1) { 61 ipat1++; 62 optcount1++; 63 continue; 64 } 65 if(pat2[ipat2]==-1) { 66 ipat2++; 67 optcount2++; 68 continue; 69 } 70 if (sequence[i + ipat1-optcount1] != pat1[ipat1] 71 && sequence[i + ipat2-optcount2] != pat2[ipat2]) { 58 while (ipat1 < pat1.length 59 && ipat2 < pat2.length) { 60 61 if (pat1[ipat1] == -1) { 62 ipat1++; 63 optcount1++; 64 continue; 65 } 66 67 if (pat2[ipat2] == -1) { 68 ipat2++; 69 optcount2++; 70 continue; 71 } 72 73 74 if (sequence[i + ipat1 - optcount1] != pat1[ipat1] 75 && sequence[i + ipat2 - optcount2] != pat2[ipat2]) { 72 76 i++; 73 //System.out.println(sequence[i+ipat1] + " != " + pat1[ipat1] + " || " + sequence[i+ipat2] + " != " + pat2[ipat2]); 77 // System.out.println(sequence[i+ipat1-optcount1] + 78 // " != " + pat1[ipat1] + " || " + 79 // sequence[i+ipat2-optcount2] + " != " + pat2[ipat2]); 74 80 continue notmatched; 75 81 } 76 ipat1++;77 ipat2++;82 ipat1++; 83 ipat2++; 78 84 } 85 79 86 result.add(i); 87 System.out.println("FOUND MATCH AT: " + i); 88 this.printSequence(); 89 pattern.getFirstSequence().printSequence(); 90 pattern.getSecondSequence().printSequence(); 80 91 } 81 92 i++; … … 83 94 return result; 84 95 } 85 86 // Returns the number of times event occurs in this sequence96 97 // Returns the number of times event occurs in this sequence 87 98 public int eventCount(int event) { 88 99 int count = 0; 89 for (int i=0;i<sequence.length;i++) {90 if (sequence[i] == event) {100 for (int i = 0; i < sequence.length; i++) { 101 if (sequence[i] == event) { 91 102 count++; 92 103 } … … 99 110 } 100 111 101 102 112 public int getId() { 103 113 return id; 104 114 } 105 115 106 107 116 public void setId(int id) { 108 117 this.id = id; 109 118 } 110 119 111 120 public boolean equals(NumberSequence n) { 112 121 int[] seq = n.getSequence(); 113 if (n.size() !=this.size()) {114 return false; 122 if (n.size() != this.size()) { 123 return false; 115 124 } 116 for (int i =0; i<n.size();i++) {117 if (seq[i] != this.sequence[i]) {125 for (int i = 0; i < n.size(); i++) { 126 if (seq[i] != this.sequence[i]) { 118 127 return false; 119 128 } … … 121 130 return true; 122 131 } 123 124 132 125 133 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
r1656 r1657 17 17 import java.util.Iterator; 18 18 19 import org.apache.commons.lang.NotImplementedException; 20 19 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 20 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; … … 46 48 private static int idCounter = 0; 47 49 50 public static int missedOptionals = 0; 51 48 52 /** 49 53 * <p> … … 107 111 .createNewTaskInstance(model); 108 112 109 for (int i=0; i<subsequence.getSequence().getChildren().size();i++) { 110 System.out.println(subsequence.getSequence().getChildren().get(i)); 111 } 112 System.out.println(); 113 113 //for (int i=0; i<subsequence.getSequence().getChildren().size();i++) { 114 // System.out.println(subsequence.getSequence().getChildren().get(i)); 115 //} 116 System.out.println(); 117 //TODO: This is dirty! 118 missedOptionals=0; 114 119 int modelindex=0; 115 120 for (int i = startIndex; i <= endIndex; i++) { 116 121 122 if(modelindex == model.getChildren().size()) { 123 break; 124 } 117 125 ITask tempTask = model.getChildren().get(modelindex); 118 126 //System.out.println("Trying to add " + parent.get(startIndex) … … 131 139 taskBuilder.addChild(subsequence, optional); 132 140 modelindex++; 133 i++;141 missedOptionals++; 134 142 continue; 135 143 } … … 142 150 } else if (tempTask.getType() == "sequence") { 143 151 System.out.println("Adding SequenceInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 152 //TODO: Implement this 153 throw new NotImplementedException(); 144 154 145 155 } else if (tempTask.getType() == "iteration") { 156 //TODO: Implement this 146 157 System.out.println("Adding IterationInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 158 throw new NotImplementedException(); 147 159 } else { 148 160 System.out.println("Adding EventInstance " + parent.get(startIndex) + " to " + tempTask.getType()); … … 152 164 modelindex++; 153 165 } 154 166 /* 167 System.out.println(); 155 168 System.out.println("Sequence instance:"); 156 169 for(Iterator<ITaskInstance> it = subsequence.iterator();it.hasNext();) { 157 170 System.out.println(it.next()); 158 } 171 }*/ 172 System.out.println(); 173 System.out.println(); 159 174 160 175 taskBuilder.addTaskInstance(parent, startIndex, subsequence); -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1656 r1657 95 95 * <p> 96 96 * the task handling strategy to be used for comparing tasks during 97 * iteration detection i.e., after the tasks are 98 * harmonized 97 * iteration detection i.e., after the tasks are harmonized 99 98 * </p> 100 99 */ 101 100 private TaskHandlingStrategy identityTaskHandlingStrategy; 102 103 104 101 105 102 /** … … 166 163 .generate(appData.getNumberSequences(), submat, 9); 167 164 168 169 170 165 // Retrieve all matches reached a specific threshold 171 166 Console.traceln(Level.INFO, "retrieving significant sequence pieces"); … … 174 169 Level.FINEST, 175 170 "retrieving significant sequence pieces: " 176 + Math.round((float) i / (float) appData.getNumberSequences().size() 177 * 100) + "%"); 171 + Math.round((float) i 172 / (float) appData.getNumberSequences() 173 .size() * 100) + "%"); 178 174 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 179 175 if (i != j) { … … 197 193 .getFirstSequence().size()) 198 194 continue; 199 195 200 196 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 201 LinkedList<Integer> startpositions = appData .getNumberSequences().get(j)202 . containsPattern(pattern);197 LinkedList<Integer> startpositions = appData 198 .getNumberSequences().get(j).containsPattern(pattern); 203 199 if (startpositions.size() > 0) { 204 200 NumberSequence tempns = appData.getNumberSequences().get(j); 205 201 206 202 for (Iterator<Integer> jt = startpositions.iterator(); jt 207 203 .hasNext();) { 208 204 int start = jt.next(); 209 // TODO: Debug Output205 // TODO: Debug Output 210 206 /* 211 System.out.println("Found match "); 212 pattern.getFirstSequence().printSequence(); 213 pattern.getSecondSequence().printSequence(); 214 System.out.println("in sequence " + (j+1) + " at position " + start); 215 for(int k=0;k<tempns.getSequence().length;k++) { 216 System.out.print(k + ": " + tempns.getSequence()[k] + " "); 217 System.out.println(appData.getNumber2Task().get(tempns.getSequence()[k])); 218 } 219 */ 220 pattern.addOccurence( 221 new MatchOccurence(start, j)); 207 * System.out.println("Found match "); 208 * pattern.getFirstSequence().printSequence(); 209 * pattern.getSecondSequence().printSequence(); 210 * System.out.println("in sequence " + (j+1) + 211 * " at position " + start); for(int 212 * k=0;k<tempns.getSequence().length;k++) { 213 * System.out.print(k + ": " + tempns.getSequence()[k] + 214 * " "); 215 * System.out.println(appData.getNumber2Task().get( 216 * tempns.getSequence()[k])); } 217 */ 218 pattern.addOccurence(new MatchOccurence(start, start 219 + pattern.size(), j)); 222 220 } 223 221 … … 230 228 Comparator<Match> comparator = new Comparator<Match>() { 231 229 public int compare(Match m1, Match m2) { 232 return m2.occurenceCount() - m1.occurenceCount(); 233 230 return m2.occurenceCount() - m1.occurenceCount(); 231 234 232 } 235 233 }; 236 //Collections.sort(matchseqs, comparator); 237 234 // Collections.sort(matchseqs, comparator); 238 235 239 236 // TODO: Harmonize matches: finding double matches and merge them 240 237 /* 241 Console.traceln(Level.INFO, "harmonizing matches"); 242 int i=0; 243 244 while(i<matchseqs.size()) { 245 int j=i; 246 while(j<matchseqs.size()) { 247 if(i!=j) { 248 if(matchseqs.get(i).equals(matchseqs.get(j))) { 249 //matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 250 matchseqs.remove(j); 251 252 //System.out.println("Sequence " + i); 253 //matchseqs.get(i).getFirstSequence().printSequence(); 254 //matchseqs.get(i).getSecondSequence().printSequence(); 255 //System.out.println("is equal to sequence " + j); 256 //matchseqs.get(j).getFirstSequence().printSequence(); 257 //matchseqs.get(j).getSecondSequence().printSequence(); 258 continue; 259 } 260 } 261 j++; 262 } 263 i++; 264 } 265 Collections.sort(matchseqs, comparator); 266 */ 267 268 269 // Just printing the results out 238 * Console.traceln(Level.INFO, "harmonizing matches"); int i=0; 239 * 240 * while(i<matchseqs.size()) { int j=i; while(j<matchseqs.size()) { 241 * if(i!=j) { if(matchseqs.get(i).equals(matchseqs.get(j))) { 242 * //matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 243 * matchseqs.remove(j); 244 * 245 * //System.out.println("Sequence " + i); 246 * //matchseqs.get(i).getFirstSequence().printSequence(); 247 * //matchseqs.get(i).getSecondSequence().printSequence(); 248 * //System.out.println("is equal to sequence " + j); 249 * //matchseqs.get(j).getFirstSequence().printSequence(); 250 * //matchseqs.get(j).getSecondSequence().printSequence(); continue; } } 251 * j++; } i++; } Collections.sort(matchseqs, comparator); 252 */ 253 254 HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); 255 // Replace matches in the sessions 270 256 for (int i = 0; i < matchseqs.size(); i++) { 271 257 // Every pattern consists of 2 sequences, therefore the minimum … … 274 260 // well 275 261 if (matchseqs.get(i).occurenceCount() > 2) { 276 277 ISequence task = matchAsSequence(appData,matchseqs.get(i)); 278 for(Iterator<MatchOccurence> it = matchseqs.get(i).getOccurences().iterator();it.hasNext();) { 262 263 ISequence task = matchAsSequence(appData, matchseqs.get(i)); 264 invalidOccurence: for (Iterator<MatchOccurence> it = matchseqs 265 .get(i).getOccurences().iterator(); it.hasNext();) { 279 266 MatchOccurence oc = it.next(); 280 267 System.out.println("Trying to replace sequence: "); 281 268 matchseqs.get(i).getFirstSequence().printSequence(); 282 269 matchseqs.get(i).getSecondSequence().printSequence(); 283 System.out.println(" in session number: " + (oc.getSequenceId()+1) + " at position " + (oc.getStartindex()) + "-" + (oc.getStartindex()+matchseqs.get(i).getFirstSequence().size())); 270 System.out.println(" in session number: " 271 + (oc.getSequenceId() + 1) 272 + " at position " 273 + (oc.getStartindex()) 274 + "-" 275 + (oc.getStartindex() + matchseqs.get(i) 276 .getFirstSequence().size())); 284 277 System.out.println(); 285 /* 286 System.out.println("Printing session: "); 287 for(int j=0;j<sessions.get(oc.getSequenceId()).size();j++) { 288 System.out.println(j+ ": " + sessions.get(oc.getSequenceId()).get(j)); 289 }*/ 290 List<ISequenceInstance> sequenceInstances = new LinkedList<ISequenceInstance>(); 291 RuleUtils.createNewSubSequenceInRange(sessions.get(oc.getSequenceId()), oc.getStartindex(), oc.getStartindex()+matchseqs.get(i).getFirstSequence().size(), task, taskFactory, taskBuilder); 292 } 293 //System.out.println(task); 294 //matchseqs.get(i).getFirstSequence().printSequence(); 295 //matchseqs.get(i).getSecondSequence().printSequence(); 296 //System.out.println("Found pattern " 297 // + matchseqs.get(i).occurenceCount() + " times"); 278 279 //System.out.println("Printing session: "); 280 for (int j = 0; j < sessions.get(oc.getSequenceId()).size(); j++) { 281 System.out.println(j + ": "+ sessions.get(oc.getSequenceId()).get(j)); 282 } 283 284 // Check if nothing has been replaced in the sequence we 285 // want to replace 286 if (replacedOccurences.get(oc.getSequenceId()) == null) { 287 replacedOccurences.put(oc.getSequenceId(), 288 new LinkedList<MatchOccurence>()); 289 } else { 290 // check if we have any replaced occurence with indexes 291 // smaller than ours. If so, we need to adjust our start 292 // and endpoints 293 // of the replacement. 294 // Also do a check if we have replaced this specific 295 // MatchOccurence in this sequence already. Jump to the 296 // next occurence if this is the case. 297 // This is no more neccessary once the matches are 298 // harmonized. 299 for (Iterator<MatchOccurence> jt = replacedOccurences 300 .get(oc.getSequenceId()).iterator(); jt 301 .hasNext();) { 302 MatchOccurence tmpOC = jt.next(); 303 if (tmpOC.getStartindex() == oc.getStartindex()) { 304 System.out.println("This position has already been replaced in this iteration"); 305 continue invalidOccurence; 306 307 } 308 if (tmpOC.getStartindex() < oc 309 .getStartindex()) { 310 int diff = tmpOC.getEndindex() 311 - tmpOC.getStartindex(); 312 // Just to be sure. 313 if (diff > 0) { 314 System.out.println("Old index: Start: " 315 + oc.getStartindex() + " End " 316 + oc.getEndindex()); 317 oc.setStartindex(oc.getStartindex() - diff+1); 318 oc.setEndindex(oc.getEndindex() - diff+1); 319 System.out.println("Updated index: Start: " 320 + oc.getStartindex() + " End " 321 + oc.getEndindex()); 322 } else { 323 Console.traceln(Level.WARNING, 324 "End index of a Match before start. This should never happen"); 325 } 326 } 327 } 328 } 329 330 331 ISequenceInstance sequenceInstances = RuleUtils.createNewSubSequenceInRange( 332 sessions.get(oc.getSequenceId()), 333 oc.getStartindex(), oc.getEndindex(), task, 334 taskFactory, taskBuilder); 335 336 //Adjust the length of the match regarding to the length of instance. (OptionalInstances may be shorter) 337 oc.setEndindex(oc.getStartindex()+sequenceInstances.size()-RuleUtils.missedOptionals); 338 replacedOccurences.get(oc.getSequenceId()).add(oc); 339 } 340 298 341 System.out.println(); 299 342 } 300 343 } 301 302 344 303 345 alignments = null; 304 346 305 347 do { 306 307 appData.getStopWatch().start("whole loop"); // 308 detectAndReplaceIterations(appData); 309 310 appData.getStopWatch().start("task replacement"); // 311 //detectAndReplaceTasks(appData); // 312 appData.getStopWatch().stop("task replacement"); // 313 appData.getStopWatch().stop("whole loop"); 314 315 appData.getStopWatch().dumpStatistics(System.out); // 316 appData.getStopWatch().reset(); 317 318 } while (appData.detectedAndReplacedTasks()); 319 348 349 appData.getStopWatch().start("whole loop"); // 350 detectAndReplaceIterations(appData); 351 352 appData.getStopWatch().start("task replacement"); // 353 // detectAndReplaceTasks(appData); // 354 appData.getStopWatch().stop("task replacement"); // 355 appData.getStopWatch().stop("whole loop"); 356 357 appData.getStopWatch().dumpStatistics(System.out); // 358 appData.getStopWatch().reset(); 359 360 } while (appData.detectedAndReplacedTasks()); 320 361 321 362 Console.println("created " … … 334 375 } 335 376 336 337 338 377 /** 339 378 * <p> … … 363 402 ITask task; 364 403 List<IUserSession> sessions = appData.getSessions(); 365 for (int j = 0; j < sessions.size();j++) {404 for (int j = 0; j < sessions.size(); j++) { 366 405 IUserSession session = sessions.get(j); 367 406 368 407 NumberSequence templist = new NumberSequence(session.size()); 369 408 … … 375 414 uniqueTasks.addSymbol(taskInstance, taskInstance.getTask()); 376 415 templist.getSequence()[i] = taskInstance.getTask().getId(); 377 416 378 417 } else { 379 418 taskBuilder.setTask(taskInstance, task); … … 381 420 unifiedTasks++; 382 421 } 383 appData.getNumber2Task().put(templist.getSequence()[i], taskInstance.getTask()); 422 appData.getNumber2Task().put(templist.getSequence()[i], 423 taskInstance.getTask()); 384 424 385 //System.out.println("TaskID: " + taskInstance.getTask().getId()+ " Numbersequence: " + templist.getSequence()[i]); 386 } 387 //Each NumberSequence is identified by its id, beginning to count at zero 425 //if(j==1) { 426 // System.out.println(i + ": TaskID: " + 427 // taskInstance.getTask().getId()+ " Numbersequence: " + 428 // templist.getSequence()[i]); 429 //} 430 431 } 432 // Each NumberSequence is identified by its id, beginning to count 433 // at zero 388 434 templist.setId(j); 389 435 appData.getNumberSequences().add(templist); … … 528 574 } 529 575 530 531 ISequence matchAsSequence(RuleApplicationData appData,Match m) { 532 533 ISequence sequence = taskFactory.createNewSequence(); 534 535 int[] first = m.getFirstSequence().getSequence(); 536 int[] second = m.getSecondSequence().getSequence(); 537 538 539 //Both sequences of a match are equally long 540 for(int i=0;i<m.getFirstSequence().size();i++) { 541 542 //Two gaps aligned to each other: Have not seen it happening so far, just to handle it 543 if(first[i]==-1 && second[i]==-1) { 544 //TODO: Do nothing? 545 } 546 //Both events are equal, we can simply add the task referring to the number 547 else if(first[i]==second[i]) { 548 taskBuilder.addChild(sequence, appData.getNumber2Task().get(first[i])); 549 } 550 //We have a gap in the first sequence, we need to add the task of the second sequence as optional 551 else if(first[i]==-1 && second[i]!=-1) { 552 IOptional optional = taskFactory.createNewOptional(); 553 taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(second[i])); 554 taskBuilder.addChild(sequence,optional); 555 } 556 //We have a gap in the second sequence, we need to add the task of the first sequence as optional 557 else if(first[i]!=-1 && second[i]==-1) { 558 IOptional optional = taskFactory.createNewOptional(); 559 taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(first[i])); 560 taskBuilder.addChild(sequence,optional); 561 } 562 //Both tasks are unequal, we need to insert a selection here 563 else { 564 ISelection selection = taskFactory.createNewSelection(); 565 taskBuilder.addChild(selection, appData.getNumber2Task().get(first[i])); 566 taskBuilder.addChild(selection, appData.getNumber2Task().get(second[i])); 567 taskBuilder.addChild(sequence,selection); 568 } 569 } 570 571 //TODO: Debug output 572 /* 573 for (int i =0;i<sequence.getChildren().size();i++) { 574 System.out.println(sequence.getChildren().get(i)); 575 576 if(sequence.getChildren().get(i).getType() == "selection") { 577 for(int j=0; j< ((ISelection) sequence.getChildren().get(i)).getChildren().size();j++) { 578 System.out.println("\t" +((ISelection) sequence.getChildren().get(i)).getChildren().get(j)); 579 } 580 } 581 } 582 */ 583 return sequence; 584 } 585 586 576 ISequence matchAsSequence(RuleApplicationData appData, Match m) { 577 578 ISequence sequence = taskFactory.createNewSequence(); 579 580 int[] first = m.getFirstSequence().getSequence(); 581 int[] second = m.getSecondSequence().getSequence(); 582 583 // Both sequences of a match are equally long 584 for (int i = 0; i < m.getFirstSequence().size(); i++) { 585 586 // Two gaps aligned to each other: Have not seen it happening so 587 // far, just to handle it 588 if (first[i] == -1 && second[i] == -1) { 589 // TODO: Do nothing? 590 } 591 // Both events are equal, we can simply add the task referring to 592 // the number 593 else if (first[i] == second[i]) { 594 taskBuilder.addChild(sequence, 595 appData.getNumber2Task().get(first[i])); 596 } 597 // We have a gap in the first sequence, we need to add the task of 598 // the second sequence as optional 599 else if (first[i] == -1 && second[i] != -1) { 600 IOptional optional = taskFactory.createNewOptional(); 601 taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 602 .get(second[i])); 603 taskBuilder.addChild(sequence, optional); 604 } 605 // We have a gap in the second sequence, we need to add the task of 606 // the first sequence as optional 607 else if (first[i] != -1 && second[i] == -1) { 608 IOptional optional = taskFactory.createNewOptional(); 609 taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 610 .get(first[i])); 611 taskBuilder.addChild(sequence, optional); 612 } 613 // Both tasks are unequal, we need to insert a selection here 614 else { 615 ISelection selection = taskFactory.createNewSelection(); 616 taskBuilder.addChild(selection, 617 appData.getNumber2Task().get(first[i])); 618 taskBuilder.addChild(selection, 619 appData.getNumber2Task().get(second[i])); 620 taskBuilder.addChild(sequence, selection); 621 } 622 } 623 624 // TODO: Debug output 625 /* 626 * for (int i =0;i<sequence.getChildren().size();i++) { 627 * System.out.println(sequence.getChildren().get(i)); 628 * 629 * if(sequence.getChildren().get(i).getType() == "selection") { for(int 630 * j=0; j< ((ISelection) 631 * sequence.getChildren().get(i)).getChildren().size();j++) { 632 * System.out.println("\t" +((ISelection) 633 * sequence.getChildren().get(i)).getChildren().get(j)); } } } 634 */ 635 return sequence; 636 } 637 587 638 /** 588 639 * <p> … … 659 710 appData.getStopWatch().start("detecting tasks"); 660 711 661 // getSequencesOccuringMostOften(appData);712 // getSequencesOccuringMostOften(appData); 662 713 663 714 appData.getStopWatch().stop("detecting tasks"); … … 667 718 668 719 appData.getStopWatch().stop("replacing tasks"); 669 670 //Console.traceln(Level.INFO, "detected and replaced " 671 // + appData.getLastFoundTasks().size() + " tasks occuring " 672 // + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 673 } 674 675 676 720 721 // Console.traceln(Level.INFO, "detected and replaced " 722 // + appData.getLastFoundTasks().size() + " tasks occuring " 723 // + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 724 } 677 725 678 726 /** … … 684 732 appData.detectedAndReplacedTasks(false); 685 733 686 /* 687 Console.traceln(Level.FINER, "replacing tasks occurrences"); 688 689 for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 690 ISequence sequence = taskFactory.createNewSequence(); 691 692 Console.traceln(Level.FINEST, "replacing " + sequence.getId() 693 + ": " + task); 694 695 List<ISequenceInstance> sequenceInstances = replaceTaskOccurrences( 696 task, appData.getSessions(), sequence); 697 698 harmonizeSequenceInstancesModel(sequence, sequenceInstances, 699 task.size()); 700 appData.detectedAndReplacedTasks(appData 701 .detectedAndReplacedTasks() 702 || (sequenceInstances.size() > 0)); 703 704 if (sequenceInstances.size() < appData.getLastFoundTasks() 705 .getOccurrenceCount()) { 706 Console.traceln(Level.FINE, 707 sequence.getId() 708 + ": replaced task only " 709 + sequenceInstances.size() 710 + " times instead of expected " 711 + appData.getLastFoundTasks() 712 .getOccurrenceCount()); 713 } 714 } 715 */ 716 } 717 734 /* 735 * Console.traceln(Level.FINER, "replacing tasks occurrences"); 736 * 737 * for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 738 * ISequence sequence = taskFactory.createNewSequence(); 739 * 740 * Console.traceln(Level.FINEST, "replacing " + sequence.getId() + ": " 741 * + task); 742 * 743 * List<ISequenceInstance> sequenceInstances = replaceTaskOccurrences( 744 * task, appData.getSessions(), sequence); 745 * 746 * harmonizeSequenceInstancesModel(sequence, sequenceInstances, 747 * task.size()); appData.detectedAndReplacedTasks(appData 748 * .detectedAndReplacedTasks() || (sequenceInstances.size() > 0)); 749 * 750 * if (sequenceInstances.size() < appData.getLastFoundTasks() 751 * .getOccurrenceCount()) { Console.traceln(Level.FINE, sequence.getId() 752 * + ": replaced task only " + sequenceInstances.size() + 753 * " times instead of expected " + appData.getLastFoundTasks() 754 * .getOccurrenceCount()); } } 755 */ 756 } 718 757 719 758 /** … … 847 886 } 848 887 849 850 888 /** 851 889 * … … 853 891 private static class RuleApplicationData { 854 892 855 856 private HashMap<Integer,ITask> number2task; 857 858 893 private HashMap<Integer, ITask> number2task; 894 859 895 private ArrayList<NumberSequence> numberseqs; 860 896 861 897 /** 862 898 * 863 899 */ 864 900 private List<IUserSession> sessions; 865 866 867 901 868 902 /** … … 887 921 this.sessions = sessions; 888 922 numberseqs = new ArrayList<NumberSequence>(); 889 number2task = new HashMap<Integer, ITask>();890 stopWatch = new StopWatch();891 result = 923 number2task = new HashMap<Integer, ITask>(); 924 stopWatch = new StopWatch(); 925 result = new RuleApplicationResult(); 892 926 } 893 927 … … 899 933 } 900 934 901 902 935 private ArrayList<NumberSequence> getNumberSequences() { 903 936 return numberseqs; 904 937 } 905 906 907 938 908 939 /** … … 934 965 } 935 966 936 private HashMap<Integer, ITask> getNumber2Task() {967 private HashMap<Integer, ITask> getNumber2Task() { 937 968 return number2task; 938 969 } … … 940 971 } 941 972 942 943 944 945 973 }
Note: See TracChangeset
for help on using the changeset viewer.