Changeset 1662


Ignore:
Timestamp:
08/12/14 00:47:22 (10 years ago)
Author:
rkrimmel
Message:

Changed index updating procedure.

Location:
branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/autoquest-core-tasktrees-alignment-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequenceTest.java

    r1661 r1662  
    3737                int[] pat11 = new int[]{5,-1,-1,6}; 
    3838                int[] pat12 = new int[]{10,12,12,12};  
    39          
    40                 //int[] pat13 = new int[]{6, 0, 6, 9,-1,-1,10,0}; 
    41                 //int[] pat14 = new int[]{6,-1, 9,71,32, 5,10,0}; 
    4239                 
    4340                int[] pat13 = new int[]{6, 0, 9, 32,0,5,10,0}; 
    4441                int[] pat14 = new int[]{6,-1, 71,32,-1,5,10,0}; 
     42                 
     43                //int[] pat15 = new int[]{6, 0, 6, 9,-1,-1,10,0}; 
     44                //int[] pat16 = new int[]{6,-1, 9,71,32, 5,10,0}; 
    4545                 
    4646                NumberSequence ns = new NumberSequence(10); 
     
    125125                 
    126126                 
    127                 assertEquals(2,ns2.containsPattern(pattern3)); 
    128                 assertEquals(2,ns2.containsPattern(pattern3).size()); 
    129                 assertEquals(Integer.valueOf(3),ns.containsPattern(pattern3).get(0)); 
    130                 assertEquals(Integer.valueOf(26),ns.containsPattern(pattern3).get(1)); 
     127                assertEquals(1,ns2.containsPattern(pattern3).size()); 
     128                assertEquals(Integer.valueOf(26),ns2.containsPattern(pattern3).get(0)); 
    131129                 
    132130                 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java

    r1660 r1662  
    4545 
    4646        //Recursive check if sequence contains pattern at position i 
    47         public boolean 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) { 
    4848                 
    4949                if(p1.length==ip1) { 
     
    6969         
    7070        //Searching occurrences of pattern 
    71  
    7271        public LinkedList<Integer> containsPattern(Match pattern) { 
    7372                LinkedList<Integer> result = new LinkedList<Integer>(); 
     
    7877                while (i < sequence.length ) { 
    7978                        if(matches(i,pat1,pat2,0,0)) { 
    80                                 System.out.println(i); 
    8179                                result.add(i); 
    82                                 System.out.println("FOUND MATCH AT: " + i); 
    83                                 this.printSequence(); 
    84                                 pattern.getFirstSequence().printSequence(); 
    85                                 pattern.getSecondSequence().printSequence(); 
    8680                        } 
    8781                        i++; 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java

    r1657 r1662  
    232232                        } 
    233233                }; 
    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); 
    253235 
    254236                HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); 
     
    277259                                        System.out.println(); 
    278260 
    279                                         //System.out.println("Printing session: "); 
     261                                        // System.out.println("Printing session: "); 
    280262                                        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)); 
    282265                                        } 
    283266 
    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                                } 
    342282                        } 
    343283                } 
     
    373313 
    374314                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                } 
    375355        } 
    376356 
     
    422402                                appData.getNumber2Task().put(templist.getSequence()[i], 
    423403                                                taskInstance.getTask()); 
    424                                  
    425                                 //if(j==1) { 
    426                                 //      System.out.println(i + ": TaskID: " + 
    427                                 //      taskInstance.getTask().getId()+ " Numbersequence: " + 
    428                                 //      templist.getSequence()[i]); 
    429                                 //} 
    430                                  
     404 
     405                                // if(j==1) { 
     406                                // System.out.println(i + ": TaskID: " + 
     407                                // taskInstance.getTask().getId()+ " Numbersequence: " + 
     408                                // templist.getSequence()[i]); 
     409                                // } 
     410 
    431411                        } 
    432412                        // Each NumberSequence is identified by its id, beginning to count 
Note: See TracChangeset for help on using the changeset viewer.