Changeset 1127 for trunk


Ignore:
Timestamp:
03/18/13 11:54:15 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task detection
  • many performance improvements in task detection
  • improved merging of sequences using Myers diff algorithm
Location:
trunk
Files:
4 added
9 edited
9 moved

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/AbstractTemporalRelationshipTC.java

    r1106 r1127  
    184184            } 
    185185            else { 
    186                 status = RuleApplicationStatus.RULE_NOT_APPLIED; 
    187             } 
    188              
    189             assertTrue(status != RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     186                status = RuleApplicationStatus.NOT_APPLIED; 
     187            } 
     188             
     189            assertTrue(status != RuleApplicationStatus.FEASIBLE); 
    190190             
    191191            if ((result != null) && (result.getNewlyCreatedParentNodes() != null)) { 
     
    195195            } 
    196196             
    197             if (status == RuleApplicationStatus.RULE_NOT_APPLIED) { 
     197            if (status == RuleApplicationStatus.NOT_APPLIED) { 
    198198                toBeAppliedOn.pop(); 
    199199            } 
    200200             
    201201        } 
    202         while ((!toBeAppliedOn.isEmpty()) || 
    203                (status == RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 
     202        while ((!toBeAppliedOn.isEmpty()) || (status == RuleApplicationStatus.FINISHED)); 
    204203 
    205204        return taskTreeNodeFactory.createTaskTree(sequence); 
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/IterationOfSubtreesDetectionRuleTest.java

    r1106 r1127  
    2929 * @author 2012, last modified by $Author: patrick$ 
    3030 */ 
    31 public class DefaultIterationDetectionRuleTest extends AbstractTemporalRelationshipTC { 
     31public class IterationOfSubtreesDetectionRuleTest extends AbstractTemporalRelationshipTC { 
    3232 
    3333    /** 
     
    4242            ("Sequence sequence1 {" + 
    4343             "  Event bla {}" + 
    44              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
    45  
    46         simulateEvent(event1, element1); 
    47         new TaskTreeChecker().assertTaskTree 
    48             ("Sequence sequence1 {" + 
    49              "  Iteration iteration1 {" + 
    50              "    Event bla {}" + 
    51              "  }" + 
    52              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
    53  
    54         simulateEvent(event1, element1); 
    55         new TaskTreeChecker().assertTaskTree 
    56             ("Sequence sequence1 {" + 
    57              "  Iteration iteration1 {" + 
    58              "    Event bla {}" + 
    59              "  }" + 
    60              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     44             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
     45 
     46        simulateEvent(event1, element1); 
     47        new TaskTreeChecker().assertTaskTree 
     48            ("Sequence sequence1 {" + 
     49             "  Iteration iteration1 {" + 
     50             "    Event bla {}" + 
     51             "  }" + 
     52             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
     53 
     54        simulateEvent(event1, element1); 
     55        new TaskTreeChecker().assertTaskTree 
     56            ("Sequence sequence1 {" + 
     57             "  Iteration iteration1 {" + 
     58             "    Event bla {}" + 
     59             "  }" + 
     60             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    6161 
    6262        for (int i = 0; i < 10; i++) { 
     
    6969             "    Event bla {}" + 
    7070             "  }" + 
    71              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     71             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    7272 
    7373        // now test with preceding and trailing other events 
     
    9595             "  Event blup {}" + 
    9696             "  Event bli {}" + 
    97              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     97             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    9898 
    9999        // now test with iterations of iterations 
     
    136136             "    }" + 
    137137             "  }" + 
    138              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     138             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    139139 
    140140    } 
     
    157157             "  Event bli {}" + 
    158158             "  Event blup {}" + 
    159              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
    160  
    161         simulateEvent(event1, element1); 
    162         simulateEvent(event2, element1); 
    163         simulateEvent(event3, element1); 
    164         new TaskTreeChecker().assertTaskTree 
    165             ("Sequence sequence1 {" + 
    166              "  Iteration iteration1 {" + 
    167              "    Sequence sequence2 {" + 
    168              "      Event bla {}" + 
    169              "      Event bli {}" + 
    170              "      Event blup {}" + 
    171              "    }" + 
    172              "  }" + 
    173              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
    174  
    175         simulateEvent(event1, element1); 
    176         simulateEvent(event2, element1); 
    177         simulateEvent(event3, element1); 
    178         new TaskTreeChecker().assertTaskTree 
    179             ("Sequence sequence1 {" + 
    180              "  Iteration iteration1 {" + 
    181              "    Sequence sequence2 {" + 
    182              "      Event bla {}" + 
    183              "      Event bli {}" + 
    184              "      Event blup {}" + 
    185              "    }" + 
    186              "  }" + 
    187              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     159             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
     160 
     161        simulateEvent(event1, element1); 
     162        simulateEvent(event2, element1); 
     163        simulateEvent(event3, element1); 
     164        new TaskTreeChecker().assertTaskTree 
     165            ("Sequence sequence1 {" + 
     166             "  Iteration iteration1 {" + 
     167             "    Sequence sequence2 {" + 
     168             "      Event bla {}" + 
     169             "      Event bli {}" + 
     170             "      Event blup {}" + 
     171             "    }" + 
     172             "  }" + 
     173             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
     174 
     175        simulateEvent(event1, element1); 
     176        simulateEvent(event2, element1); 
     177        simulateEvent(event3, element1); 
     178        new TaskTreeChecker().assertTaskTree 
     179            ("Sequence sequence1 {" + 
     180             "  Iteration iteration1 {" + 
     181             "    Sequence sequence2 {" + 
     182             "      Event bla {}" + 
     183             "      Event bli {}" + 
     184             "      Event blup {}" + 
     185             "    }" + 
     186             "  }" + 
     187             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    188188 
    189189        for (int i = 0; i < 10; i++) { 
     
    202202             "    }" + 
    203203             "  }" + 
    204              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     204             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    205205 
    206206        // now test with preceding and trailing other events 
     
    242242             "  Event blo {}" + 
    243243             "  Event ble {}" + 
    244              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     244             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    245245 
    246246        // now test with iterations of iterations 
     
    310310             "    }" + 
    311311             "  }" + 
    312              "}", getTaskTree(DefaultIterationDetectionRule.class, null)); 
     312             "}", getTaskTree(IterationOfSubtreesDetectionRule.class, null)); 
    313313    } 
    314314 
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceDependingOnEventTypeDetectionRuleTest.java

    r1106 r1127  
    2828 * @author 2011, last modified by $Author: $ 
    2929 */ 
    30 public class DefaultGuiEventSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC { 
     30public class SequenceDependingOnEventTypeDetectionRuleTest extends AbstractTemporalRelationshipTC { 
    3131     
    3232    /** 
     
    4343             "  Event start {}" + 
    4444             "  Event end {}" + 
    45              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     45             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    4646    } 
    4747     
     
    6262             "  Event bla {}" + 
    6363             "  Event end {}" + 
    64              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     64             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    6565    } 
    6666     
     
    9696             "    Event end {}" + 
    9797             "  }" + 
    98              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     98             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    9999    } 
    100100     
     
    128128             "  }" + 
    129129             "  Event startFinish {}" + 
    130              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     130             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    131131    } 
    132132 
     
    190190             "  }" + 
    191191             "  Event finish {}" + 
    192              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     192             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    193193    } 
    194194 
     
    260260             "  }" + 
    261261             "  Event finish {}" + 
    262              "}", getTaskTree(DefaultGuiEventSequenceDetectionRule.class, null)); 
     262             "}", getTaskTree(SequenceDependingOnEventTypeDetectionRule.class, null)); 
    263263    } 
    264264     
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleTest.java

    r1109 r1127  
    2020import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 
    2121import de.ugoe.cs.autoquest.tasktrees.TaskTreeChecker; 
     22import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    2223import de.ugoe.cs.autoquest.test.DummyGUIElement; 
    2324import de.ugoe.cs.autoquest.test.DummyInteraction; 
     
    2930 * @author 2012, last modified by $Author: patrick$ 
    3031 */ 
    31 public class DefaultTaskSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC { 
     32public class SequenceForTaskDetectionRuleTest extends AbstractTemporalRelationshipTC { 
    3233 
    3334    /** 
     
    6566        simulateEvent(new DummyInteraction("noise8", 1), element1); 
    6667         
    67         new TaskTreeChecker().assertTaskTree 
    68             ("Sequence sequence1 {" + 
    69              "  Event noise0 {}" + 
    70              "  Sequence sequence2 {" + 
    71              "    Event action1 {}" + 
    72              "    Event action2 {}" + 
    73              "    Event action3 {}" + 
    74              "    Event action4 {}" + 
     68        new TaskTreeChecker(true).assertTaskTree 
     69            ("Sequence root {" + 
     70             "  Sequence session1 {" + 
     71             "    Event noise0 {}" + 
     72             "    Sequence sequence2 {" + 
     73             "      Event action1 {}" + 
     74             "      Event action2 {}" + 
     75             "      Event action3 {}" + 
     76             "      Event action4 {}" + 
     77             "    }" + 
     78             "    Event noise1 {}" + 
     79             "    Event noise2 {}" + 
     80             "    Sequence sequence2 {" + 
     81             "      Event action1 {}" + 
     82             "      Event action2 {}" + 
     83             "      Event action3 {}" + 
     84             "      Event action4 {}" + 
     85             "    }" + 
     86             "    Event noise3 {}" + 
     87             "    Event noise4 {}" + 
     88             "    Event noise5 {}" + 
     89             "    Event noise6 {}" + 
     90             "    Sequence sequence2 {" + 
     91             "      Event action1 {}" + 
     92             "      Event action2 {}" + 
     93             "      Event action3 {}" + 
     94             "      Event action4 {}" + 
     95             "    }" + 
     96             "    Event noise7 {}" + 
     97             "    Event noise8 {}" + 
    7598             "  }" + 
    76              "  Event noise1 {}" + 
    77              "  Event noise2 {}" + 
    78              "  Sequence sequence2 {" + 
    79              "    Event action1 {}" + 
    80              "    Event action2 {}" + 
    81              "    Event action3 {}" + 
    82              "    Event action4 {}" + 
    83              "  }" + 
    84              "  Event noise3 {}" + 
    85              "  Event noise4 {}" + 
    86              "  Event noise5 {}" + 
    87              "  Event noise6 {}" + 
    88              "  Sequence sequence2 {" + 
    89              "    Event action1 {}" + 
    90              "    Event action2 {}" + 
    91              "    Event action3 {}" + 
    92              "    Event action4 {}" + 
    93              "  }" + 
    94              "  Event noise7 {}" + 
    95              "  Event noise8 {}" + 
    96              "}", getTaskTree()); 
     99             "}", getTaskTree(SequenceForTaskDetectionRule.class, NodeEquality.LEXICALLY_EQUAL)); 
    97100 
    98101    } 
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceOnGuiElementDetectionRuleTest.java

    r1106 r1127  
    2828 * @author 2011, last modified by $Author: $ 
    2929 */ 
    30 public class DefaultGuiElementSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC { 
     30public class SequenceOnGuiElementDetectionRuleTest extends AbstractTemporalRelationshipTC { 
    3131     
    3232    /** 
     
    6262             "  Event blu {}" + 
    6363             "  Event bla {}" + 
    64              "}", getTaskTree(DefaultGuiElementSequenceDetectionRule.class, null)); 
     64             "}", getTaskTree(SequenceOnGuiElementDetectionRule.class, null)); 
    6565    } 
    6666 
     
    103103             "    Event bla {}" + 
    104104             "  }" + 
    105              "}", getTaskTree(DefaultGuiElementSequenceDetectionRule.class, null)); 
     105             "}", getTaskTree(SequenceOnGuiElementDetectionRule.class, null)); 
    106106    } 
    107107 
     
    162162             "    Event blo {}" + 
    163163             "  }" + 
    164              "}", getTaskTree(DefaultGuiElementSequenceDetectionRule.class, null)); 
     164             "}", getTaskTree(SequenceOnGuiElementDetectionRule.class, null)); 
    165165    } 
    166166 
     
    233233             "    }" + 
    234234             "  }" + 
    235              "}", getTaskTree(DefaultGuiElementSequenceDetectionRule.class, null)); 
     235             "}", getTaskTree(SequenceOnGuiElementDetectionRule.class, null)); 
    236236    } 
    237237 
  • trunk/autoquest-core-tasktrees/pom.xml

    r1108 r1127  
    2828      <version>${project.parent.version}</version> 
    2929    </dependency> 
     30    <dependency> 
     31      <groupId>com.googlecode.java-diff-utils</groupId> 
     32      <artifactId>diffutils</artifactId> 
     33      <version>1.2.1</version> 
     34    </dependency> 
    3035  </dependencies> 
    3136</project> 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/IterationOfSubtreesDetectionRule.java

    r1117 r1127  
    7575 * @author Patrick Harms 
    7676 */ 
    77 class DefaultIterationDetectionRule implements TemporalRelationshipRule { 
     77class IterationOfSubtreesDetectionRule implements TemporalRelationshipRule { 
    7878 
    7979    /** 
     
    101101    /** 
    102102     * <p> 
    103      * the node equality manager needed for comparing task tree nodes with each other 
    104      * </p> 
    105      */ 
    106     private NodeEqualityRuleManager nodeEqualityRuleManager; 
    107  
    108     /** 
    109      * <p> 
    110      * the minimal node equality two identified sublists need to have to consider them as equal 
    111      * and to create an iteration for 
    112      * </p> 
    113      */ 
    114     private NodeEquality minimalNodeEquality; 
     103     * the node comparator used for comparing task tree nodes with each other 
     104     * </p> 
     105     */ 
     106    private TaskTreeNodeComparator nodeComparator; 
    115107 
    116108    /** 
     
    120112     * </p> 
    121113     */ 
    122     DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
    123                                   NodeEquality            minimalNodeEquality, 
    124                                   ITaskTreeNodeFactory    taskTreeNodeFactory, 
    125                                   ITaskTreeBuilder        taskTreeBuilder) 
     114    IterationOfSubtreesDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
     115                                     NodeEquality            minimalNodeEquality, 
     116                                     ITaskTreeNodeFactory    taskTreeNodeFactory, 
     117                                     ITaskTreeBuilder        taskTreeBuilder) 
    126118    { 
    127         this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
    128         this.minimalNodeEquality = minimalNodeEquality; 
    129119        this.taskTreeNodeFactory = taskTreeNodeFactory; 
    130120        this.taskTreeBuilder = taskTreeBuilder; 
     121         
     122        this.nodeComparator = 
     123            new TaskTreeNodeComparator(nodeEqualityRuleManager, minimalNodeEquality); 
     124    } 
     125 
     126    /** 
     127     * <p> 
     128     * instantiates the rule and initializes it with a node equality rule manager and the minimal 
     129     * node equality identified sublist must have to consider them as iterated. 
     130     * </p> 
     131     */ 
     132    IterationOfSubtreesDetectionRule(TaskTreeNodeComparator nodeComparator, 
     133                                     ITaskTreeNodeFactory   taskTreeNodeFactory, 
     134                                     ITaskTreeBuilder       taskTreeBuilder) 
     135    { 
     136        this.nodeComparator = nodeComparator; 
     137        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     138        this.taskTreeBuilder = taskTreeBuilder; 
    131139    } 
    132140 
     
    136144    @Override 
    137145    public String toString() { 
    138         return "DefaultIterationDetectionRule"; 
     146        return "IterationOfSubtreesDetectionRule"; 
    139147    } 
    140148 
     
    154162            // the rule is always feasible as iterations may occur at any time 
    155163            RuleApplicationResult result = new RuleApplicationResult(); 
    156             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     164            result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 
    157165            return result; 
    158166        } 
    159167 
     168        List<ITaskTreeNode> children = parent.getChildren(); 
     169         
    160170        // parent must already have at least 2 children 
    161         if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) { 
     171        if ((children == null) || (children.size() < 2)) { 
    162172            return null; 
    163173        } 
    164174         
    165          
    166         SubSequences subSequences = getEqualSubsequences(parent); 
     175        SubSequences subSequences = getEqualSubsequences(children); 
    167176 
    168177        if (subSequences != null) { 
    169178            RuleApplicationResult result = new RuleApplicationResult(); 
    170179 
    171             mergeEqualNodes(subSequences.equalVariants); 
     180            // merge the identified variants, but preserve the differences in form of selections 
     181            // by using lexical equality for merge comparisons 
     182            TaskTreeNodeMerger merger = new TaskTreeNodeMerger 
     183                (taskTreeNodeFactory, taskTreeBuilder, nodeComparator); 
     184 
     185            merger.mergeTaskNodes(subSequences.equalVariants); 
     186             
    172187            IIteration newIteration = 
    173188                createIterationBasedOnIdentifiedVariants(subSequences, result); 
     
    183198            taskTreeBuilder.addChild((ISequence) parent, subSequences.start, newIteration); 
    184199 
    185             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     200            result.setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
    186201            return result; 
    187202        } 
     
    193208     * <p> 
    194209     * this method initiates the trial and error algorithm denoted in the description of this class. 
    195      * Its main purpose is the selection of a subpart of all children in the parent node in which 
     210     * Its main purpose is the selection of a subpart of the provided list of nodes in which 
    196211     * equal sublists shall be searched. It is important, to always find the last iterations in a 
    197212     * part first. The reason for this are iterations of iterations. If we always found the first 
     
    202217     * </p> 
    203218     *  
    204      * @param parent      the parent node in which iterations of children shall be found 
     219     * @param nodes the list of nodes in which iterations shall be found 
    205220     *  
    206221     * @return the iterated subsequences identified in a specific part (contains the equal 
     
    208223     *         subpart in which the sequences were found)  
    209224     */ 
    210     private SubSequences getEqualSubsequences(ITaskTreeNode parent) { 
     225    private SubSequences getEqualSubsequences(List<ITaskTreeNode> nodes) { 
    211226        SubSequences subSequences = null; 
    212227 
    213228        // to find longer iterations first, start with long sequences 
    214229        FIND_ITERATION: 
    215         for (int end = parent.getChildren().size(); end > 0; end--) { 
     230        for (int end = nodes.size(); end > 0; end--) { 
    216231            for (int start = 0; start < end; start++) { 
    217                 boolean useEqualSublistLengths = equalSublistLengthsCanBeUsed(parent, start, end); 
     232                boolean useEqualSublistLengths = equalSublistLengthsCanBeUsed(nodes, start, end); 
    218233 
    219234                subSequences = new SubSequences(); 
     
    221236 
    222237                boolean foundFurtherVariants = findFurtherVariants 
    223                     (subSequences, parent, start, end, useEqualSublistLengths); 
     238                    (subSequences, nodes, start, end, useEqualSublistLengths); 
    224239 
    225240                if (foundFurtherVariants) { 
     
    239254     * for optimization purposes, we check if the length of the sublists to be identified as 
    240255     * iterations has to be the same for any sublist. This only applies, if the minimum node 
    241      * equality to be checked for is lexical equality. If the children of the parent are all event 
    242      * tasks, then sublists can only be lexically equal, if they all have the same length. 
     256     * equality to be checked for is lexical equality. If the nodes in the provided list are all 
     257     * event tasks, then sublists can only be lexically equal, if they all have the same length. 
    243258     * Therefore we check, if the minimal node equality is lexical equality. And if so, we also 
    244      * check if all children of the parent in which an iteration shall be searched for are event 
    245      * tasks. 
     259     * check if all nodes in the list in which an iteration shall be searched for are event tasks. 
    246260     * </p> 
    247261     * 
    248      * @param parent the parent node to search for iterations of its children 
     262     * @param nodes  the list of nodes to search for iterations 
    249263     * @param start  the beginning of the subpart (inclusive) to be considered 
    250264     * @param end    the end of the subpart (exclusive) to be considered 
     
    252266     * @return true, if the sublists must have the same lengths, false else 
    253267     */ 
    254     private boolean equalSublistLengthsCanBeUsed(ITaskTreeNode parent, int start, int end) { 
    255         boolean equalLengthsCanBeUsed = minimalNodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL); 
     268    private boolean equalSublistLengthsCanBeUsed(List<ITaskTreeNode> nodes, int start, int end) { 
     269        boolean equalLengthsCanBeUsed = 
     270            nodeComparator.getConsideredNodeEquality().isAtLeast(NodeEquality.LEXICALLY_EQUAL); 
    256271         
    257272        if (equalLengthsCanBeUsed) { 
    258273            for (int i = start; i < end; i++) { 
    259                 if (!(parent.getChildren().get(i) instanceof IEventTask)) { 
     274                if (!(nodes.get(i) instanceof IEventTask)) { 
    260275                    equalLengthsCanBeUsed = false; 
    261276                    break; 
     
    269284    /** 
    270285     * <p> 
    271      * this method starts at a specific position in the list of children of the provided parent 
    272      * and checks, if it finds a further sublist, that matches the already found sublists. If 
    273      * the sublist lengths must be equal, it only searches for a sublist of the same length of the 
    274      * already found sublists. The method calls itself if it identifies a further equal sublist but 
    275      * if the end of the subpart of children is not yet reached. 
     286     * this method starts at a specific position in the provided list of nodes and checks, if it 
     287     * finds a further sublist, that matches the already found sublists. If the sublist lengths 
     288     * must be equal, it only searches for a sublist of the same length of the already found 
     289     * sublists. The method calls itself if it identifies a further equal sublist but 
     290     * if the end of the subpart of the provided list is not yet reached. 
    276291     * </p> 
    277292     *  
    278293     * @param subSequences           the sublist found so far against which equality of the next 
    279294     *                               sublist must be checked 
    280      * @param parent                 the parent node of which the children are analyzed 
     295     * @param nodes                  the list of nodes to be checked for iterations 
    281296     * @param start                  the starting index from which to start the next sublist to be 
    282297     *                               identified 
    283      * @param end                    the end index (exclusive) of the current subpart of children 
    284      *                               in which iterations are searched for 
     298     * @param end                    the end index (exclusive) of the current subpart of list of 
     299     *                               nodes in which iterations are searched for 
    285300     * @param useEqualSublistLengths true if the sublists to be searched for all need to have the 
    286301     *                               same length 
     
    288303     * @return true if a further equal variant was found, false else 
    289304     */ 
    290     private boolean findFurtherVariants(SubSequences         subSequences, 
    291                                         ITaskTreeNode        parent, 
    292                                         int                  start, 
    293                                         int                  end, 
    294                                         boolean              useEqualSublistLengths) 
     305    private boolean findFurtherVariants(SubSequences        subSequences, 
     306                                        List<ITaskTreeNode> nodes, 
     307                                        int                 start, 
     308                                        int                 end, 
     309                                        boolean             useEqualSublistLengths) 
    295310    { 
    296311        boolean foundFurtherVariants = (start == end) && (subSequences.equalVariants.size() > 1); 
     
    312327             
    313328            for (int j = start; j < start + childCount; j++) { 
    314                 taskTreeBuilder.addChild(furtherVariant, parent.getChildren().get(j)); 
     329                taskTreeBuilder.addChild(furtherVariant, nodes.get(j)); 
    315330            } 
    316331             
     
    318333             
    319334            for (ITaskTreeNode equalVariant : subSequences.equalVariants) { 
    320                 NodeEquality nodeEquality = 
    321                     nodeEqualityRuleManager.applyRules(equalVariant, furtherVariant); 
    322                  
    323                 if (!nodeEquality.isAtLeast(minimalNodeEquality)) { 
     335                if (!nodeComparator.equals(equalVariant, furtherVariant)) { 
    324336                    allVariantsEqual = false; 
    325337                    break; 
     
    335347                 
    336348                foundFurtherVariants = findFurtherVariants 
    337                     (subSequences, parent, start + childCount, end, useEqualSublistLengths); 
     349                    (subSequences, nodes, start + childCount, end, useEqualSublistLengths); 
    338350 
    339351                if (foundFurtherVariants) { 
     
    348360         
    349361        return foundFurtherVariants; 
    350     } 
    351  
    352     /** 
    353      * <p> 
    354      * this method merges task tree nodes in a list, if they can be merged. for this, it tries 
    355      * to merge every node with every other node in the provided list using the 
    356      * {@link #mergeEqualTasks(ITaskTreeNode, ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory)} 
    357      * method. If a merge is possible, it removes the merged nodes from the list and adds the 
    358      * merge result.  
    359      * </p> 
    360      * 
    361      * @param nodes       the list of nodes to be merged 
    362      */ 
    363     private void mergeEqualNodes(List<ITaskTreeNode> nodes) { 
    364         int index1 = 0; 
    365         int index2 = 0; 
    366         ITaskTreeNode variant1; 
    367         ITaskTreeNode variant2; 
    368          
    369         while (index1 < nodes.size()) { 
    370             variant1 = nodes.get(index1); 
    371             index2 = index1 + 1; 
    372              
    373             while (index2 < nodes.size()) { 
    374                 variant2 = nodes.get(index2); 
    375                 ITaskTreeNode mergedChild = mergeEqualTasks(variant1, variant2); 
    376                  
    377                 if (mergedChild != null) { 
    378                     // if we merged something start from the beginning to perform the next merge 
    379                     nodes.remove(index2); 
    380                     nodes.remove(index1); 
    381                     nodes.add(index1, mergedChild); 
    382                     index1 = -1; 
    383                     break; 
    384                 } 
    385                 else { 
    386                     index2++; 
    387                 } 
    388             } 
    389              
    390             index1++; 
    391         } 
    392     } 
    393  
    394     /** 
    395      * <p> 
    396      * this method merges two equal tasks with each other if possible. If the tasks are lexically 
    397      * equal, the first of them is returned as merge result. If both tasks are of the same 
    398      * temporal relationship type, the appropriate merge method is called to merge them. If one 
    399      * of the nodes is a selection, the other one is added as a variant of this selection. 
    400      * (However, if both nodes are selections, they are merged using the appropriate merge method.) 
    401      * If merging is not possible, then a selection of both provided nodes is created and 
    402      * returned as merge result. 
    403      * </p> 
    404      * 
    405      * @param node1       the first task to be merged 
    406      * @param node2       the second task to be merged 
    407      *  
    408      * @return the result of the merge 
    409      */ 
    410     private ITaskTreeNode mergeEqualTasks(ITaskTreeNode node1, ITaskTreeNode node2) { 
    411         ITaskTreeNode mergeResult = null; 
    412          
    413         if ((node1 instanceof ISequence) && (node2 instanceof ISequence)) { 
    414             mergeResult = mergeEqualSequences((ISequence) node1, (ISequence) node2); 
    415         } 
    416         else if ((node1 instanceof ISelection) && (node2 instanceof ISelection)) { 
    417             mergeResult = mergeEqualSelections((ISelection) node1, (ISelection) node2); 
    418         } 
    419         else if ((node1 instanceof IIteration) && (node2 instanceof IIteration)) { 
    420             mergeResult = mergeEqualIterations((IIteration) node1, (IIteration) node2); 
    421         } 
    422         else if (node1 instanceof ISelection) { 
    423             taskTreeBuilder.addChild((ISelection) node1, node2); 
    424             mergeResult = node1; 
    425         } 
    426         else if (node2 instanceof ISelection) { 
    427             taskTreeBuilder.addChild((ISelection) node2, node1); 
    428             mergeResult = node2; 
    429         } 
    430         else if (node1 instanceof IIteration) { 
    431             mergeResult = mergeEqualTasks(((IIteration) node1).getChildren().get(0), node2); 
    432              
    433             if (mergeResult != null) { 
    434                 IIteration iteration = taskTreeNodeFactory.createNewIteration(); 
    435                 taskTreeBuilder.setChild(iteration, mergeResult); 
    436                 mergeResult = iteration; 
    437             } 
    438         } 
    439         else if (node2 instanceof IIteration) { 
    440             mergeResult = mergeEqualTasks(((IIteration) node2).getChildren().get(0), node1); 
    441              
    442             if (mergeResult != null) { 
    443                 IIteration iteration = taskTreeNodeFactory.createNewIteration(); 
    444                 taskTreeBuilder.setChild(iteration, mergeResult); 
    445                 mergeResult = iteration; 
    446             } 
    447         } 
    448         else { 
    449             NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(node1, node2); 
    450              
    451             if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 
    452                 mergeResult = node1; 
    453             } 
    454         } 
    455  
    456         if (mergeResult == null) { 
    457             mergeResult = taskTreeNodeFactory.createNewSelection(); 
    458             taskTreeBuilder.addChild((ISelection) mergeResult, node1); 
    459             taskTreeBuilder.addChild((ISelection) mergeResult, node2); 
    460         } 
    461          
    462         return mergeResult; 
    463     } 
    464  
    465     /** 
    466      * <p> 
    467      * merges equal sequences. This is done through trying to merge each node of sequence 1 with 
    468      * the node in sequence 2 being located at the same position. If not all children can be merged 
    469      * or if the sequences have different lengths, null is returned to indicate, that merging is 
    470      * not possible. For merging children, the 
    471      * {@link #mergeEqualTasks(ITaskTreeNode, ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory)} 
    472      * method is called. 
    473      * </p> 
    474      * 
    475      * @param sequence1   the first sequence to be merged 
    476      * @param sequence2   the second sequence to be merged 
    477      *  
    478      * @return the result of the merge or null if merging was not possible 
    479      */ 
    480     private ISequence mergeEqualSequences(ISequence sequence1, ISequence sequence2) { 
    481         ISequence mergeResult = null; 
    482          
    483         if (sequence1.getChildren().size() == sequence2.getChildren().size()) { 
    484             mergeResult = taskTreeNodeFactory.createNewSequence(); 
    485              
    486             for (int i = 0; i < sequence1.getChildren().size(); i++) { 
    487                 ITaskTreeNode mergedNode = mergeEqualTasks 
    488                     (sequence1.getChildren().get(i), sequence2.getChildren().get(i)); 
    489                  
    490                 if (mergedNode != null) { 
    491                     taskTreeBuilder.addChild(mergeResult, mergedNode); 
    492                 } 
    493                 else { 
    494                     mergeResult = null; 
    495                     break; 
    496                 } 
    497             } 
    498         } 
    499          
    500         return mergeResult; 
    501     } 
    502  
    503     /** 
    504      * <p> 
    505      * merges equal selections. This is done by adding those children of the second selection to 
    506      * the first selection that can not be merged with any of the children of the first selection. 
    507      * If a merge is possible and this merge is not a simple selection of the merged children, 
    508      * then the merged child replaces the child of the first selection which was merged. 
    509      * </p> 
    510      * 
    511      * @param selection1  the first selection to be merged 
    512      * @param selection2  the second selection to be merged 
    513      *  
    514      * @return the result of the merge which is never null 
    515      */ 
    516     private ITaskTreeNode mergeEqualSelections(ISelection selection1, ISelection selection2) { 
    517         ISelection mergeResult = selection1; 
    518          
    519         ITaskTreeNode childToMerge = null; 
    520         ITaskTreeNode mergedChild = null; 
    521          
    522         // check for each child of selection 2 if it is a duplicate of one of the children 
    523         // if selection 1. If not, add it as further child to the merge result, else skip it. 
    524         for (int i = 0; i < selection2.getChildren().size(); i++) { 
    525             childToMerge = selection2.getChildren().get(i); 
    526             for (int j = 0; j < selection1.getChildren().size(); j++) { 
    527                 mergedChild = mergeEqualTasks(selection1.getChildren().get(j), childToMerge); 
    528                  
    529                 // a merge must not be a selection, except it is one of the children. Otherwise 
    530                 // no real merge was done. 
    531                 if ((mergedChild != null) && 
    532                     ((!(mergedChild instanceof ISelection)) || 
    533                      (selection1.getChildren().get(j) == mergedChild) || 
    534                      (childToMerge == mergedChild))) 
    535                 { 
    536                     // we found a real merge. So replace the original child in selection 1 with 
    537                     // the merged child 
    538                     taskTreeBuilder.removeChild(selection1, selection1.getChildren().get(j)); 
    539                     taskTreeBuilder.addChild(selection1, mergedChild); 
    540                     mergedChild = null; 
    541                     childToMerge = null; 
    542                     break; 
    543                 } 
    544             } 
    545              
    546             if (childToMerge != null) { 
    547                 taskTreeBuilder.addChild(selection1, childToMerge); 
    548             } 
    549         } 
    550          
    551         return mergeResult; 
    552     } 
    553  
    554     /** 
    555      * <p> 
    556      * merges equal iterations. This is done through merging the children of both iterations. If 
    557      * this is possible, a resulting iteration with the merge result of the children as its own 
    558      * child is returned. Otherwise null is returned to indicate that merging was not possible. 
    559      * </p> 
    560      * 
    561      * @param selection1  the first iteration to be merged 
    562      * @param selection2  the second iteration to be merged 
    563      *  
    564      * @return the result of the merge or null if merging is not possible 
    565      */ 
    566     private ITaskTreeNode mergeEqualIterations(IIteration iteration1, IIteration iteration2) { 
    567         ITaskTreeNode mergedChild = mergeEqualTasks 
    568             (iteration1.getChildren().get(0), iteration2.getChildren().get(0)); 
    569          
    570         IIteration mergeResult = null; 
    571          
    572         if (mergedChild != null) { 
    573             mergeResult = taskTreeNodeFactory.createNewIteration(); 
    574             taskTreeBuilder.setChild(mergeResult, mergedChild); 
    575         } 
    576          
    577         return mergeResult; 
    578362    } 
    579363 
     
    691475        List<ITaskTreeNode> parentNodes = new ArrayList<ITaskTreeNode>(); 
    692476         
    693         if (subtree.getChildren().size() > 0) { 
     477        List<ITaskTreeNode> children = subtree.getChildren(); 
     478         
     479        if (children.size() > 0) { 
    694480            parentNodes.add(subtree); 
    695481             
    696             for (ITaskTreeNode child : subtree.getChildren()) { 
     482            for (ITaskTreeNode child : children) { 
    697483                parentNodes.addAll(getParentNodes(child)); 
    698484            } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleApplicationResult.java

    r1113 r1127  
    3333 
    3434    /** */ 
    35     private RuleApplicationStatus status = RuleApplicationStatus.RULE_NOT_APPLIED; 
     35    private RuleApplicationStatus status = RuleApplicationStatus.NOT_APPLIED; 
    3636 
    3737    /** */ 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleApplicationStatus.java

    r1113 r1127  
    2424 */ 
    2525enum RuleApplicationStatus { 
    26     RULE_APPLICATION_FINISHED, 
    27     RULE_APPLICATION_FEASIBLE, 
    28     RULE_NOT_APPLIED; 
     26    FINISHED, 
     27    FEASIBLE, 
     28    NOT_APPLIED; 
    2929} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java

    r1107 r1127  
    3535     *  
    3636     */ 
     37    static ISequence getSubSequenceInRange(ITaskTreeNode         parent, 
     38                                           int                   startIndex, 
     39                                           int                   endIndex, 
     40                                           String                description, 
     41                                           ITaskTreeNodeFactory  nodeFactory, 
     42                                           ITaskTreeBuilder      builder) 
     43    { 
     44        ISequence sequence = nodeFactory.createNewSequence(); 
     45        if (description != null) { 
     46            builder.setDescription(sequence, description); 
     47        } 
     48 
     49        for (int i = startIndex; i <= endIndex; i++) { 
     50            builder.addChild(sequence, parent.getChildren().get(i)); 
     51        } 
     52 
     53        return sequence; 
     54    } 
     55 
     56    /** 
     57     *  
     58     */ 
    3759    static ISequence createNewSubSequenceInRange(ITaskTreeNode         parent, 
    3860                                                 int                   startIndex, 
     
    6082     * 
    6183     */ 
    62     public static synchronized String getNewId() { 
     84    static synchronized String getNewId() { 
    6385        return Integer.toString(idCounter++); 
    6486    } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceDependingOnEventTypeDetectionRule.java

    r1117 r1127  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
     17import java.util.List; 
    1718import java.util.Stack; 
    1819 
     
    3435 * @author 2012, last modified by $Author: patrick$ 
    3536 */ 
    36 class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 
     37class SequenceDependingOnEventTypeDetectionRule implements TemporalRelationshipRule { 
    3738 
    3839    /** 
     
    6364     *                            the temporal relationships identified during rule application 
    6465     */ 
    65     DefaultGuiEventSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
    66                                          ITaskTreeBuilder     taskTreeBuilder) 
     66    SequenceDependingOnEventTypeDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     67                                              ITaskTreeBuilder     taskTreeBuilder) 
    6768    { 
    6869        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     
    7576    @Override 
    7677    public String toString() { 
    77         return "DefaultGuiEventSequenceDetectionRule"; 
     78        return "SequenceDependingOnEventTypeDetectionRule"; 
    7879    } 
    7980 
     
    9394        Stack<Integer> sequenceStartingIndex = new Stack<Integer>(); 
    9495 
     96        List<ITaskTreeNode> children = parent.getChildren(); 
     97         
    9598        int index = 0; 
    96         while (index < parent.getChildren().size()) { 
    97             ITaskTreeNode child = parent.getChildren().get(index); 
     99        while (index < children.size()) { 
     100            ITaskTreeNode child = children.get(index); 
    98101 
    99102            if ((child instanceof IEventTask) && 
     
    104107                if (eventType.finishesLogicalSequence() && (sequenceStartingIndex.size() > 0)) { 
    105108                    index = handleLogicalSequence(sequenceStartingIndex, index, parent, result); 
     109                    // the parents child list will have changed, retrieve it again 
     110                    children = parent.getChildren(); 
    106111                } 
    107112 
     
    116121        if (sequenceStartingIndex.size() > 0) { 
    117122            if (!finalize) { 
    118                 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     123                result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 
    119124            } 
    120125            else { 
    121                 ITaskTreeNode lastChild = parent.getChildren().get(parent.getChildren().size() - 1); 
     126                ITaskTreeNode lastChild = children.get(children.size() - 1); 
    122127                 
    123128                if (lastChild instanceof IEventTask) { 
    124129                    handleLogicalSequence 
    125                         (sequenceStartingIndex, parent.getChildren().size() - 1, parent, result); 
     130                        (sequenceStartingIndex, children.size() - 1, parent, result); 
    126131                } 
    127132            } 
     
    143148    { 
    144149        int newIndex = index; 
     150         
     151        List<ITaskTreeNode> children = parent.getChildren(); 
     152         
    145153        IInteraction eventType = 
    146             (IInteraction) ((IEventTask) parent.getChildren().get(index)).getEventType(); 
     154            (IInteraction) ((IEventTask) children.get(index)).getEventType(); 
    147155 
    148156        // There are several situations in which this implementation may cause infinite 
     
    163171         
    164172        boolean allChildrenBelongToSubSequence = 
    165             (sequenceStartingIndex.peek() == 0) && (index == (parent.getChildren().size() - 1)); 
     173            (sequenceStartingIndex.peek() == 0) && (index == (children.size() - 1)); 
    166174         
    167175        boolean atLeastOneChildToCondense = index - sequenceStartingIndex.peek() > 0; 
     
    172180 
    173181            for (int j = startIndex; j < index; j++) { 
    174                 taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     182                taskTreeBuilder.addChild(sequence, children.get(startIndex)); 
    175183                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    176184            } 
    177185 
    178186            if (!eventType.startsLogicalSequence()) { 
    179                 taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     187                taskTreeBuilder.addChild(sequence, children.get(startIndex)); 
    180188                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    181189                newIndex = startIndex; 
     
    191199            taskTreeBuilder.setDescription(sequence, "logical sequence started by the first event"); 
    192200                 
    193             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     201            result.setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
    194202        } 
    195203         
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java

    r1119 r1127  
    2121import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    2222import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     24import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    2325import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2426import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    2527import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    2628import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
    27 import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator; 
    2829import de.ugoe.cs.autoquest.usageprofiles.Trie; 
    2930import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor; 
     31import de.ugoe.cs.util.console.Console; 
    3032 
    3133/** 
     
    3638 * @author Patrick Harms 
    3739 */ 
    38 class DefaultTaskSequenceDetectionRule implements TemporalRelationshipRule { 
     40class SequenceForTaskDetectionRule implements TemporalRelationshipRule { 
    3941     
    4042    /** 
     
    5860     * </p> 
    5961     */ 
    60     private SymbolComparator<ITaskTreeNode> nodeComparator; 
     62    private TaskTreeNodeComparator nodeComparator; 
    6163 
    6264    /** 
     
    6668     * </p> 
    6769     */ 
    68     DefaultTaskSequenceDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
    69                                      NodeEquality            minimalNodeEquality, 
    70                                      ITaskTreeNodeFactory    taskTreeNodeFactory, 
    71                                      ITaskTreeBuilder        taskTreeBuilder) 
     70    SequenceForTaskDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
     71                                 NodeEquality            minimalNodeEquality, 
     72                                 ITaskTreeNodeFactory    taskTreeNodeFactory, 
     73                                 ITaskTreeBuilder        taskTreeBuilder) 
    7274    { 
    7375        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     
    8385    @Override 
    8486    public String toString() { 
    85         return "DefaultTaskSequenceDetectionRule"; 
     87        return "SequenceForTaskDetectionRule"; 
    8688    } 
    8789 
     
    101103            // the rule is always feasible as tasks may occur at any time 
    102104            RuleApplicationResult result = new RuleApplicationResult(); 
    103             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     105            result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 
    104106            return result; 
    105107        } 
    106108 
    107         RuleApplicationData<ITaskTreeNode> appData = new RuleApplicationData<ITaskTreeNode>(parent); 
    108          
    109         appData.getStopWatch().start("whole rule application"); 
    110          
     109        List<ITaskTreeNode> children = parent.getChildren(); 
     110        List<ISequence> sessions = new LinkedList<ISequence>(); 
     111         
     112        for (ITaskTreeNode child : children) { 
     113            if (child instanceof ISequence) { 
     114                sessions.add((ISequence) child); 
     115            } 
     116            else { 
     117                Console.println("provided parent is no parent of sessions"); 
     118                return null; 
     119            } 
     120        } 
     121         
     122        RuleApplicationData appData = new RuleApplicationData(sessions); 
     123 
     124        boolean finished = false; 
     125         
     126        // this is the real rule application. Loop while something is replaced. 
    111127        do { 
    112             getSequencesOccuringMostOften(appData); 
    113              
    114             if ((appData.getLastFoundSequences().size() > 0) && 
    115                 (appData.getLastFoundSequences().getOccurrenceCount() > 1)) 
    116             { 
    117                 System.out.println("found " + appData.getLastFoundSequences().size() + 
    118                                    " tasks occurring " + 
    119                                    appData.getLastFoundSequences().getOccurrenceCount() + " times"); 
    120  
    121                 for (List<ITaskTreeNode> task : appData.getLastFoundSequences()) { 
    122                     // only tasks occurring more often than once are of interest 
    123                     appData.stopWatch.start("creating task sequences"); 
    124  
    125                     String taskId = "task " + RuleUtils.getNewId(); 
    126                     System.out.println(taskId + ": " + task); 
    127                      
    128                     appData.resetReplacementCounter(); 
    129                     createSequenceForTaskOccurrences(taskId, task, parent, appData); 
    130                      
    131                     if (appData.getReplacementCounter() < 
    132                         appData.getLastFoundSequences().getOccurrenceCount()) 
    133                     { 
    134                         System.out.println(taskId + ": replaced task only " + 
    135                                            appData.getReplacementCounter() + 
    136                                            " times instead of expected " + 
    137                                            appData.getLastFoundSequences().getOccurrenceCount()); 
    138                          
    139                     } 
    140  
    141                     appData.stopWatch.stop("creating task sequences"); 
     128            System.out.println(); 
     129             
     130            appData.getStopWatch().start("whole loop"); 
     131            detectAndReplaceIterations(appData); 
     132            //mergeEqualTasks(appData); 
     133            appData.getStopWatch().start("task replacement"); 
     134            detectAndReplaceTasks(appData); 
     135            appData.getStopWatch().stop("task replacement"); 
     136            appData.getStopWatch().stop("whole loop"); 
     137             
     138            //((TaskTreeNodeComparator) nodeComparator).getStopWatch().dumpStatistics(System.out); 
     139            //((TaskTreeNodeComparator) nodeComparator).getStopWatch().reset(); 
     140             
     141            appData.getStopWatch().dumpStatistics(System.out); 
     142            appData.getStopWatch().reset(); 
     143             
     144            finished = (appData.getReplacementCounter() == 0); 
     145        } 
     146        while (!finished); 
     147         
     148        System.out.println("created " + appData.getResult().getNewlyCreatedParentNodes().size() + 
     149                           " new parent nodes\n"); 
     150         
     151        if (appData.getResult().getNewlyCreatedParentNodes().size() > 0) { 
     152            appData.getResult().setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
     153        } 
     154         
     155        return appData.getResult(); 
     156    } 
     157 
     158    /** 
     159     * <p> 
     160     * TODO: comment 
     161     * </p> 
     162     * 
     163     * @param appData 
     164     */ 
     165    private void detectAndReplaceIterations(RuleApplicationData appData) { 
     166        System.out.print("detecting iterations"); 
     167        appData.getStopWatch().start("detecting iterations"); 
     168         
     169        List<ISequence> sessions = appData.getSessions(); 
     170        int foundIterations = 0; 
     171         
     172        for (ISequence session : sessions) { 
     173            foundIterations += detectAndReplaceIterations(session, appData); 
     174        } 
     175         
     176        appData.getStopWatch().stop("detecting iterations"); 
     177        System.out.println(" --> found " + foundIterations); 
     178    } 
     179 
     180    /** 
     181     * <p> 
     182     * TODO: comment 
     183     * </p> 
     184     * 
     185     * @param appData 
     186     */ 
     187    private int detectAndReplaceIterations(ISequence           session, 
     188                                           RuleApplicationData appData) 
     189    { 
     190        int count = 0; 
     191         
     192        TemporalRelationshipRule rule = new SimpleIterationDetectionRule 
     193            (nodeComparator, taskTreeNodeFactory, taskTreeBuilder); 
     194 
     195        RuleApplicationResult result = rule.apply(session, true); 
     196             
     197        if ((result != null) && (result.getNewlyCreatedParentNodes() != null)) { 
     198            for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 
     199                appData.getResult().addNewlyCreatedParentNode(newParent); 
     200                if (newParent instanceof IIteration) { 
     201                    count++; 
    142202                } 
    143203            } 
    144              
    145         } 
    146         while (appData.getLastFoundSequences().getOccurrenceCount() > 2); 
    147          
    148         appData.getStopWatch().stop("whole rule application"); 
    149         appData.getStopWatch().dumpStatistics(System.out); 
    150          
    151         if (appData.getResult().getNewlyCreatedParentNodes().size() > 0) { 
    152             appData.getResult().setRuleApplicationStatus 
    153                 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
    154         } 
    155          
    156         System.out.println(appData.getResult().getNewlyCreatedParentNodes().size()); 
    157          
    158         for (ITaskTreeNode node : appData.getResult().getNewlyCreatedParentNodes()) { 
    159             for (ITaskTreeNode child : node.getChildren()) { 
    160                 System.out.println(child); 
    161             } 
    162             System.out.println(); 
    163         } 
    164          
    165         return appData.getResult(); 
     204        } 
     205         
     206        return count; 
     207    } 
     208 
     209//    /** 
     210//     * <p> 
     211//     * TODO: comment 
     212//     * </p> 
     213//     * 
     214//     * @param appData 
     215//     */ 
     216//    private void mergeEqualTasks(RuleApplicationData appData) { 
     217//        System.out.println("merging equal tasks"); 
     218//        appData.getStopWatch().start("merging equal tasks"); 
     219//         
     220//        int replacements = 0; 
     221//        List<ISequence> sessions = appData.getSessions(); 
     222//         
     223//        IdentityHashMap<ITaskTreeNode, ITaskTreeNode> replacedChildren = 
     224//            new IdentityHashMap<ITaskTreeNode, ITaskTreeNode>(); 
     225//         
     226//        for (int sessionIdx1 = 0; sessionIdx1 < sessions.size(); sessionIdx1++) { 
     227//            List<ITaskTreeNode> children1 = appData.getSessions().get(sessionIdx1).getChildren(); 
     228//            for (int childIdx1 = 0; childIdx1 < children1.size(); childIdx1++) { 
     229//                // this is the child of which we search equal other children to merge and to 
     230//                // replace with one single unique node 
     231//                ITaskTreeNode child1 = children1.get(childIdx1); 
     232//                 
     233//                if (replacedChildren.containsKey(child1)) { 
     234//                    continue; 
     235//                } 
     236//                 
     237//                // now search for all other children that are equal. Also record the session they 
     238//                // belong to as well as the index in that session 
     239//                List<ITaskTreeNode> equalChildren = new LinkedList<ITaskTreeNode>(); 
     240//                List<Integer> sessionIndexes = new LinkedList<Integer>(); 
     241//                List<Integer> childIndexes = new LinkedList<Integer>(); 
     242// 
     243//                // add all information about the current child 
     244//                equalChildren.add(child1); 
     245//                sessionIndexes.add(sessionIdx1); 
     246//                childIndexes.add(childIdx1); 
     247//                 
     248//                for (int sessionIdx2 = sessionIdx1; sessionIdx2 < sessions.size(); sessionIdx2++) { 
     249//                    List<ITaskTreeNode> children2 = 
     250//                          appData.getSessions().get(sessionIdx2).getChildren(); 
     251//                     
     252//                    int startIndex = (sessionIdx1 == sessionIdx2) ? childIdx1 + 1 : 0; 
     253//                     
     254//                    for (int childIdx2 = startIndex; childIdx2 < children2.size(); childIdx2++) { 
     255//                        ITaskTreeNode child2 = children2.get(childIdx2); 
     256//                         
     257//                        if ((child1 != child2) && (nodeComparator.equals(child1, child2))) { 
     258//                            // this is an equal child --> record its occurrence 
     259//                            equalChildren.add(child2); 
     260//                            sessionIndexes.add(sessionIdx2); 
     261//                            childIndexes.add(childIdx2); 
     262//                        } 
     263//                    } 
     264//                } 
     265//                 
     266//                // now merge the found children 
     267//                if (equalChildren.size() > 1) { 
     268//                    ITaskTreeNode replacement = 
     269//                        mergeVariantsOfTasks(child1.toString(), equalChildren); 
     270// 
     271//                    for (int i = 0; i < sessionIndexes.size(); i++) { 
     272//                        taskTreeBuilder.setChild(appData.getSessions().get(sessionIndexes.get(i)), 
     273//                                                 childIndexes.get(i), replacement); 
     274//                     
     275//                        replacements++; 
     276//                    } 
     277//                     
     278//                    // remember the replacement to prevent comparison of merged nodes 
     279//                    replacedChildren.put(replacement, replacement); 
     280//                     
     281//                    System.out.println 
     282//                        ("replaced " + sessionIndexes.size() + " occurrences of " + child1); 
     283//                } 
     284//            } 
     285//        } 
     286// 
     287//        appData.getStopWatch().stop("merging equal tasks"); 
     288//         
     289//        System.out.println("replaced " + replacements + " equal tasks with unique replacements"); 
     290//    } 
     291// 
     292    /** 
     293     * <p> 
     294     * TODO: comment 
     295     * </p> 
     296     * 
     297     * @param appData 
     298     */ 
     299    private void detectAndReplaceTasks(RuleApplicationData appData) { 
     300        System.out.println("detecting and replacing tasks"); 
     301        appData.getStopWatch().start("detecting tasks"); 
     302         
     303        getSequencesOccuringMostOften(appData); 
     304 
     305        appData.getStopWatch().stop("detecting tasks"); 
     306        appData.getStopWatch().start("replacing tasks"); 
     307         
     308        replaceSequencesOccurringMostOften(appData); 
     309         
     310        appData.getStopWatch().stop("replacing tasks"); 
     311        System.out.println("detected and replaced " + appData.getLastFoundTasks().size() + " tasks"); 
    166312    } 
    167313 
     
    174320     * @return 
    175321     */ 
    176     private void getSequencesOccuringMostOften(RuleApplicationData<ITaskTreeNode> appData) { 
    177         System.out.println("determining most prominent tasks with a maximum of " + 
    178                            (appData.getLastFoundSequences().getOccurrenceCount() - 1) + 
    179                            " occurrences"); 
    180  
    181         Sequences<ITaskTreeNode> sequences; 
     322    private void getSequencesOccuringMostOften(RuleApplicationData appData) { 
     323        System.out.println("determining most prominent tasks"); 
     324 
     325        Tasks tasks; 
    182326        boolean createNewTrie = (appData.getLastTrie() == null) || 
    183327            appData.getReplacementCounter() > 0; // tree has changed 
     
    188332            } 
    189333             
    190             /*PathDumper dumper = new PathDumper(); 
    191             trie.process(dumper); 
    192          
    193             dumper.dump();*/ 
    194          
    195             appData.getStopWatch().start("determining tasks"); 
    196  
    197             MaxCountAndLongestSequenceFinder finder = new MaxCountAndLongestSequenceFinder 
    198                   (appData.getLastFoundSequences().getOccurrenceCount() - 1); 
     334            MaxCountAndLongestTasksFinder finder = new MaxCountAndLongestTasksFinder(); 
    199335            appData.getLastTrie().process(finder); 
    200336         
    201             sequences = finder.getFoundSequences(); 
     337            tasks = finder.getFoundTasks(); 
    202338             
    203339            createNewTrie = false; 
    204340             
    205             for (List<ITaskTreeNode> task : sequences) { 
     341            for (List<ITaskTreeNode> task : tasks) { 
    206342                if (task.size() >= appData.getTrainedSequenceLength()) { 
    207343                    // Trie must be recreated with a longer sequence length to be sure that 
     
    212348                } 
    213349            } 
    214              
    215             appData.getStopWatch().stop("determining tasks"); 
    216350        } 
    217351        while (createNewTrie); 
    218352         
    219         appData.setLastFoundSequences(sequences); 
     353        appData.setLastFoundTasks(tasks); 
     354 
     355        System.out.println("found " + appData.getLastFoundTasks().size() + " tasks occurring " + 
     356                           appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
    220357    } 
    221358 
     
    228365     * @return 
    229366     */ 
    230     private void createNewTrie(RuleApplicationData<ITaskTreeNode> appData) { 
     367    private void createNewTrie(RuleApplicationData appData) { 
    231368        System.out.println("training trie with a maximum sequence length of " + 
    232369                           appData.getTrainedSequenceLength()); 
     
    235372        appData.setLastTrie(new Trie<ITaskTreeNode>(nodeComparator)); 
    236373     
    237         trainTrie(appData.getTree(), appData); 
     374        List<ISequence> sessions = appData.getSessions(); 
     375         
     376        for (ISequence session : sessions) { 
     377            trainTrie(session, appData); 
     378        } 
     379         
    238380        appData.getStopWatch().stop("training trie"); 
    239381    } 
     
    247389     * @param parent 
    248390     */ 
    249     private void trainTrie(ITaskTreeNode parent, RuleApplicationData<ITaskTreeNode> appData) { 
    250         // prevent training of already replaces sequences as those shall not be replaced anymore 
    251         if (!appData.getResult().getNewlyCreatedParentNodes().contains(parent)) { 
    252             List<ITaskTreeNode> children = parent.getChildren(); 
    253          
    254             if ((children != null) && (children.size() > 0)) { 
     391    private void trainTrie(ISequence session, RuleApplicationData appData) { 
     392        List<ITaskTreeNode> children = session.getChildren(); 
     393         
     394        if ((children != null) && (children.size() > 0)) { 
     395            appData.getLastTrie().train(children, appData.getTrainedSequenceLength()); 
     396        } 
     397    } 
     398 
     399    /** 
     400     * <p> 
     401     * TODO: comment 
     402     * </p> 
     403     * 
     404     * @param appData 
     405     */ 
     406    private void replaceSequencesOccurringMostOften(RuleApplicationData appData) { 
     407        appData.resetReplacementCounter(); 
     408 
     409        if ((appData.getLastFoundTasks().size() > 0) && 
     410            (appData.getLastFoundTasks().getOccurrenceCount() > 1)) 
     411        { 
     412            System.out.println("replacing tasks occurrences with merged variants of all versions"); 
     413 
     414            for (List<ITaskTreeNode> task : appData.getLastFoundTasks()) { 
     415                String taskId = "task " + RuleUtils.getNewId(); 
     416                System.out.println("replacing " + taskId + ": " + task); 
     417 
     418                appData.clearTaskOccurrences(); 
     419                determineVariantsOfTaskOccurrences(task, appData.getSessions(), appData); 
    255420                 
    256                 /*System.out.println(); 
    257                 for (int i = 0; i < children.size(); i++) { 
    258                     System.out.println(children.get(i)); 
    259                 }*/ 
     421                appData.getStopWatch().start("merging task nodes"); 
     422                ITaskTreeNode taskReplacement = mergeVariantsOfTaskOccurrence(taskId, appData); 
     423                appData.getStopWatch().stop("merging task nodes"); 
     424 
     425                appData.resetReplacementCounter(); 
     426                replaceTaskOccurrences(task, taskReplacement, appData.getSessions(), appData); 
     427 
     428                if (appData.getReplacementCounter() > 0) { 
     429                    appData.getResult().addNewlyCreatedParentNode(taskReplacement); 
     430                } 
     431 
     432                if (appData.getReplacementCounter() < 
     433                    appData.getLastFoundTasks().getOccurrenceCount()) 
     434                { 
     435                    System.out.println(taskId + ": replaced task only " + 
     436                                       appData.getReplacementCounter() + 
     437                                       " times instead of expected " + 
     438                                       appData.getLastFoundTasks().getOccurrenceCount()); 
     439                } 
     440            } 
     441        } 
     442         
     443    } 
     444 
     445    /** 
     446     * <p> 
     447     * TODO: comment 
     448     * </p> 
     449     * 
     450     * @param tree 
     451     */ 
     452    private void determineVariantsOfTaskOccurrences(List<ITaskTreeNode> task, 
     453                                                    List<ISequence>     sessions, 
     454                                                    RuleApplicationData appData) 
     455    { 
     456        for (ISequence session : sessions) { 
     457            int index = -1; 
    260458                 
    261                 appData.getLastTrie().train(children, appData.getTrainedSequenceLength()); 
    262              
    263                 for (ITaskTreeNode child : children) { 
    264                     trainTrie(child, appData); 
     459            List<ITaskTreeNode> children = session.getChildren(); 
     460 
     461            do { 
     462                index = getSubListIndex(children, task, ++index); 
     463 
     464                if (index > -1) { 
     465                    ISequence taskOccurrence = RuleUtils.getSubSequenceInRange 
     466                            (session, index, index + task.size() - 1, null, 
     467                             taskTreeNodeFactory, taskTreeBuilder); 
     468 
     469                    appData.addTaskOccurrence(taskOccurrence); 
     470 
     471                    // let the index point to the last element the belongs the identified occurrence 
     472                    index += task.size() - 1; 
    265473                } 
    266474            } 
     475            while (index > -1); 
     476        } 
     477    } 
     478 
     479    /** 
     480     * <p> 
     481     * TODO: comment 
     482     * </p> 
     483     * 
     484     * @param appData 
     485     * @return 
     486     */ 
     487    private ITaskTreeNode mergeVariantsOfTaskOccurrence(String              taskId, 
     488                                                        RuleApplicationData appData) 
     489    { 
     490        return mergeVariantsOfTasks(taskId, appData.getTaskOccurrences()); 
     491    } 
     492 
     493    /** 
     494     * <p> 
     495     * TODO: comment 
     496     * </p> 
     497     * 
     498     * @param appData 
     499     * @return 
     500     */ 
     501    private ITaskTreeNode mergeVariantsOfTasks(String description, List<ITaskTreeNode> variants) { 
     502        // merge but preserve lexically distinct variants 
     503        TaskTreeNodeMerger merger = new TaskTreeNodeMerger 
     504            (taskTreeNodeFactory, taskTreeBuilder, nodeComparator); 
     505         
     506        merger.mergeTaskNodes(variants); 
     507         
     508        if (variants.size() == 1) { 
     509            ITaskTreeNode replacement = variants.get(0); 
     510            taskTreeBuilder.setDescription(replacement, description); 
     511            return replacement; 
     512        } 
     513        else { 
     514            ISelection selection = taskTreeNodeFactory.createNewSelection(); 
     515            taskTreeBuilder.setDescription(selection, "variants of task " + description); 
     516             
     517            for (ITaskTreeNode variant : variants) { 
     518                taskTreeBuilder.addChild(selection, variant); 
     519            } 
     520             
     521            return selection; 
    267522        } 
    268523    } 
     
    279534     * @param result 
    280535     */ 
    281     private void createSequenceForTaskOccurrences(String                             taskId, 
    282                                                   List<ITaskTreeNode>                task, 
    283                                                   ITaskTreeNode                      parent, 
    284                                                   RuleApplicationData<ITaskTreeNode> appData) 
     536    private void replaceTaskOccurrences(List<ITaskTreeNode> task, 
     537                                        ITaskTreeNode       replacement, 
     538                                        List<ISequence>     sessions, 
     539                                        RuleApplicationData appData) 
    285540    { 
    286         List<ITaskTreeNode> children = parent.getChildren(); 
    287          
    288         if ((children == null) || (children.size() == 0)) { 
    289             return; 
    290         } 
    291          
    292         // first traverse the children 
    293         for (ITaskTreeNode child : children) { 
    294             createSequenceForTaskOccurrences(taskId, task, child, appData); 
    295         } 
    296          
    297541        // now check the children themselves for an occurrence of the task 
    298         int index = -1; 
    299          
    300         do { 
    301             index = getSubListIndex(children, task, ++index); 
    302              
    303             if (index > -1) { 
    304                 if (task.size() < children.size()) { 
    305                     ISequence sequence = RuleUtils.createNewSubSequenceInRange 
    306                         (parent, index, index + task.size() - 1, taskId, 
    307                          taskTreeNodeFactory, taskTreeBuilder); 
    308                      
    309                     appData.getResult().addNewlyCreatedParentNode(sequence); 
    310                     appData.incrementReplacementCounter(); 
    311                   
    312                     children = parent.getChildren(); 
    313                 } 
    314                 else { 
    315                     // the whole list of children is an occurrence of this task. Just set the 
    316                     // description of the parent and break up 
    317                     String description = parent.getDescription(); 
    318                      
    319                     if ((description != null) && (description.length() > 0)) { 
    320                         description += "; " + taskId; 
     542        for (int i = 0; i < sessions.size(); i++) { 
     543            ISequence session = sessions.get(i); 
     544             
     545            int index = -1; 
     546         
     547            List<ITaskTreeNode> children = session.getChildren(); 
     548 
     549            do { 
     550                index = getSubListIndex(children, task, ++index); 
     551 
     552                if (index > -1) { 
     553                    if ((!(replacement instanceof ISequence)) || 
     554                        (task.size() < children.size())) 
     555                    { 
     556                        for (int j = index; j < index + task.size(); j++) { 
     557                            taskTreeBuilder.removeChild(session, index); 
     558                        } 
     559 
     560                        taskTreeBuilder.addChild(session, index, replacement); 
     561                        appData.incrementReplacementCounter(); 
     562 
     563                        children = session.getChildren(); 
    321564                    } 
    322565                    else { 
    323                         description = taskId; 
     566                        // the whole list of children is an occurrence of this task. So ask the 
     567                        // caller of the method to replace the whole node 
     568                        sessions.set(i, (ISequence) replacement); 
     569                        appData.incrementReplacementCounter(); 
     570                        break; 
    324571                    } 
    325                      
    326                     taskTreeBuilder.setDescription(parent, description); 
    327                     break; 
    328572                } 
    329573            } 
    330         } 
    331         while (index > -1); 
     574            while (index > -1); 
     575        } 
    332576    } 
    333577 
     
    356600                    break; 
    357601                } 
    358                 else if (!nodeComparator.equals(subList.get(j), list.get(i + j))){ 
    359                     throw new RuntimeException("comparator not commutative"); 
    360                 } 
    361602            } 
    362603             
     
    377618     * @author Patrick Harms 
    378619     */ 
    379     private class MaxCountAndLongestSequenceFinder implements TrieProcessor<ITaskTreeNode> { 
    380          
    381         /** 
    382          *  
    383          */ 
    384         private int maxCount; 
     620    private class MaxCountAndLongestTasksFinder implements TrieProcessor<ITaskTreeNode> { 
    385621         
    386622        /** 
     
    392628         *  
    393629         */ 
    394         private List<List<ITaskTreeNode>> foundSequences = new LinkedList<List<ITaskTreeNode>>(); 
     630        private List<List<ITaskTreeNode>> foundTasks = new LinkedList<List<ITaskTreeNode>>(); 
    395631 
    396632        /** 
     
    401637         * @param maxCount 
    402638         */ 
    403         public MaxCountAndLongestSequenceFinder(int maxCount) { 
     639        public MaxCountAndLongestTasksFinder() { 
    404640            super(); 
    405             this.maxCount = maxCount; 
    406641            this.currentCount = 0; 
    407642        } 
     
    411646         */ 
    412647        @Override 
    413         public TrieProcessor.Result process(List<ITaskTreeNode> sequence, int count) { 
    414             if (sequence.size() < 2) { 
     648        public TrieProcessor.Result process(List<ITaskTreeNode> task, int count) { 
     649            if (task.size() < 2) { 
    415650                // ignore single nodes 
    416651                return TrieProcessor.Result.CONTINUE; 
     
    422657            } 
    423658 
    424             if (count > this.maxCount) { 
    425                 // ignore sequences that occur too often 
    426                 return TrieProcessor.Result.CONTINUE; 
    427             } 
    428              
    429659            if (this.currentCount > count) { 
    430660                // ignore this children of this node, as they may have only smaller counts than 
    431                 // the already found sequences 
     661                // the already found tasks 
    432662                return TrieProcessor.Result.SKIP_NODE; 
    433663            } 
    434664             
    435665            if (this.currentCount < count) { 
    436                 // the provided sequence occurs more often that all sequences found so far. 
    437                 // clear all found sequences and use the new count as the one searched for 
    438                 foundSequences.clear(); 
     666                // the provided task occurs more often that all tasks found so far. 
     667                // clear all found tasks and use the new count as the one searched for 
     668                foundTasks.clear(); 
    439669                this.currentCount = count; 
    440670            } 
    441671             
    442672            if (this.currentCount == count) { 
    443                 // the sequence is of interest. Sort it into the other found sequences so that 
     673                // the task is of interest. Sort it into the other found tasks so that 
    444674                // the longest come first 
    445675                boolean added = false; 
    446                 for (int i = 0; i < foundSequences.size(); i++) { 
    447                     if (foundSequences.get(i).size() < sequence.size()) { 
     676                for (int i = 0; i < foundTasks.size(); i++) { 
     677                    if (foundTasks.get(i).size() < task.size()) { 
    448678                        // defensive copy 
    449                         foundSequences.add(i, new LinkedList<ITaskTreeNode>(sequence)); // defensive copy 
     679                        foundTasks.add(i, new LinkedList<ITaskTreeNode>(task)); // defensive copy 
    450680                        added = true; 
    451681                        break; 
     
    454684                 
    455685                if (!added) { 
    456                     foundSequences.add(new LinkedList<ITaskTreeNode>(sequence)); // defensive copy 
     686                    foundTasks.add(new LinkedList<ITaskTreeNode>(task)); // defensive copy 
    457687                } 
    458688            } 
     
    468698         * @return 
    469699         */ 
    470         public Sequences<ITaskTreeNode> getFoundSequences() { 
     700        public Tasks getFoundTasks() { 
    471701            removePermutationsOfShorterTasks(); 
    472             return new Sequences<ITaskTreeNode>(currentCount, foundSequences); 
     702            return new Tasks(currentCount, foundTasks); 
    473703        } 
    474704 
     
    482712            // now iterate the sorted list and for each task remove all other tasks that are shorter 
    483713            // (i.e. come later in the sorted list) and that represent a subpart of the task 
    484             for (int i = 0; i < foundSequences.size(); i++) { 
    485                 for (int j = i + 1; j < foundSequences.size();) { 
    486                     if (foundSequences.get(j).size() < foundSequences.get(i).size()) { 
     714            for (int i = 0; i < foundTasks.size(); i++) { 
     715                for (int j = i + 1; j < foundTasks.size();) { 
     716                    if (foundTasks.get(j).size() < foundTasks.get(i).size()) { 
    487717                        // found a task that is a potential subtask. Check for this and remove the 
    488718                        // subtask if needed 
    489                         List<ITaskTreeNode> longTask = foundSequences.get(i); 
    490                         List<ITaskTreeNode> shortTask = foundSequences.get(j); 
     719                        List<ITaskTreeNode> longTask = foundTasks.get(i); 
     720                        List<ITaskTreeNode> shortTask = foundTasks.get(j); 
    491721                         
    492722                        if (getSubListIndex(longTask, shortTask, 0) > -1) { 
    493                             foundSequences.remove(j); 
     723                            foundTasks.remove(j); 
    494724                        } 
    495725                        else { 
     
    509739     *  
    510740     */ 
    511     private class RuleApplicationData<T> { 
    512          
    513         /** 
    514          *  
    515          */ 
    516         private T tree; 
     741    private class RuleApplicationData { 
     742         
     743        /** 
     744         *  
     745         */ 
     746        private List<ISequence> sessions; 
     747         
     748        /** 
     749         *  
     750         */ 
     751        private Trie<ITaskTreeNode> lastTrie; 
     752         
     753        /** 
     754         * default and minimum trained sequence length is 3 
     755         */ 
     756        private int trainedSequenceLength = 3; 
     757         
     758        /** 
     759         *  
     760         */ 
     761        private Tasks lastFoundTasks = new Tasks(Integer.MAX_VALUE, null); 
     762         
     763        /** 
     764         *  
     765         */ 
     766        private List<ITaskTreeNode> taskOccurrences = new LinkedList<ITaskTreeNode>(); 
     767         
     768        /** 
     769         *  
     770         */ 
     771        private int replacementCounter; 
    517772         
    518773        /** 
     
    524779         *  
    525780         */ 
    526         private Sequences<T> lastFoundSequences = new Sequences<T>(Integer.MAX_VALUE, null); 
    527          
    528         /** 
    529          *  
    530          */ 
    531         private Trie<T> lastTrie; 
    532          
    533         /** 
    534          * default and minimum trained sequence length is 3 
    535          */ 
    536         private int trainedSequenceLength = 3; 
    537          
    538         /** 
    539          *  
    540          */ 
    541         private int replacementCounter; 
    542          
    543         /** 
    544          *  
    545          */ 
    546781        private StopWatch stopWatch = new StopWatch(); 
    547782         
     
    549784         *  
    550785         */ 
    551         private RuleApplicationData(T tree) { 
    552             this.tree = tree; 
    553         } 
    554  
    555         /** 
    556          * @return the lastFoundSequences 
    557          */ 
    558         private Sequences<T> getLastFoundSequences() { 
    559             return lastFoundSequences; 
    560         } 
    561  
    562         /** 
    563          * @param lastFoundSequences the lastFoundSequences to set 
    564          */ 
    565         private void setLastFoundSequences(Sequences<T> lastFoundSequences) { 
    566             this.lastFoundSequences = lastFoundSequences; 
     786        private RuleApplicationData(List<ISequence> sessions) { 
     787            this.sessions = sessions; 
     788        } 
     789 
     790        /** 
     791         * @return the tree 
     792         */ 
     793        private List<ISequence> getSessions() { 
     794            return sessions; 
     795        } 
     796 
     797        /** 
     798         * @param lastTrie the lastTrie to set 
     799         */ 
     800        private void setLastTrie(Trie<ITaskTreeNode> lastTrie) { 
     801            this.lastTrie = lastTrie; 
    567802        } 
    568803 
     
    570805         * @return the lastTrie 
    571806         */ 
    572         private Trie<T> getLastTrie() { 
     807        private Trie<ITaskTreeNode> getLastTrie() { 
    573808            return lastTrie; 
     809        } 
     810 
     811        /** 
     812         * @param trainedSequenceLength the trainedSequenceLength to set 
     813         */ 
     814        private void setTrainedSequenceLength(int trainedSequenceLength) { 
     815            this.trainedSequenceLength = trainedSequenceLength; 
    574816        } 
    575817 
     
    582824 
    583825        /** 
    584          * @param trainedSequenceLength the trainedSequenceLength to set 
    585          */ 
    586         private void setTrainedSequenceLength(int trainedSequenceLength) { 
    587             this.trainedSequenceLength = trainedSequenceLength; 
    588         } 
    589  
    590         /** 
    591          * @param lastTrie the lastTrie to set 
    592          */ 
    593         private void setLastTrie(Trie<T> lastTrie) { 
    594             this.lastTrie = lastTrie; 
    595         } 
    596  
    597         /** 
    598          * @return the tree 
    599          */ 
    600         private T getTree() { 
    601             return tree; 
    602         } 
    603  
     826         * @param lastFoundSequences the lastFoundSequences to set 
     827         */ 
     828        private void setLastFoundTasks(Tasks lastFoundSequences) { 
     829            this.lastFoundTasks = lastFoundSequences; 
     830        } 
     831 
     832        /** 
     833         * @return the lastFoundSequences 
     834         */ 
     835        private Tasks getLastFoundTasks() { 
     836            return lastFoundTasks; 
     837        } 
     838 
     839        /** 
     840         * @return the taskOccurrences 
     841         */ 
     842        private void clearTaskOccurrences() { 
     843            taskOccurrences.clear(); 
     844        } 
     845 
     846        /** 
     847         * @return the taskOccurrences 
     848         */ 
     849        private void addTaskOccurrence(ITaskTreeNode taskOccurrence) { 
     850            taskOccurrences.add(taskOccurrence); 
     851        } 
     852 
     853        /** 
     854         * @return the taskOccurrences 
     855         */ 
     856        private List<ITaskTreeNode> getTaskOccurrences() { 
     857            return taskOccurrences; 
     858        } 
     859 
     860        /** 
     861         * 
     862         */ 
     863        private void resetReplacementCounter() { 
     864            replacementCounter = 0; 
     865        } 
     866 
     867        /** 
     868         * 
     869         */ 
     870        private void incrementReplacementCounter() { 
     871            replacementCounter++; 
     872        } 
     873 
     874        /** 
     875         * 
     876         */ 
     877        private int getReplacementCounter() { 
     878            return replacementCounter; 
     879        } 
     880         
    604881        /** 
    605882         * @return the result 
     
    616893        } 
    617894 
    618         /** 
    619          * 
    620          */ 
    621         private void resetReplacementCounter() { 
    622             replacementCounter = 0; 
    623         } 
    624  
    625         /** 
    626          * 
    627          */ 
    628         private void incrementReplacementCounter() { 
    629             replacementCounter++; 
    630         } 
    631  
    632         /** 
    633          * 
    634          */ 
    635         private int getReplacementCounter() { 
    636             return replacementCounter; 
    637         } 
    638895    } 
    639896     
     
    646903     * @author Patrick Harms 
    647904     */ 
    648     private class Sequences<T> implements Iterable<List<T>> { 
     905    private class Tasks implements Iterable<List<ITaskTreeNode>> { 
    649906         
    650907        /** 
     
    656913         *  
    657914         */ 
    658         private List<List<T>> sequences; 
     915        private List<List<ITaskTreeNode>> sequences; 
    659916 
    660917        /** 
     
    666923         * @param sequences 
    667924         */ 
    668         private Sequences(int occurrenceCount, List<List<T>> sequences) { 
     925        private Tasks(int occurrenceCount, List<List<ITaskTreeNode>> sequences) { 
    669926            super(); 
    670927            this.occurrenceCount = occurrenceCount; 
     
    702959         */ 
    703960        @Override 
    704         public Iterator<List<T>> iterator() { 
     961        public Iterator<List<ITaskTreeNode>> iterator() { 
    705962            return this.sequences.iterator(); 
    706963        } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceOnGuiElementDetectionRule.java

    r1117 r1127  
    3434 * @author 2012, last modified by $Author: patrick$ 
    3535 */ 
    36 class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule { 
     36class SequenceOnGuiElementDetectionRule implements TemporalRelationshipRule { 
    3737 
    3838    /** 
     
    7070     *                            the temporal relationships identified during rule application 
    7171     */ 
    72     DefaultGuiElementSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
    73                                            ITaskTreeBuilder     taskTreeBuilder) 
     72    SequenceOnGuiElementDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     73                                      ITaskTreeBuilder     taskTreeBuilder) 
    7474    { 
    7575        this(null, taskTreeNodeFactory, taskTreeBuilder); 
     
    9090     *                            the temporal relationships identified during rule application 
    9191     */ 
    92     DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter, 
     92    SequenceOnGuiElementDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter, 
    9393                                           ITaskTreeNodeFactory taskTreeNodeFactory, 
    9494                                           ITaskTreeBuilder     taskTreeBuilder) 
     
    104104    @Override 
    105105    public String toString() { 
    106         return "DefaultGuiElementSequenceDetectionRule"; 
     106        return "SequenceOnGuiElementDetectionRule"; 
    107107    } 
    108108 
     
    154154         
    155155        if (status == null) { 
    156             status = RuleApplicationStatus.RULE_NOT_APPLIED; 
     156            status = RuleApplicationStatus.NOT_APPLIED; 
    157157        } 
    158158             
     
    193193        int startingIndex = -1; 
    194194         
    195         RuleApplicationStatus status = RuleApplicationStatus.RULE_NOT_APPLIED; 
     195        RuleApplicationStatus status = RuleApplicationStatus.NOT_APPLIED; 
    196196        boolean subsequenceHasStarted = false; 
    197197        boolean exceedingGuiHierarchyDepth = false; 
     
    202202 
    203203        int index = 0; 
    204         while (index < parent.getChildren().size()) { 
     204        List<ITaskTreeNode> children = parent.getChildren(); 
     205         
     206        while (index < children.size()) { 
    205207            hierarchy = hierarchies.get(index); 
    206208 
     
    220222                status = condenseSequence 
    221223                    (parent, hierarchies, hierarchyLevel, startingIndex, index - 1, result); 
     224                 
     225                // children may have changed, retrieve them again. 
     226                children = parent.getChildren(); 
    222227 
    223228                if (status != null) { 
     
    244249                status = condenseSequence 
    245250                    (parent, hierarchies, hierarchyLevel, startingIndex, 
    246                      parent.getChildren().size() - 1, result); 
    247             } 
    248             else if (status != RuleApplicationStatus.RULE_APPLICATION_FINISHED) { 
    249                 status = RuleApplicationStatus.RULE_NOT_APPLIED; 
     251                     children.size() - 1, result); 
     252            } 
     253            else if (status != RuleApplicationStatus.FINISHED) { 
     254                status = RuleApplicationStatus.NOT_APPLIED; 
    250255            } 
    251256        } 
    252257        else { 
    253             if ((currentParent != null) && 
    254                 (status != RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 
    255             { 
    256                 status = RuleApplicationStatus.RULE_APPLICATION_FEASIBLE; 
     258            if ((currentParent != null) && (status != RuleApplicationStatus.FINISHED)) { 
     259                status = RuleApplicationStatus.FEASIBLE; 
    257260            } 
    258261        } 
     
    288291    { 
    289292        boolean onlyASingleChildToReduce = (endIndex - startIndex) == 0; 
     293         
     294        List<ITaskTreeNode> children = parent.getChildren(); 
     295         
    290296        boolean singleChildIsSequence = onlyASingleChildToReduce && 
    291             parent.getChildren().get(startIndex) instanceof ISequence; 
     297            children.get(startIndex) instanceof ISequence; 
    292298 
    293299        if (!onlyASingleChildToReduce || !singleChildIsSequence) { 
     
    302308 
    303309            for (int i = startIndex; i <= endIndex; i++) { 
    304                 taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     310                taskTreeBuilder.addChild(sequence, children.get(startIndex)); 
    305311                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    306312                 
     
    316322            result.addNewlyCreatedParentNode(sequence); 
    317323 
    318             return RuleApplicationStatus.RULE_APPLICATION_FINISHED; 
     324            return RuleApplicationStatus.FINISHED; 
    319325        } 
    320326        else { 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceOnSameTargetDetectionRule.java

    r1117 r1127  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
     17import java.util.List; 
     18 
    1719import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    1820import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     
    2931 * @author 2012, last modified by $Author: patrick$ 
    3032 */ 
    31 class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 
     33class SequenceOnSameTargetDetectionRule implements TemporalRelationshipRule { 
    3234 
    3335    /** 
     
    5860     *                            the temporal relationships identified during rule application 
    5961     */ 
    60     DefaultEventTargetSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
    61                                             ITaskTreeBuilder     taskTreeBuilder) 
     62    SequenceOnSameTargetDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     63                                      ITaskTreeBuilder     taskTreeBuilder) 
    6264    { 
    6365        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     
    7072    @Override 
    7173    public String toString() { 
    72         return "DefaultEventTargetSequenceDetectionRule"; 
     74        return "SequenceOnSameTargetDetectionRule"; 
    7375    } 
    7476 
     
    9193 
    9294        int index = 0; 
    93         while (index < parent.getChildren().size()) { 
    94             ITaskTreeNode child = parent.getChildren().get(index); 
     95        List<ITaskTreeNode> children = parent.getChildren(); 
     96         
     97        while (index < children.size()) { 
     98            ITaskTreeNode child = children.get(index); 
    9599 
    96100            IEventTarget eventTarget = determineEventTarget(child); 
     
    109113                    // or if this child is not a sequence itself 
    110114                    if ((startingIndex != endIndex) || 
    111                         (!(parent.getChildren().get(startingIndex) instanceof ISequence))) 
     115                        (!(children.get(startingIndex) instanceof ISequence))) 
    112116                    { 
    113117                        handleEventTargetSequence 
    114118                            (parent, currentEventTarget, startingIndex, endIndex, result); 
    115119 
    116                         result.setRuleApplicationStatus 
    117                             (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     120                        result.setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
    118121                        return result; 
    119122                    } 
     
    134137 
    135138        if (startingIndex > -1) { 
    136             int endIndex = parent.getChildren().size() - 1; 
     139            int endIndex = children.size() - 1; 
    137140             
    138141            if (finalize) { 
     
    141144                if ((startingIndex > 0) && 
    142145                    ((startingIndex != endIndex) || 
    143                      (!(parent.getChildren().get(startingIndex) instanceof ISequence)))) 
     146                     (!(children.get(startingIndex) instanceof ISequence)))) 
    144147                { 
    145148                    handleEventTargetSequence 
    146149                        (parent, currentEventTarget, startingIndex, endIndex, result); 
    147150                 
    148                     result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     151                    result.setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
    149152                } 
    150153            } 
    151154            else { 
    152                 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     155                result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 
    153156            } 
    154157        } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskTreeNodeComparator.java

    r1107 r1127  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
     17import java.util.HashMap; 
     18 
    1719import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    1820import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 
     
    4446    private NodeEquality minimalNodeEquality; 
    4547 
    46  
     48    private Comparer comparer; 
     49 
     50    private Comparer lexicalComparer; 
     51 
     52    private StopWatch stopWatch = new StopWatch(); 
     53     
     54    private HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>(); 
     55 
     56    private HashMap<Long, Boolean> lexicalEqualityBuffer; 
    4757 
    4858    /** 
     
    6070        this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
    6171        this.minimalNodeEquality = minimalNodeEquality; 
    62     } 
    63  
    64  
     72         
     73        if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) { 
     74            comparer = new LexicalComparer(); 
     75        } 
     76        else if (minimalNodeEquality == NodeEquality.SYNTACTICALLY_EQUAL) { 
     77            comparer = new SyntacticalComparer(); 
     78        } 
     79        else if (minimalNodeEquality == NodeEquality.SEMANTICALLY_EQUAL) { 
     80            comparer = new SemanticalComparer(); 
     81        } 
     82        else { 
     83            comparer = new DefaultComparer(); 
     84        } 
     85         
     86        if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) { 
     87            lexicalComparer = comparer; 
     88            lexicalEqualityBuffer = equalityBuffer; 
     89        } 
     90        else { 
     91            lexicalComparer = new LexicalComparer(); 
     92            lexicalEqualityBuffer = new HashMap<Long, Boolean>(); 
     93        } 
     94    } 
    6595 
    6696    /* (non-Javadoc) 
     
    6999    @Override 
    70100    public boolean equals(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 
    71         return nodeEqualityRuleManager.applyRules(symbol1, symbol2).isAtLeast(minimalNodeEquality); 
    72     } 
    73  
     101        //String id = "compare " + symbol1.getClass().getSimpleName() + " " + 
     102        //    symbol2.getClass().getSimpleName(); 
     103        //String id = "compare"; 
     104        //stopWatch.start(id); 
     105         
     106        Boolean result; 
     107         
     108        if (symbol1 != symbol2) { 
     109            long key = ((long) System.identityHashCode(symbol1)) << 32; 
     110            key += System.identityHashCode(symbol2); 
     111             
     112            result = equalityBuffer.get(key); 
     113             
     114            if (result == null) { 
     115                result = comparer.compare(symbol1, symbol2); 
     116                equalityBuffer.put(key, result); 
     117            } 
     118        } 
     119        else { 
     120            result = true; 
     121        } 
     122        //stopWatch.stop(id); 
     123         
     124        /*boolean result2 = nodeEqualityRuleManager.areAtLeastEqual(symbol1, symbol2, minimalNodeEquality); 
     125        if (result != result2) { 
     126            throw new IllegalStateException("implementation error"); 
     127        }*/ 
     128         
     129        return result; 
     130    } 
     131 
     132    /** 
     133     * <p> 
     134     * TODO: comment 
     135     * </p> 
     136     * 
     137     * @return 
     138     */ 
     139    StopWatch getStopWatch() { 
     140        return stopWatch; 
     141    } 
     142 
     143    /** 
     144     * <p> 
     145     * TODO: comment 
     146     * </p> 
     147     * 
     148     * @param node1 
     149     * @param node2 
     150     * @return 
     151     */ 
     152    boolean areLexicallyEqual(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 
     153        Boolean result; 
     154         
     155        if (symbol1 != symbol2) { 
     156            long key = ((long) System.identityHashCode(symbol1)) << 32; 
     157            key += System.identityHashCode(symbol2); 
     158             
     159            result = lexicalEqualityBuffer.get(key); 
     160             
     161            if (result == null) { 
     162                result = lexicalComparer.compare(symbol1, symbol2); 
     163                lexicalEqualityBuffer.put(key, result); 
     164            } 
     165        } 
     166        else { 
     167            result = true; 
     168        } 
     169         
     170        return result; 
     171    } 
     172 
     173    /** 
     174     * <p> 
     175     * TODO: comment 
     176     * </p> 
     177     * 
     178     * @return 
     179     */ 
     180    NodeEquality getConsideredNodeEquality() { 
     181        return minimalNodeEquality; 
     182    } 
     183 
     184    /** 
     185     *  
     186     */ 
     187    private interface Comparer { 
     188        /** 
     189         *  
     190         */ 
     191        boolean compare(ITaskTreeNode node1, ITaskTreeNode node2); 
     192    } 
     193 
     194    /** 
     195     *  
     196     */ 
     197    private class LexicalComparer implements Comparer { 
     198         
     199        /** 
     200         *  
     201         */ 
     202        public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
     203            return nodeEqualityRuleManager.areLexicallyEqual(node1, node2); 
     204        } 
     205    } 
     206 
     207    /** 
     208     *  
     209     */ 
     210    private class SyntacticalComparer implements Comparer { 
     211         
     212        /** 
     213         *  
     214         */ 
     215        public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
     216            return nodeEqualityRuleManager.areSyntacticallyEqual(node1, node2); 
     217        } 
     218    } 
     219 
     220    /** 
     221     *  
     222     */ 
     223    private class SemanticalComparer implements Comparer { 
     224         
     225        /** 
     226         *  
     227         */ 
     228        public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
     229            return nodeEqualityRuleManager.areSemanticallyEqual(node1, node2); 
     230        } 
     231    } 
     232 
     233    /** 
     234     *  
     235     */ 
     236    private class DefaultComparer implements Comparer { 
     237         
     238        /** 
     239         *  
     240         */ 
     241        public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
     242            return nodeEqualityRuleManager.areAtLeastEqual(node1, node2, minimalNodeEquality); 
     243        } 
     244    } 
    74245} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java

    r1113 r1127  
    157157 
    158158        treeScopeRules = new TemporalRelationshipRule[] { 
     159            new SequenceForTaskDetectionRule 
     160                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
     161                 taskTreeNodeFactory, taskTreeBuilder), 
     162            /*new DefaultTaskSequenceDetectionRule 
     163                (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
     164                 taskTreeNodeFactory, taskTreeBuilder), 
    159165            new DefaultTaskSequenceDetectionRule 
    160                 (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
    161                  taskTreeNodeFactory, taskTreeBuilder) 
     166                (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
     167                 taskTreeNodeFactory, taskTreeBuilder),*/ 
     168            /*new TreeScopeWrapperRule 
     169                (new DefaultIterationDetectionRule 
     170                    (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
     171                     taskTreeNodeFactory, taskTreeBuilder)), 
     172            new TreeScopeWrapperRule 
     173                (new DefaultIterationDetectionRule 
     174                    (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
     175                     taskTreeNodeFactory, taskTreeBuilder)), 
     176            new TreeScopeWrapperRule 
     177                (new DefaultIterationDetectionRule 
     178                    (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
     179                     taskTreeNodeFactory, taskTreeBuilder))*/ 
    162180        }; 
    163181         
     
    165183 
    166184        nodeScopeRules = new TemporalRelationshipRule[] { 
    167             //new DefaultGuiElementSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
    168             //new DefaultEventTargetSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     185            //new SequenceOnGuiElementDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     186            //new EventSequenceOnSameTargetDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
    169187            new TrackBarSelectionDetectionRule 
    170188                (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder), 
    171189            //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
    172             new DefaultIterationDetectionRule 
    173                 (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
    174                  taskTreeNodeFactory, taskTreeBuilder), 
    175             new DefaultIterationDetectionRule 
    176                 (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
    177                  taskTreeNodeFactory, taskTreeBuilder), 
    178             new DefaultIterationDetectionRule 
    179                 (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
    180                  taskTreeNodeFactory, taskTreeBuilder) 
    181190        }; 
    182191 
     
    245254 
    246255                if ((result != null) && 
    247                     (result.getRuleApplicationStatus() == 
    248                      RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 
     256                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 
    249257                { 
    250258                    Console.traceln 
     
    252260                    noOfRuleApplications++; 
    253261                     
    254                     dumpTask(parent, ""); 
     262                    //dumpTask(parent, ""); 
    255263 
    256264                    for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 
     
    261269            } 
    262270            while ((result != null) && 
    263                    (result.getRuleApplicationStatus() == 
    264                     RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 
     271                   (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 
    265272 
    266273            if ((!finalize) && 
    267274                (result != null) && 
    268                 (result.getRuleApplicationStatus() == 
    269                  RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 
     275                (result.getRuleApplicationStatus() == RuleApplicationStatus.FEASIBLE)) 
    270276            { 
    271277                // in this case, don't go on applying rules, which should not be applied yet 
     
    275281 
    276282        if (noOfRuleApplications <= 0) { 
    277             Console.traceln(Level.INFO, logIndent + "no rules applied --> no temporal " + 
     283            Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 
    278284                            "relationship generated"); 
    279285        } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java

    r1117 r1127  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
     17import java.util.List; 
     18 
    1719import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; 
    1820import de.ugoe.cs.autoquest.eventcore.guimodel.ITrackBar; 
    19 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    2021import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 
    2122import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     
    9798 
    9899        int index = 0; 
    99         while (index < parent.getChildren().size()) { 
    100             ITaskTreeNode child = parent.getChildren().get(index); 
     100        List<ITaskTreeNode> children = parent.getChildren(); 
     101         
     102        while (index < children.size()) { 
     103            ITaskTreeNode child = children.get(index); 
    101104 
    102105            if ((child instanceof IEventTask) && 
     
    128131            if (finalize) { 
    129132                handleValueSelections(parent, currentTrackBar, valueSelectionStartIndex, 
    130                                       parent.getChildren().size() - 1, result); 
     133                                      children.size() - 1, result); 
    131134            } 
    132135            else { 
    133                 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     136                result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 
    134137            } 
    135138        } 
     
    156159        taskTreeBuilder.setChild(iteration, selection); 
    157160 
     161        List<ITaskTreeNode> children = parent.getChildren(); 
     162         
    158163        for (int i = endIndex - startIndex; i >= 0; i--) { 
    159             addChildIfNecessary(selection, parent.getChildren().get(startIndex), result); 
     164            addChildIfNecessary(selection, children.get(startIndex), result); 
    160165            taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    161166        } 
     
    163168        taskTreeBuilder.addChild((ISequence) parent, startIndex, iteration); 
    164169 
    165         result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     170        result.setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 
    166171    } 
    167172 
     
    173178                                     RuleApplicationResult result) 
    174179    { 
    175         for (int i = 0; i < parentSelection.getChildren().size(); i++) { 
    176             ITaskTreeNode child = parentSelection.getChildren().get(i); 
     180        List<ITaskTreeNode> children = parentSelection.getChildren(); 
     181         
     182        for (int i = 0; i < children.size(); i++) { 
     183            ITaskTreeNode child = children.get(i); 
    177184 
    178185            // check, if the new node is a variant for the current event task 
    179             NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 
    180             if (nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 
     186            if (nodeEqualityRuleManager.areSyntacticallyEqual(child, node)) { 
    181187                return; 
    182188            } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TreeScopeWrapperRule.java

    r1119 r1127  
    1414 
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
     16 
     17import java.util.List; 
    1618 
    1719import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     
    6971            result = new RuleApplicationResult(); 
    7072             
    71             if (parent.getChildren() != null) { 
    72                 for (ITaskTreeNode child : parent.getChildren()) { 
     73            List<ITaskTreeNode> children = parent.getChildren(); 
     74            if (children != null) { 
     75                for (ITaskTreeNode child : children) { 
    7376                    merge(result, apply(child, finalize)); 
    7477                } 
     
    97100        RuleApplicationStatus intermediateStatus = intermediate.getRuleApplicationStatus(); 
    98101         
    99         if ((intermediateStatus == RuleApplicationStatus.RULE_APPLICATION_FINISHED) || 
    100             ((intermediateStatus == RuleApplicationStatus.RULE_APPLICATION_FEASIBLE) && 
    101              (overallStatus == RuleApplicationStatus.RULE_NOT_APPLIED))) 
     102        if ((intermediateStatus == RuleApplicationStatus.FINISHED) || 
     103            ((intermediateStatus == RuleApplicationStatus.FEASIBLE) && 
     104             (overallStatus == RuleApplicationStatus.NOT_APPLIED))) 
    102105        { 
    103106            overallResult.setRuleApplicationStatus(intermediateStatus); 
Note: See TracChangeset for help on using the changeset viewer.