Changeset 1675


Ignore:
Timestamp:
08/13/14 18:25:22 (10 years ago)
Author:
rkrimmel
Message:

Fixed first iteration of sequence detection and replacement

Location:
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java

    r1620 r1675  
    5555                                eti1 = (IEventTaskInstance) obj1; 
    5656                        } 
     57                        else { 
     58                                //System.out.println("Not an EventTaskInstance"); 
     59                                continue; 
     60                        } 
    5761                 
    5862                        for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() 
     
    6266                                if (obj2 instanceof IEventTaskInstance) { 
    6367                                        eti2 = (IEventTaskInstance) obj2; 
     68                                } 
     69                                else{ 
     70                                        //System.out.println("Not an EventtaskInstance"); 
     71                                        continue; 
    6472                                } 
    6573                                IGUIElement first = (IGUIElement) eti1.getEvent().getTarget(); 
     
    102110                        } 
    103111                } 
    104                  
    105                 //System.out.println(meandistance/(uniqueTasks.size()*uniqueTasks.size())); 
    106                 //System.out.println(idmapping.toString()); 
    107                 //System.out.println(matrix.toString()); 
    108                 //System.out.println("ObjectDistanceMatrix: MaxDistance: " + maxDistance); 
    109                 //System.out.println(idmapping.keySet().toString()); 
    110                 //System.out.println(idmapping.values().toString()); 
    111                  
    112112        } 
    113113         
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java

    r1666 r1675  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
    17 import java.util.Iterator; 
    18  
    19 import org.apache.commons.lang.NotImplementedException; 
    20  
     17import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     19import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2120import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    2221import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     
    129128                                                 
    130129                                        if(((IMarkingTemporalRelationship) tempTask).getMarkedTask() == parent.get(startIndex).getTask()) { 
    131                                                 //System.out.println("Adding OptionalInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
     130                                                System.out.println("Adding OptionalInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    132131                                                IOptionalInstance optional = taskFactory.createNewTaskInstance((IOptional) tempTask); 
    133132                                                taskBuilder.setChild(optional, parent.get(startIndex)); 
     
    135134                                        } 
    136135                                        else { 
    137                                                 //System.out.println("Adding Empty optional, not deleting anything from the input sequence"); 
     136                                                System.out.println("Adding Empty optional, not deleting anything from the input sequence"); 
    138137                                                IOptionalInstance optional = taskFactory.createNewTaskInstance((IOptional) tempTask); 
    139138                                                taskBuilder.addChild(subsequence, optional); 
     
    143142                                        }                                
    144143                        } else if (tempTask.getType() == "selection") { 
    145                                 //System.out.println("Adding SelectionInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
     144                                System.out.println("Adding SelectionInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    146145                                ISelectionInstance selection = taskFactory.createNewTaskInstance((ISelection) tempTask); 
    147146                                taskBuilder.setChild(selection, parent.get(startIndex) ); 
     
    149148 
    150149                        } else if (tempTask.getType() == "sequence") { 
    151                                 //System.out.println("Adding SequenceInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    152                                 //TODO: Implement this 
    153                                 throw new NotImplementedException(); 
     150                                System.out.println("Adding SequenceInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
     151                                ISequenceInstance sequence = taskFactory.createNewTaskInstance((ISequence) tempTask); 
     152                                taskBuilder.addChild(sequence,parent.get(startIndex)); 
    154153                                 
    155154                        } else if (tempTask.getType() == "iteration") { 
    156                                 //TODO: Implement this 
    157                                 //System.out.println("Adding IterationInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    158                                 throw new NotImplementedException(); 
     155                                IIterationInstance iteration = taskFactory.createNewTaskInstance((IIteration) tempTask); 
     156                                taskBuilder.addChild(iteration,parent.get(startIndex)); 
     157                                System.out.println("Adding IterationInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    159158                        } else { 
    160                                 //System.out.println("Adding EventInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
     159                                System.out.println("Adding EventInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    161160                                taskBuilder.addChild(subsequence, parent.get(startIndex)); 
    162161                        } 
     
    164163                        modelindex++; 
    165164                } 
    166                 /* 
    167                 System.out.println(); 
    168                 System.out.println("Sequence instance:"); 
    169                 for(Iterator<ITaskInstance> it = subsequence.iterator();it.hasNext();) { 
    170                         System.out.println(it.next()); 
    171                 }*/ 
    172                 //System.out.println(); 
    173                 //System.out.println(); 
    174165                 
    175166                taskBuilder.addTaskInstance(parent, startIndex, subsequence); 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java

    r1669 r1675  
    4545import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
    4646import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    47 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
    4847import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    4948import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; 
     
    148147                RuleApplicationData appData = new RuleApplicationData(sessions); 
    149148 
    150  
    151149                harmonizeEventTaskInstancesModel(appData); 
    152  
     150                appData.detectedAndReplacedTasks = false; 
    153151                do { 
    154152 
    155153                        appData.getStopWatch().start("whole loop"); // 
    156                         //detectAndReplaceIterations(appData); 
     154                        // detectAndReplaceIterations(appData); 
    157155                        appData.getStopWatch().start("task replacement"); // 
    158156                        detectAndReplaceTasks(appData); // 
     
    179177        } 
    180178 
    181          
     179        private ArrayList<NumberSequence> createNumberSequences( 
     180                        RuleApplicationData appData) { 
     181                ArrayList<NumberSequence> result = new ArrayList<NumberSequence>(); 
     182                for (int i = 0; i < appData.getSessions().size(); i++) { 
     183                        IUserSession session = appData.getSessions().get(i); 
     184                        NumberSequence templist = new NumberSequence(session.size()); 
     185                        for (int j = 0; j < session.size(); j++) { 
     186                                ITaskInstance taskInstance = session.get(j); 
     187                                templist.getSequence()[j] = taskInstance.getTask().getId(); 
     188                                appData.getNumber2Task().put(templist.getSequence()[j], 
     189                                                taskInstance.getTask()); 
     190                        } 
     191                        // Each NumberSequence is identified by its id, beginning to count 
     192                        // at zero 
     193                        templist.setId(i); 
     194                        result.add(templist); 
     195                } 
     196                return result; 
     197        } 
     198 
    182199        /** 
    183200         * <p> 
     
    193210         * @return Returns the unique tasks symbol map 
    194211         */ 
    195         private void harmonizeEventTaskInstancesModel( 
    196                         RuleApplicationData appData) { 
     212        private void harmonizeEventTaskInstancesModel(RuleApplicationData appData) { 
    197213                Console.traceln(Level.INFO, 
    198214                                "harmonizing task model of event task instances"); 
    199215                appData.getStopWatch().start("harmonizing event tasks"); 
    200                  
    201                 appData.uniqueTasks = preparationTaskHandlingStrategy 
    202                                 .createSymbolMap(); 
    203                  
     216 
     217                appData.uniqueTasks = preparationTaskHandlingStrategy.createSymbolMap(); 
     218 
    204219                TaskInstanceComparator comparator = preparationTaskHandlingStrategy 
    205220                                .getTaskComparator(); 
     
    218233 
    219234                                if (task == null) { 
    220                                         appData.getUniqueTasks().addSymbol(taskInstance, taskInstance.getTask()); 
    221                                         templist.getSequence()[i] = taskInstance.getTask().getId(); 
    222  
     235                                        appData.getUniqueTasks().addSymbol(taskInstance, 
     236                                                        taskInstance.getTask()); 
    223237                                } else { 
    224238                                        taskBuilder.setTask(taskInstance, task); 
    225                                         templist.getSequence()[i] = task.getId(); 
    226239                                        unifiedTasks++; 
    227240                                } 
    228                                 appData.getNumber2Task().put(templist.getSequence()[i], 
    229                                                 taskInstance.getTask()); 
    230  
    231                                 // if(j==1) { 
    232                                 // System.out.println(i + ": TaskID: " + 
    233                                 // taskInstance.getTask().getId()+ " Numbersequence: " + 
    234                                 // templist.getSequence()[i]); 
    235                                 // } 
    236  
    237                         } 
    238                         // Each NumberSequence is identified by its id, beginning to count 
    239                         // at zero 
    240                         templist.setId(j); 
    241                         appData.getNumberSequences().add(templist); 
     241                        } 
    242242                        comparator.clearBuffers(); 
    243243                } 
     
    330330 
    331331                for (ITask iteratedTask : iteratedTasks) { 
    332                          
    333                         //TODO: Add this to uniqueTasks and number2task 
     332 
     333                        // TODO: Check if this is correct 
    334334                        IIteration iteration = taskFactory.createNewIteration(); 
     335                        appData.getUniqueTasks().addSymbol( 
     336                                        taskFactory.createNewTaskInstance(iteration), iteration); 
     337                        appData.getNumber2Task().put(iteration.getId(), iteration); 
    335338                        iterations.put(iteratedTask, iteration); 
    336339                        iterationInstances.put(iteration, 
     
    406409                        else if (first[i] == -1 && second[i] != -1) { 
    407410                                IOptional optional = taskFactory.createNewOptional(); 
     411                                appData.uniqueTasks.addSymbol( 
     412                                                taskFactory.createNewTaskInstance(optional), optional); 
     413                                appData.number2task.put(optional.getId(), optional); 
    408414                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 
    409415                                                .get(second[i])); 
     
    414420                        else if (first[i] != -1 && second[i] == -1) { 
    415421                                IOptional optional = taskFactory.createNewOptional(); 
     422                                appData.uniqueTasks.addSymbol( 
     423                                                taskFactory.createNewTaskInstance(optional), optional); 
     424                                appData.number2task.put(optional.getId(), optional); 
    416425                                taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 
    417426                                                .get(first[i])); 
    418427                                taskBuilder.addChild(sequence, optional); 
    419428                        } 
    420                         // Both tasks are unequal, we need to insert a selection here 
     429                        // Both tasks are not equal, we need to insert a selection here 
    421430                        else { 
     431                                System.out.println("First: " + first[i] + " Second: " + second[i]); 
    422432                                ISelection selection = taskFactory.createNewSelection(); 
     433                                appData.uniqueTasks 
     434                                                .addSymbol( 
     435                                                                taskFactory.createNewTaskInstance(selection), 
     436                                                                selection); 
     437                                appData.number2task.put(selection.getId(), selection); 
    423438                                taskBuilder.addChild(selection, 
    424439                                                appData.getNumber2Task().get(first[i])); 
     
    517532                appData.getStopWatch().start("detecting tasks"); 
    518533 
    519                  
     534                // Create NumberSequences 
     535                appData.setNumberSequences(this.createNumberSequences(appData)); 
     536 
    520537                // Generate a substitution matrix between all occurring events. 
    521                                 Console.traceln(Level.INFO, "generating substitution matrix"); 
    522                                 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 
    523                                                 appData.getUniqueTasks(), 6, -3); 
    524                                 submat.generate(); 
    525  
    526                                 // Generate pairwise alignments 
    527                                 Console.traceln(Level.INFO, "generating pairwise alignments"); 
    528                                 LinkedList<Match> matchseqs = new LinkedList<Match>(); 
    529                                 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 
    530                                                 .generate(appData.getNumberSequences(), submat, 9); 
    531  
    532                                 // Retrieve all matches reached a specific threshold 
    533                                 Console.traceln(Level.INFO, "retrieving significant sequence pieces"); 
    534                                 for (int i = 0; i < appData.getNumberSequences().size(); i++) { 
    535                                         Console.traceln( 
    536                                                         Level.FINEST, 
    537                                                         "retrieving significant sequence pieces:  " 
    538                                                                         + Math.round((float) i 
    539                                                                                         / (float) appData.getNumberSequences() 
    540                                                                                                         .size() * 100) + "%"); 
    541                                         for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
    542                                                 if (i != j) { 
    543                                                         matchseqs.addAll(alignments.get(i, j).getMatches()); 
     538                Console.traceln(Level.INFO, "generating substitution matrix"); 
     539                ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 
     540                                appData.getUniqueTasks(), 6, -3); 
     541                submat.generate(); 
     542 
     543                // Generate pairwise alignments 
     544                Console.traceln(Level.INFO, "generating pairwise alignments"); 
     545                LinkedList<Match> matchseqs = new LinkedList<Match>(); 
     546                PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 
     547                                .generate(appData.getNumberSequences(), submat, 9); 
     548 
     549                // Retrieve all matches reached a specific threshold 
     550                Console.traceln(Level.INFO, "retrieving significant sequence pieces"); 
     551                for (int i = 0; i < appData.getNumberSequences().size(); i++) { 
     552                        Console.traceln( 
     553                                        Level.FINEST, 
     554                                        "retrieving significant sequence pieces:  " 
     555                                                        + Math.round((float) i 
     556                                                                        / (float) appData.getNumberSequences() 
     557                                                                                        .size() * 100) + "%"); 
     558                        for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
     559                                if (i != j) { 
     560                                        matchseqs.addAll(alignments.get(i, j).getMatches()); 
     561                                } 
     562                        } 
     563                } 
     564                if (matchseqs.size() > 0) { 
     565                        appData.detectedAndReplacedTasks = true; 
     566                } 
     567                Console.traceln(Level.FINEST, 
     568                                "retrieving significant sequence pieces:  100%"); 
     569                Console.traceln(Level.INFO, "searching for patterns occuring most"); 
     570 
     571                // search each match in every other sequence 
     572                for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 
     573                        Match pattern = it.next(); 
     574 
     575                        // Skip sequences with more 0 events (scrolls) than other events. 
     576                        // Both of the pattern sequences are equally long, so the zero 
     577                        // counts just need to be smaller than the length of one sequence 
     578                        if (pattern.getFirstSequence().eventCount(0) 
     579                                        + pattern.getSecondSequence().eventCount(0) + 1 > pattern 
     580                                        .getFirstSequence().size()) 
     581                                continue; 
     582 
     583                        for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
     584                                LinkedList<Integer> startpositions = appData 
     585                                                .getNumberSequences().get(j).containsPattern(pattern); 
     586                                if (startpositions.size() > 0) { 
     587                                        for (Iterator<Integer> jt = startpositions.iterator(); jt 
     588                                                        .hasNext();) { 
     589                                                int start = jt.next(); 
     590                                                pattern.addOccurence(new MatchOccurence(start, start 
     591                                                                + pattern.size(), j)); 
     592                                        } 
     593 
     594                                } 
     595                        } 
     596                } 
     597 
     598                Console.traceln(Level.INFO, "sorting results"); 
     599                // Sort results to get the most occurring results 
     600                Comparator<Match> comparator = new Comparator<Match>() { 
     601                        public int compare(Match m1, Match m2) { 
     602                                return m2.occurenceCount() - m1.occurenceCount(); 
     603 
     604                        } 
     605                }; 
     606                Collections.sort(matchseqs, comparator); 
     607                appData.getStopWatch().stop("detecting tasks"); 
     608 
     609                appData.getStopWatch().start("replacing tasks"); 
     610                HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); 
     611                // Replace matches in the sessions 
     612                for (int i = 0; i < matchseqs.size(); i++) { 
     613                        // Every pattern consists of 2 sequences, therefore the minimum 
     614                        // occurrences here is 2. 
     615                        // We just need the sequences also occurring in other sequences as 
     616                        // well 
     617                        if (matchseqs.get(i).occurenceCount() > 2) { 
     618 
     619                                ISequence task = matchAsSequence(appData, matchseqs.get(i)); 
     620                                invalidOccurence: for (Iterator<MatchOccurence> it = matchseqs 
     621                                                .get(i).getOccurences().iterator(); it.hasNext();) { 
     622                                        MatchOccurence oc = it.next(); 
     623 
     624                                        /* 
     625                                         * System.out.println("Trying to replace sequence: "); 
     626                                         * matchseqs.get(i).getFirstSequence().printSequence(); 
     627                                         * matchseqs.get(i).getSecondSequence().printSequence(); 
     628                                         * System.out.println(" in session number: " + 
     629                                         * (oc.getSequenceId() + 1) + " at position " + 
     630                                         * (oc.getStartindex()) + "-" + oc.getEndindex()); 
     631                                         * System.out.println(); 
     632                                         */ 
     633 
     634                                        // System.out.println("Printing session: "); 
     635                                        // for (int j = 0; j < 
     636                                        // appData.getSessions().get(oc.getSequenceId()).size(); 
     637                                        // j++) { 
     638                                        // System.out.println(j + ": " 
     639                                        // + appData.getSessions().get(oc.getSequenceId()).get(j)); 
     640                                        // } 
     641 
     642                                        // Check if nothing has been replaced in the sequence we 
     643                                        // want to replace 
     644                                        if (replacedOccurences.get(oc.getSequenceId()) == null) { 
     645                                                replacedOccurences.put(oc.getSequenceId(), 
     646                                                                new LinkedList<MatchOccurence>()); 
     647                                        } else { 
     648                                                // check if we have any replaced occurence with indexes 
     649                                                // smaller than ours. If so, we need to adjust our start 
     650                                                // and endpoints 
     651                                                // of the replacement. 
     652                                                // Also do a check if we have replaced this specific 
     653                                                // MatchOccurence in this sequence already. Jump to the 
     654                                                // next occurence if this is the case. 
     655                                                // This is no more neccessary once the matches are 
     656                                                // harmonized. 
     657                                                for (Iterator<MatchOccurence> jt = replacedOccurences 
     658                                                                .get(oc.getSequenceId()).iterator(); jt 
     659                                                                .hasNext();) { 
     660                                                        MatchOccurence tmpOC = jt.next(); 
     661 
     662                                                        if (oc.getStartindex() >= tmpOC.getStartindex() 
     663                                                                        && oc.getStartindex() <= tmpOC 
     664                                                                                        .getEndindex()) { 
     665                                                                continue invalidOccurence; 
     666                                                        } 
     667                                                        if (oc.getEndindex() >= tmpOC.getStartindex()) { 
     668                                                                continue invalidOccurence; 
     669 
     670                                                        } else if (oc.getStartindex() > tmpOC.getEndindex()) { 
     671                                                                int diff = tmpOC.getEndindex() 
     672                                                                                - tmpOC.getStartindex(); 
     673                                                                // Just to be sure. 
     674                                                                if (diff > 0) { 
     675                                                                        oc.setStartindex(oc.getStartindex() - diff 
     676                                                                                        + 1); 
     677                                                                        oc.setEndindex(oc.getEndindex() - diff + 1); 
     678                                                                } else { 
     679                                                                        Console.traceln(Level.WARNING, 
     680                                                                                        "End index of a Match before start. This should never happen"); 
     681                                                                } 
     682                                                        } 
    544683                                                } 
    545684                                        } 
    546                                 } 
    547                                 Console.traceln(Level.FINEST, 
    548                                                 "retrieving significant sequence pieces:  100%"); 
    549                                 Console.traceln(Level.INFO, "searching for patterns occuring most"); 
    550  
    551                                 // search each match in every other sequence 
    552                                 for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 
    553                                         Match pattern = it.next(); 
    554  
    555                                         // Skip sequences with more 0 events (scrolls) than other events. 
    556                                         // Both of the pattern sequences are equally long, so the zero 
    557                                         // counts just need to be smaller than the length of one sequence 
    558                                         if (pattern.getFirstSequence().eventCount(0) 
    559                                                         + pattern.getSecondSequence().eventCount(0) + 1 > pattern 
    560                                                         .getFirstSequence().size()) 
    561                                                 continue; 
    562  
    563                                         for (int j = 0; j < appData.getNumberSequences().size(); j++) { 
    564                                                 LinkedList<Integer> startpositions = appData 
    565                                                                 .getNumberSequences().get(j).containsPattern(pattern); 
    566                                                 if (startpositions.size() > 0) { 
    567                                                         for (Iterator<Integer> jt = startpositions.iterator(); jt 
    568                                                                         .hasNext();) { 
    569                                                                 int start = jt.next(); 
    570                                                                 pattern.addOccurence(new MatchOccurence(start, start 
    571                                                                                 + pattern.size(), j)); 
    572                                                         } 
    573  
    574                                                 } 
    575                                         } 
    576                                 } 
    577  
    578                                 Console.traceln(Level.INFO, "sorting results"); 
    579                                 // Sort results to get the most occurring results 
    580                                 Comparator<Match> comparator = new Comparator<Match>() { 
    581                                         public int compare(Match m1, Match m2) { 
    582                                                 return m2.occurenceCount() - m1.occurenceCount(); 
    583  
    584                                         } 
    585                                 }; 
    586                                 Collections.sort(matchseqs, comparator); 
    587                                 appData.getStopWatch().stop("detecting tasks"); 
    588                                  
    589                                 appData.getStopWatch().start("replacing tasks"); 
    590                                 HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); 
    591                                 // Replace matches in the sessions 
    592                                 for (int i = 0; i < matchseqs.size(); i++) { 
    593                                         // Every pattern consists of 2 sequences, therefore the minimum 
    594                                         // occurrences here is 2. 
    595                                         // We just need the sequences also occurring in other sequences as 
    596                                         // well 
    597                                         if (matchseqs.get(i).occurenceCount() > 2) { 
    598  
    599                                                 ISequence task = matchAsSequence(appData, matchseqs.get(i)); 
    600                                                 invalidOccurence: for (Iterator<MatchOccurence> it = matchseqs 
    601                                                                 .get(i).getOccurences().iterator(); it.hasNext();) { 
    602                                                         MatchOccurence oc = it.next(); 
    603                                                         /* 
    604                                                         System.out.println("Trying to replace sequence: "); 
    605                                                         matchseqs.get(i).getFirstSequence().printSequence(); 
    606                                                         matchseqs.get(i).getSecondSequence().printSequence(); 
    607                                                         System.out.println(" in session number: " 
    608                                                                         + (oc.getSequenceId() + 1) 
    609                                                                         + " at position " 
    610                                                                         + (oc.getStartindex()) 
    611                                                                         + "-" 
    612                                                                         + oc.getEndindex()); 
    613                                                         System.out.println(); 
    614                                                         */ 
    615                                                          
    616                                                         // System.out.println("Printing session: "); 
    617                                                         //for (int j = 0; j < sessions.get(oc.getSequenceId()).size(); j++) { 
    618                                                         //      System.out.println(j + ": " 
    619                                                         //                      + sessions.get(oc.getSequenceId()).get(j)); 
    620                                                         //} 
    621  
    622                                                         // Check if nothing has been replaced in the sequence we 
    623                                                         // want to replace 
    624                                                         if (replacedOccurences.get(oc.getSequenceId()) == null) { 
    625                                                                 replacedOccurences.put(oc.getSequenceId(), 
    626                                                                                 new LinkedList<MatchOccurence>()); 
    627                                                         } else { 
    628                                                                 // check if we have any replaced occurence with indexes 
    629                                                                 // smaller than ours. If so, we need to adjust our start 
    630                                                                 // and endpoints 
    631                                                                 // of the replacement. 
    632                                                                 // Also do a check if we have replaced this specific 
    633                                                                 // MatchOccurence in this sequence already. Jump to the 
    634                                                                 // next occurence if this is the case. 
    635                                                                 // This is no more neccessary once the matches are 
    636                                                                 // harmonized. 
    637                                                                 for (Iterator<MatchOccurence> jt = replacedOccurences 
    638                                                                                 .get(oc.getSequenceId()).iterator(); jt 
    639                                                                                 .hasNext();) { 
    640                                                                         MatchOccurence tmpOC = jt.next(); 
    641                                                                          
    642                                                                         if (oc.getStartindex() >= tmpOC.getStartindex() && oc.getStartindex()<=tmpOC.getEndindex()) { 
    643                                                                                 continue invalidOccurence; 
    644                                                                         } 
    645                                                                         if (oc.getEndindex()>=tmpOC.getStartindex()) { 
    646                                                                                 continue invalidOccurence; 
    647                                                                                  
    648                                                                         } 
    649                                                                         else if (oc.getStartindex()>tmpOC.getEndindex()) { 
    650                                                                                 int diff = tmpOC.getEndindex() 
    651                                                                                                 - tmpOC.getStartindex(); 
    652                                                                                 // Just to be sure. 
    653                                                                                 if (diff > 0) { 
    654                                                                                         oc.setStartindex(oc.getStartindex() - diff+1); 
    655                                                                                         oc.setEndindex(oc.getEndindex() - diff+1); 
    656                                                                                 } else { 
    657                                                                                         Console.traceln(Level.WARNING, 
    658                                                                                                         "End index of a Match before start. This should never happen"); 
    659                                                                                 } 
    660                                                                         } 
    661                                                                 } 
    662                                                         } 
    663                                                         ISequenceInstance sequenceInstances = RuleUtils 
    664                                                                         .createNewSubSequenceInRange( 
    665                                                                                         appData.getSessions().get(oc.getSequenceId()), 
    666                                                                                         oc.getStartindex(), oc.getEndindex(), task, 
    667                                                                                         taskFactory, taskBuilder); 
    668                                                         // Adjust the length of the match regarding to the length of 
    669                                                         // instance. (OptionalInstances may be shorter) 
    670                                                         oc.setEndindex(oc.getStartindex() 
    671                                                                         + sequenceInstances.size() 
    672                                                                         - RuleUtils.missedOptionals); 
    673                                                         replacedOccurences.get(oc.getSequenceId()).add(oc); 
    674                                                 } 
    675                                         } 
    676                                 } 
    677  
    678                                 alignments = null; 
     685                                        ISequenceInstance sequenceInstances = RuleUtils 
     686                                                        .createNewSubSequenceInRange(appData.getSessions() 
     687                                                                        .get(oc.getSequenceId()), oc 
     688                                                                        .getStartindex(), oc.getEndindex(), task, 
     689                                                                        taskFactory, taskBuilder); 
     690                                        // Adjust the length of the match regarding to the length of 
     691                                        // instance. (OptionalInstances may be shorter) 
     692                                        oc.setEndindex(oc.getStartindex() 
     693                                                        + sequenceInstances.size() 
     694                                                        - RuleUtils.missedOptionals); 
     695                                        replacedOccurences.get(oc.getSequenceId()).add(oc); 
     696                                } 
     697                        } 
     698                } 
     699 
     700                alignments = null; 
     701                matchseqs = null; 
    679702                appData.getStopWatch().stop("replacing tasks"); 
    680703        } 
    681  
    682704 
    683705        /** 
     
    751773        } 
    752774 
    753          
    754775        /** 
    755776     *  
     
    758779 
    759780                private HashMap<Integer, ITask> number2task; 
    760                  
    761                 private SymbolMap<ITaskInstance, ITask> uniqueTasks;  
     781 
     782                private SymbolMap<ITaskInstance, ITask> uniqueTasks; 
    762783 
    763784                private ArrayList<NumberSequence> numberseqs; 
     
    804825                        return uniqueTasks; 
    805826                } 
    806                  
    807                 private void setUniqueTasks(SymbolMap<ITaskInstance, ITask> ut) { 
    808                         this.uniqueTasks = ut; 
    809                 } 
    810                  
     827 
     828                // private void setUniqueTasks(SymbolMap<ITaskInstance, ITask> ut) { 
     829                // this.uniqueTasks = ut; 
     830                // } 
     831 
     832                private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { 
     833                        this.numberseqs = numberseqs; 
     834                } 
     835 
    811836                private ArrayList<NumberSequence> getNumberSequences() { 
    812837                        return numberseqs; 
    813838                } 
    814  
    815839 
    816840                /** 
Note: See TracChangeset for help on using the changeset viewer.