Changeset 1662 for branches/autoquest-core-tasktrees-alignment/src
- Timestamp:
- 08/12/14 00:47:22 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1660 r1662 45 45 46 46 //Recursive check if sequence contains pattern at position i 47 p ublicboolean matches(int i, int[] p1, int[] p2 ,int ip1,int ip2) {47 private boolean matches(int i, int[] p1, int[] p2 ,int ip1,int ip2) { 48 48 49 49 if(p1.length==ip1) { … … 69 69 70 70 //Searching occurrences of pattern 71 72 71 public LinkedList<Integer> containsPattern(Match pattern) { 73 72 LinkedList<Integer> result = new LinkedList<Integer>(); … … 78 77 while (i < sequence.length ) { 79 78 if(matches(i,pat1,pat2,0,0)) { 80 System.out.println(i);81 79 result.add(i); 82 System.out.println("FOUND MATCH AT: " + i);83 this.printSequence();84 pattern.getFirstSequence().printSequence();85 pattern.getSecondSequence().printSequence();86 80 } 87 81 i++; -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1657 r1662 232 232 } 233 233 }; 234 // Collections.sort(matchseqs, comparator); 235 236 // TODO: Harmonize matches: finding double matches and merge them 237 /* 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 */ 234 Collections.sort(matchseqs, comparator); 253 235 254 236 HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); … … 277 259 System.out.println(); 278 260 279 // System.out.println("Printing session: ");261 // System.out.println("Printing session: "); 280 262 for (int j = 0; j < sessions.get(oc.getSequenceId()).size(); j++) { 281 System.out.println(j + ": "+ sessions.get(oc.getSequenceId()).get(j)); 263 System.out.println(j + ": " 264 + sessions.get(oc.getSequenceId()).get(j)); 282 265 } 283 266 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 341 System.out.println(); 267 ISequenceInstance sequenceInstances = RuleUtils 268 .createNewSubSequenceInRange( 269 sessions.get(oc.getSequenceId()), 270 oc.getStartindex(), oc.getEndindex(), task, 271 taskFactory, taskBuilder); 272 // Adjust the length of the match regarding to the length of 273 // instance. (OptionalInstances may be shorter) 274 oc.setEndindex(oc.getStartindex() 275 + sequenceInstances.size() 276 - RuleUtils.missedOptionals); 277 278 updateMatchIndexes(matchseqs, oc.getSequenceId(), 279 oc.getStartindex(), oc.getEndindex()); 280 281 } 342 282 } 343 283 } … … 373 313 374 314 return appData.getResult(); 315 } 316 317 // check if we have any replaced occurence with indexes 318 // smaller than ours. If so, we need to adjust our start 319 // and endpoints 320 // of the replacement. 321 // Also do a check if we have replaced this specific 322 // MatchOccurence in this sequence already. Jump to the 323 // next occurence if this is the case. 324 private void updateMatchIndexes(List<Match> matchseqs, int sequenceId, 325 int startindex, int endindex) { 326 327 for (int i = 0; i < matchseqs.size(); i++) { 328 for (Iterator<MatchOccurence> it = matchseqs.get(i).getOccurences() 329 .iterator(); it.hasNext();) { 330 MatchOccurence tmpOC = it.next(); 331 // if the matchoccurence starts in a sequence that has been 332 // replaced right now we delete it 333 if (tmpOC.getStartindex() > startindex 334 && tmpOC.getStartindex() < endindex) { 335 it.remove(); 336 } else if (tmpOC.getStartindex() > endindex) { 337 int diff = endindex-startindex; 338 // Just to be sure. 339 if (diff > 0) { 340 System.out.println("Old index: Start: " 341 + tmpOC.getStartindex() + " End " 342 + tmpOC.getEndindex()); 343 tmpOC.setStartindex(tmpOC.getStartindex() - diff + 1); 344 tmpOC.setEndindex(tmpOC.getEndindex() - diff + 1); 345 System.out.println("Updated index: Start: " 346 + tmpOC.getStartindex() + " End " 347 + tmpOC.getEndindex()); 348 } else { 349 Console.traceln(Level.WARNING, 350 "End index of a Match before start. This should never happen"); 351 } 352 } 353 } 354 } 375 355 } 376 356 … … 422 402 appData.getNumber2Task().put(templist.getSequence()[i], 423 403 taskInstance.getTask()); 424 425 // if(j==1) {426 // 427 // 428 // 429 // }430 404 405 // if(j==1) { 406 // System.out.println(i + ": TaskID: " + 407 // taskInstance.getTask().getId()+ " Numbersequence: " + 408 // templist.getSequence()[i]); 409 // } 410 431 411 } 432 412 // Each NumberSequence is identified by its id, beginning to count
Note: See TracChangeset
for help on using the changeset viewer.