Changeset 1107


Ignore:
Timestamp:
02/21/13 18:39:13 (12 years ago)
Author:
pharms
Message:
  • changed rules to be testable on their own
  • added first version for a task detection rule
  • refactored rules to have a simpler interface
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation
Files:
3 added
1 deleted
7 edited

Legend:

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

    r985 r1107  
    1515 * @author 2012, last modified by $Author: patrick$ 
    1616 */ 
    17 public class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 
     17class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 
    1818 
     19    /** 
     20     * <p> 
     21     * the task tree node factory to be used for creating substructures for the temporal 
     22     * relationships identified during rule 
     23     * </p> 
     24     */ 
     25    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     26    /** 
     27     * <p> 
     28     * the task tree builder to be used for creating substructures for the temporal relationships 
     29     * identified during rule application 
     30     * </p> 
     31     */ 
     32    private ITaskTreeBuilder taskTreeBuilder; 
     33     
     34    /** 
     35     * <p> 
     36     * instantiates the rule with a task tree node factory and builder to be used during rule 
     37     * application. 
     38     * </p> 
     39     *  
     40     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     41     *                            for the temporal relationships identified during rule 
     42     *                            application 
     43     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     44     *                            the temporal relationships identified during rule application 
     45     */ 
     46    DefaultEventTargetSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     47                                            ITaskTreeBuilder     taskTreeBuilder) 
     48    { 
     49        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     50        this.taskTreeBuilder = taskTreeBuilder; 
     51    } 
     52     
    1953    /* 
    2054     * (non-Javadoc) 
    2155     *  
    2256     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
    23      * TaskTreeBuilder, TaskTreeNodeFactory) 
     57     * boolean) 
    2458     */ 
    2559    @Override 
    26     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    27                                        ITaskTreeBuilder     builder, 
    28                                        ITaskTreeNodeFactory nodeFactory, 
    29                                        boolean              finalize) 
    30     { 
     60    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    3161        if (!(parent instanceof ISequence)) { 
    3262            return null; 
     
    5989                        (!(parent.getChildren().get(startingIndex) instanceof ISequence))) 
    6090                    { 
    61                         handleEventTargetSequence(parent, currentEventTarget, startingIndex, 
    62                                                   endIndex, builder, nodeFactory, result); 
     91                        handleEventTargetSequence 
     92                            (parent, currentEventTarget, startingIndex, endIndex, result); 
    6393 
    6494                        result.setRuleApplicationStatus 
     
    91121                     (!(parent.getChildren().get(startingIndex) instanceof ISequence)))) 
    92122                { 
    93                     handleEventTargetSequence(parent, currentEventTarget, startingIndex, endIndex, 
    94                                               builder, nodeFactory, result); 
     123                    handleEventTargetSequence 
     124                        (parent, currentEventTarget, startingIndex, endIndex, result); 
    95125                 
    96126                    result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     
    106136 
    107137    /** 
    108      * TODO: comment 
    109      *  
    110      * @param child 
    111      * @return 
     138     * 
    112139     */ 
    113140    private IEventTarget determineEventTarget(ITaskTreeNode node) { 
     
    134161 
    135162    /** 
    136      * TODO: comment 
    137      *  
     163     * 
    138164     */ 
    139165    private void handleEventTargetSequence(ITaskTreeNode         parent, 
     
    141167                                           int                   startIndex, 
    142168                                           int                   endIndex, 
    143                                            ITaskTreeBuilder      builder, 
    144                                            ITaskTreeNodeFactory  nodeFactory, 
    145169                                           RuleApplicationResult result) 
    146170    { 
    147         ISequence sequence = nodeFactory.createNewSequence(); 
    148         builder.setDescription(sequence, "interactions on " + target.getStringIdentifier()); 
    149  
    150         for (int i = startIndex; i <= endIndex; i++) { 
    151             builder.addChild(sequence, parent.getChildren().get(startIndex)); 
    152             builder.removeChild((ISequence) parent, startIndex); 
    153         } 
    154  
    155         builder.addChild((ISequence) parent, startIndex, sequence); 
     171        String description = "interactions on " + target.getStringIdentifier(); 
     172         
     173        ISequence sequence = RuleUtils.createNewSubSequenceInRange 
     174            (parent, startIndex, endIndex, description, taskTreeNodeFactory, taskTreeBuilder); 
    156175 
    157176        result.addNewlyCreatedParentNode(sequence); 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRule.java

    r993 r1107  
    2020 * @author 2012, last modified by $Author: patrick$ 
    2121 */ 
    22 public class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule { 
    23  
     22class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule { 
     23 
     24    /** 
     25     * <p> 
     26     * the task tree node factory to be used for creating substructures for the temporal 
     27     * relationships identified during rule 
     28     * </p> 
     29     */ 
     30    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     31    /** 
     32     * <p> 
     33     * the task tree builder to be used for creating substructures for the temporal relationships 
     34     * identified during rule application 
     35     * </p> 
     36     */ 
     37    private ITaskTreeBuilder taskTreeBuilder; 
     38     
    2439    /** 
    2540     * <p> 
     
    3146    /** 
    3247     * <p> 
    33      * instantiates the rule without a GUI element filter 
    34      * </p> 
    35      */ 
    36     DefaultGuiElementSequenceDetectionRule() { 
    37         this.guiElementFilter = null; 
    38     } 
    39  
     48     * instantiates the rule with a task tree node factory and builder to be used during rule 
     49     * application but without a GUI element filter 
     50     * </p> 
     51     *  
     52     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     53     *                            for the temporal relationships identified during rule 
     54     *                            application 
     55     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     56     *                            the temporal relationships identified during rule application 
     57     */ 
     58    DefaultGuiElementSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     59                                           ITaskTreeBuilder     taskTreeBuilder) 
     60    { 
     61        this(null, taskTreeNodeFactory, taskTreeBuilder); 
     62    } 
     63     
    4064    /** 
    4165     * <p> 
     
    4569     * </p> 
    4670     * 
    47      * @param guiElementFilter the GUI element filter to be applied 
    48      */ 
    49     DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter) { 
     71     * @param guiElementFilter    the GUI element filter to be applied 
     72     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     73     *                            for the temporal relationships identified during rule 
     74     *                            application 
     75     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     76     *                            the temporal relationships identified during rule application 
     77     */ 
     78    DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter, 
     79                                           ITaskTreeNodeFactory taskTreeNodeFactory, 
     80                                           ITaskTreeBuilder     taskTreeBuilder) 
     81    { 
    5082        this.guiElementFilter = guiElementFilter; 
     83        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     84        this.taskTreeBuilder = taskTreeBuilder; 
    5185    } 
    5286 
     
    5589     *  
    5690     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
    57      * TaskTreeBuilder, TaskTreeNodeFactory) 
     91     * boolean) 
    5892     */ 
    5993    @Override 
    60     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    61                                        ITaskTreeBuilder     builder, 
    62                                        ITaskTreeNodeFactory nodeFactory, 
    63                                        boolean              finalize) 
    64     { 
     94    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    6595        if (!(parent instanceof ISequence)) { 
    6696            return null; 
     
    95125        // anything. 
    96126         
    97         RuleApplicationStatus status; 
     127        RuleApplicationStatus status = null; 
    98128        if (initialHierarchyLevel < maxHierarchyDepth) { 
    99             status = generateSubSequences(parent, hierarchies, initialHierarchyLevel, finalize, 
    100                                           builder, nodeFactory, result); 
    101         } 
    102         else { 
     129            status = generateSubSequences 
     130                (parent, hierarchies, initialHierarchyLevel, finalize, result); 
     131        } 
     132         
     133        if (status == null) { 
    103134            status = RuleApplicationStatus.RULE_NOT_APPLIED; 
    104135        } 
     
    121152     * @param maxHierarchyDepth the maximum hierarchy depth that may apply in this application 
    122153     * @param finalize          true, if the application shall be finalized, false else 
    123      * @param builder           the builder to use for generating the tree structure 
    124      * @param nodeFactory       the node factory to use for generating the tree structure 
    125154     * @param result            the result of the rule application to add newly created parent 
    126155     *                          nodes to 
     
    136165                                                       int                     hierarchyLevel, 
    137166                                                       boolean                 finalize, 
    138                                                        ITaskTreeBuilder        builder, 
    139                                                        ITaskTreeNodeFactory    nodeFactory, 
    140167                                                       RuleApplicationResult   result) 
    141168    { 
     
    169196            } 
    170197            else if (nextGuiElementDiffers) { 
    171                 status = condenseSequence(parent, hierarchies, hierarchyLevel, startingIndex, 
    172                                           index - 1, builder, nodeFactory, result); 
     198                status = condenseSequence 
     199                    (parent, hierarchies, hierarchyLevel, startingIndex, index - 1, result); 
    173200 
    174201                if (status != null) { 
     
    195222                status = condenseSequence 
    196223                    (parent, hierarchies, hierarchyLevel, startingIndex, 
    197                      parent.getChildren().size() - 1, builder, nodeFactory, result); 
     224                     parent.getChildren().size() - 1, result); 
    198225            } 
    199226            else if (status != RuleApplicationStatus.RULE_APPLICATION_FINISHED) { 
     
    225252     * @param startIndex     the index of the first child belonging to the subgroup 
    226253     * @param endIndex       the index of the last child belonging to the subgroup 
    227      * @param builder        the builder to use for generating the tree structure 
    228      * @param nodeFactory    the node factory to use for generating the tree structure 
    229254     * @param result         the result of the rule application to add newly created parent nodes to 
    230255     *  
     
    238263                                                   int                     startIndex, 
    239264                                                   int                     endIndex, 
    240                                                    ITaskTreeBuilder        builder, 
    241                                                    ITaskTreeNodeFactory    nodeFactory, 
    242265                                                   RuleApplicationResult   result) 
    243266    { 
     
    247270 
    248271        if (!onlyASingleChildToReduce || !singleChildIsSequence) { 
    249             ISequence sequence = nodeFactory.createNewSequence(); 
     272            ISequence sequence = taskTreeNodeFactory.createNewSequence(); 
    250273             
    251274            List<List<IGUIElement>> subHierarchies = new ArrayList<List<IGUIElement>>(); 
    252275            List<IGUIElement> newHierarchy = 
    253276                hierarchies.get(startIndex).subList(0, hierarchyLevel + 1); 
    254             builder.setDescription(sequence, "interactions on " + 
    255                                    newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier()); 
     277            taskTreeBuilder.setDescription 
     278                (sequence, "interactions on " + 
     279                 newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier()); 
    256280 
    257281            for (int i = startIndex; i <= endIndex; i++) { 
    258                 builder.addChild(sequence, parent.getChildren().get(startIndex)); 
    259                 builder.removeChild((ISequence) parent, startIndex); 
     282                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     283                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    260284                 
    261285                subHierarchies.add(hierarchies.remove(startIndex)); 
    262286            } 
    263287 
    264             builder.addChild((ISequence) parent, startIndex, sequence); 
     288            taskTreeBuilder.addChild((ISequence) parent, startIndex, sequence); 
    265289             
    266290            hierarchies.add(startIndex, newHierarchy); 
    267291             
    268             generateSubSequences 
    269                 (sequence, subHierarchies, hierarchyLevel + 1, true, builder, nodeFactory, result); 
     292            generateSubSequences(sequence, subHierarchies, hierarchyLevel + 1, true, result); 
    270293 
    271294            result.addNewlyCreatedParentNode(sequence); 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java

    r987 r1107  
    11package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
     2 
     3import java.util.Stack; 
    24 
    35import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 
     
    1820 * @author 2012, last modified by $Author: patrick$ 
    1921 */ 
    20 public class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 
     22class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 
    2123 
     24    /** 
     25     * <p> 
     26     * the task tree node factory to be used for creating substructures for the temporal 
     27     * relationships identified during rule 
     28     * </p> 
     29     */ 
     30    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     31    /** 
     32     * <p> 
     33     * the task tree builder to be used for creating substructures for the temporal relationships 
     34     * identified during rule application 
     35     * </p> 
     36     */ 
     37    private ITaskTreeBuilder taskTreeBuilder; 
     38     
     39    /** 
     40     * <p> 
     41     * instantiates the rule with a task tree node factory and builder to be used during rule 
     42     * application. 
     43     * </p> 
     44     *  
     45     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     46     *                            for the temporal relationships identified during rule 
     47     *                            application 
     48     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     49     *                            the temporal relationships identified during rule application 
     50     */ 
     51    DefaultGuiEventSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     52                                         ITaskTreeBuilder     taskTreeBuilder) 
     53    { 
     54        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     55        this.taskTreeBuilder = taskTreeBuilder; 
     56    } 
     57     
    2258    /* 
    2359     * (non-Javadoc) 
    2460     *  
    2561     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
    26      * TaskTreeBuilder, TaskTreeNodeFactory) 
     62     * boolean) 
    2763     */ 
    2864    @Override 
    29     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    30                                        ITaskTreeBuilder     builder, 
    31                                        ITaskTreeNodeFactory nodeFactory, 
    32                                        boolean              finalize) 
    33     { 
     65    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    3466        if (!(parent instanceof ISequence)) { 
    3567            return null; 
     
    3769 
    3870        RuleApplicationResult result = new RuleApplicationResult(); 
    39         int sequenceStartingIndex = -1; 
     71        Stack<Integer> sequenceStartingIndex = new Stack<Integer>(); 
    4072 
    4173        int index = 0; 
     
    4779            { 
    4880                IInteraction eventType = (IInteraction) ((IEventTask) child).getEventType(); 
    49                  
    50                 if (eventType.finishesLogicalSequence() && (sequenceStartingIndex > -1)) 
    51                 { 
    52                     // There are several situations in which this implementation may cause infinite 
    53                     // loops. This is because the rule manager will reapply rules until 
    54                     // no rule is applied anymore. A sequence identified in a first iteration will 
    55                     // be identified as a sequence also in a second iteration. As an example 
    56                     // many sequences start with an interaction starting that sequence and end 
    57                     // with an interaction ending that sequence. This will be reidentified as 
    58                     // further subsequence. It must therefore be assured, that a sequence, that 
    59                     // was once identified is not reidentified in a further application of the rule. 
    60                     // For this, the implementation performs a kind of dry run. It creates a list of 
    61                     // children that would belong to an identified sequence. Only if this list is 
    62                     // not a reidentification then a new sequence is created and added to the 
    63                     // parent. If it is a reidentification can be identified, if the list of 
    64                     // children will contain all children of the parent, or if the list of children 
    65                     // only consists of one sequence. Further, an identified sequence must at least 
    66                     // have one child. 
    67                     if (((sequenceStartingIndex != 0) || 
    68                          (index != (parent.getChildren().size() - 1))) && 
    69                         (((index - sequenceStartingIndex) > 0) || 
    70                           (((index - sequenceStartingIndex) == 0) && 
    71                            (!eventType.startsLogicalSequence())))) 
    72                     { 
    73                         boolean allNewChildrenAreSequences = true; 
    7481 
    75                         for (int j = sequenceStartingIndex; 
    76                              ((allNewChildrenAreSequences) && (j < index)); j++) 
    77                         { 
    78                             allNewChildrenAreSequences &= 
    79                                 (parent.getChildren().get(j) instanceof ISequence); 
    80                         } 
    81  
    82                         if (!allNewChildrenAreSequences) { 
    83                             ISequence sequence = nodeFactory.createNewSequence(); 
    84  
    85                             for (int j = sequenceStartingIndex; j < index; j++) { 
    86                                 builder.addChild 
    87                                     (sequence, parent.getChildren().get(sequenceStartingIndex)); 
    88                                 builder.removeChild((ISequence) parent, sequenceStartingIndex); 
    89                             } 
    90  
    91                             if (!eventType.startsLogicalSequence()) { 
    92                                 builder.addChild 
    93                                     (sequence, parent.getChildren().get(sequenceStartingIndex)); 
    94                                 builder.removeChild((ISequence) parent, sequenceStartingIndex); 
    95                             } 
    96  
    97                             builder.addChild((ISequence) parent, sequenceStartingIndex, sequence); 
    98  
    99                             result.addNewlyCreatedParentNode(sequence); 
    100                              
    101                             builder.setDescription 
    102                                 (sequence, "logical sequence started by the first event"); 
    103                              
    104                             result.setRuleApplicationStatus 
    105                                 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
    106                             return result; 
    107                         } 
    108                     } 
     82                if (eventType.finishesLogicalSequence() && (sequenceStartingIndex.size() > 0)) { 
     83                    index = handleLogicalSequence(sequenceStartingIndex, index, parent, result); 
    10984                } 
    11085 
    11186                if (eventType.startsLogicalSequence()) { 
    112                     sequenceStartingIndex = index; 
     87                    sequenceStartingIndex.push(index); 
    11388                } 
    11489            } 
     
    11792        } 
    11893 
    119         if (sequenceStartingIndex >= 0) { 
    120             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     94        if (sequenceStartingIndex.size() > 0) { 
     95            if (!finalize) { 
     96                result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 
     97            } 
     98            else { 
     99                ITaskTreeNode lastChild = parent.getChildren().get(parent.getChildren().size() - 1); 
     100                 
     101                if (lastChild instanceof IEventTask) { 
     102                    handleLogicalSequence 
     103                        (sequenceStartingIndex, parent.getChildren().size() - 1, parent, result); 
     104                } 
     105            } 
    121106        } 
    122107 
     
    124109    } 
    125110 
     111    /** 
     112     * <p> 
     113     * TODO: comment 
     114     * </p> 
     115     * 
     116     */ 
     117    private int handleLogicalSequence(Stack<Integer>        sequenceStartingIndex, 
     118                                      int                   index, 
     119                                      ITaskTreeNode         parent, 
     120                                      RuleApplicationResult result) 
     121    { 
     122        int newIndex = index; 
     123        IInteraction eventType = 
     124            (IInteraction) ((IEventTask) parent.getChildren().get(index)).getEventType(); 
     125 
     126        // There are several situations in which this implementation may cause infinite 
     127        // loops. This is because the rule manager will reapply rules until 
     128        // no rule is applied anymore. A sequence identified in a first iteration will 
     129        // be identified as a sequence also in a second iteration. As an example 
     130        // many sequences start with an interaction starting that sequence and end 
     131        // with an interaction ending that sequence. This will be reidentified as 
     132        // further subsequence. It must therefore be assured, that a sequence, that 
     133        // was once identified is not reidentified in a further application of the rule. 
     134        // For this, the implementation performs a kind of dry run. It creates a list of 
     135        // children that would belong to an identified sequence. Only if this list is 
     136        // not a reidentification then a new sequence is created and added to the 
     137        // parent. If it is a reidentification can be identified, if the list of 
     138        // children will contain all children of the parent, or if the list of children 
     139        // only consists of one sequence. Further, an identified sequence must at least 
     140        // have one child. 
     141         
     142        boolean allChildrenBelongToSubSequence = 
     143            (sequenceStartingIndex.peek() == 0) && (index == (parent.getChildren().size() - 1)); 
     144         
     145        boolean atLeastOneChildToCondense = index - sequenceStartingIndex.peek() > 0; 
     146         
     147        if (!allChildrenBelongToSubSequence && atLeastOneChildToCondense) { 
     148            int startIndex = sequenceStartingIndex.pop(); 
     149            ISequence sequence = taskTreeNodeFactory.createNewSequence(); 
     150 
     151            for (int j = startIndex; j < index; j++) { 
     152                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     153                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
     154            } 
     155 
     156            if (!eventType.startsLogicalSequence()) { 
     157                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     158                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
     159                newIndex = startIndex; 
     160            } 
     161            else { 
     162                newIndex = startIndex + 1; 
     163            } 
     164 
     165            taskTreeBuilder.addChild((ISequence) parent, startIndex, sequence); 
     166 
     167            result.addNewlyCreatedParentNode(sequence); 
     168                 
     169            taskTreeBuilder.setDescription(sequence, "logical sequence started by the first event"); 
     170                 
     171            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     172        } 
     173         
     174        return newIndex; 
     175    } 
     176 
    126177} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java

    r1045 r1107  
    6161 * @author Patrick Harms 
    6262 */ 
    63 public class DefaultIterationDetectionRule implements TemporalRelationshipRule { 
    64      
     63class DefaultIterationDetectionRule implements TemporalRelationshipRule { 
     64 
     65    /** 
     66     * <p> 
     67     * the maximum length for iterated sequences 
     68     * </p> 
     69     */ 
    6570    private static final int MAX_LENGTH_OF_ITERATED_SEQUENCE = 50; 
    6671     
    6772    /** 
    6873     * <p> 
     74     * the task tree node factory to be used for creating substructures for the temporal 
     75     * relationships identified during rule 
     76     * </p> 
     77     */ 
     78    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     79    /** 
     80     * <p> 
     81     * the task tree builder to be used for creating substructures for the temporal relationships 
     82     * identified during rule application 
     83     * </p> 
     84     */ 
     85    private ITaskTreeBuilder taskTreeBuilder; 
     86 
     87    /** 
     88     * <p> 
    6989     * the node equality manager needed for comparing task tree nodes with each other 
    7090     * </p> 
     
    87107     */ 
    88108    DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
    89                                   NodeEquality            minimalNodeEquality) 
     109                                  NodeEquality            minimalNodeEquality, 
     110                                  ITaskTreeNodeFactory    taskTreeNodeFactory, 
     111                                  ITaskTreeBuilder        taskTreeBuilder) 
    90112    { 
    91         super(); 
    92113        this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
    93114        this.minimalNodeEquality = minimalNodeEquality; 
     115        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     116        this.taskTreeBuilder = taskTreeBuilder; 
    94117    } 
    95118 
     
    97120     * (non-Javadoc) 
    98121     *  
    99      * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 
     122     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
     123     * boolean) 
    100124     */ 
    101125    @Override 
    102     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    103                                        ITaskTreeBuilder     treeBuilder, 
    104                                        ITaskTreeNodeFactory nodeFactory, 
    105                                        boolean              finalize) 
    106     { 
     126    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    107127        if (!(parent instanceof ISequence)) { 
    108128            return null; 
     
    122142         
    123143         
    124         SubSequences subSequences = getEqualSubsequences(parent, treeBuilder, nodeFactory); 
     144        SubSequences subSequences = getEqualSubsequences(parent); 
    125145 
    126146        if (subSequences != null) { 
    127147            RuleApplicationResult result = new RuleApplicationResult(); 
    128148 
    129             mergeEqualNodes(subSequences.equalVariants, treeBuilder, nodeFactory); 
    130             IIteration newIteration = createIterationBasedOnIdentifiedVariants 
    131                 (subSequences, treeBuilder, nodeFactory, result); 
     149            mergeEqualNodes(subSequences.equalVariants); 
     150            IIteration newIteration = 
     151                createIterationBasedOnIdentifiedVariants(subSequences, result); 
    132152 
    133153            determineNewlyCreatedParentTasks(parent, newIteration, result); 
     
    135155            // remove iterated children 
    136156            for (int j = subSequences.start; j < subSequences.end; j++) { 
    137                 treeBuilder.removeChild((ISequence) parent, subSequences.start); 
     157                taskTreeBuilder.removeChild((ISequence) parent, subSequences.start); 
    138158            } 
    139159 
    140160            // add the new iteration instead 
    141             treeBuilder.addChild((ISequence) parent, subSequences.start, newIteration); 
     161            taskTreeBuilder.addChild((ISequence) parent, subSequences.start, newIteration); 
    142162 
    143163            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     
    161181     *  
    162182     * @param parent      the parent node in which iterations of children shall be found 
    163      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    164      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    165183     *  
    166184     * @return the iterated subsequences identified in a specific part (contains the equal 
     
    168186     *         subpart in which the sequences were found)  
    169187     */ 
    170     private SubSequences getEqualSubsequences(ITaskTreeNode        parent, 
    171                                               ITaskTreeBuilder     treeBuilder, 
    172                                               ITaskTreeNodeFactory nodeFactory) 
    173     { 
     188    private SubSequences getEqualSubsequences(ITaskTreeNode parent) { 
    174189        SubSequences subSequences = null; 
    175190 
     
    184199 
    185200                boolean foundFurtherVariants = findFurtherVariants 
    186                     (subSequences, parent, start, end, treeBuilder, nodeFactory, 
    187                      useEqualSublistLengths); 
     201                    (subSequences, parent, start, end, useEqualSublistLengths); 
    188202 
    189203                if (foundFurtherVariants) { 
     
    247261     * @param end                    the end index (exclusive) of the current subpart of children 
    248262     *                               in which iterations are searched for 
    249      * @param treeBuilder            the tree builder that can be used for connecting task tree 
    250      *                               nodes 
    251      * @param nodeFactory            the node factory that can be used for instantiating task tree 
    252      *                               nodes 
    253263     * @param useEqualSublistLengths true if the sublists to be searched for all need to have the 
    254264     *                               same length 
     
    260270                                        int                  start, 
    261271                                        int                  end, 
    262                                         ITaskTreeBuilder     treeBuilder, 
    263                                         ITaskTreeNodeFactory nodeFactory, 
    264272                                        boolean              useEqualSublistLengths) 
    265273    { 
     
    279287            } 
    280288             
    281             ISequence furtherVariant = nodeFactory.createNewSequence(); 
     289            ISequence furtherVariant = taskTreeNodeFactory.createNewSequence(); 
    282290             
    283291            for (int j = start; j < start + childCount; j++) { 
    284                 treeBuilder.addChild(furtherVariant, parent.getChildren().get(j)); 
     292                taskTreeBuilder.addChild(furtherVariant, parent.getChildren().get(j)); 
    285293            } 
    286294             
     
    305313                 
    306314                foundFurtherVariants = findFurtherVariants 
    307                     (subSequences, parent, start + childCount, end, treeBuilder, nodeFactory, 
    308                      useEqualSublistLengths); 
     315                    (subSequences, parent, start + childCount, end, useEqualSublistLengths); 
    309316 
    310317                if (foundFurtherVariants) { 
     
    331338     * 
    332339     * @param nodes       the list of nodes to be merged 
    333      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    334      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    335      */ 
    336     private void mergeEqualNodes(List<ITaskTreeNode>   nodes, 
    337                                  ITaskTreeBuilder      treeBuilder, 
    338                                  ITaskTreeNodeFactory  nodeFactory) 
    339     { 
     340     */ 
     341    private void mergeEqualNodes(List<ITaskTreeNode> nodes) { 
    340342        int index1 = 0; 
    341343        int index2 = 0; 
     
    349351            while (index2 < nodes.size()) { 
    350352                variant2 = nodes.get(index2); 
    351                 ITaskTreeNode mergedChild = 
    352                     mergeEqualTasks(variant1, variant2, treeBuilder, nodeFactory); 
     353                ITaskTreeNode mergedChild = mergeEqualTasks(variant1, variant2); 
    353354                 
    354355                if (mergedChild != null) { 
     
    382383     * @param node1       the first task to be merged 
    383384     * @param node2       the second task to be merged 
    384      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    385      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    386385     *  
    387386     * @return the result of the merge 
    388387     */ 
    389     private ITaskTreeNode mergeEqualTasks(ITaskTreeNode         node1, 
    390                                           ITaskTreeNode         node2, 
    391                                           ITaskTreeBuilder      treeBuilder, 
    392                                           ITaskTreeNodeFactory  nodeFactory) 
    393     { 
     388    private ITaskTreeNode mergeEqualTasks(ITaskTreeNode node1, ITaskTreeNode node2) { 
    394389        ITaskTreeNode mergeResult = null; 
    395390         
    396391        if ((node1 instanceof ISequence) && (node2 instanceof ISequence)) { 
    397             mergeResult = mergeEqualSequences 
    398                 ((ISequence) node1, (ISequence) node2, treeBuilder, nodeFactory); 
     392            mergeResult = mergeEqualSequences((ISequence) node1, (ISequence) node2); 
    399393        } 
    400394        else if ((node1 instanceof ISelection) && (node2 instanceof ISelection)) { 
    401             mergeResult = mergeEqualSelections 
    402                 ((ISelection) node1, (ISelection) node2, treeBuilder, nodeFactory); 
     395            mergeResult = mergeEqualSelections((ISelection) node1, (ISelection) node2); 
    403396        } 
    404397        else if ((node1 instanceof IIteration) && (node2 instanceof IIteration)) { 
    405             mergeResult = mergeEqualIterations 
    406                 ((IIteration) node1, (IIteration) node2, treeBuilder, nodeFactory); 
     398            mergeResult = mergeEqualIterations((IIteration) node1, (IIteration) node2); 
    407399        } 
    408400        else if (node1 instanceof ISelection) { 
    409             treeBuilder.addChild((ISelection) node1, node2); 
     401            taskTreeBuilder.addChild((ISelection) node1, node2); 
    410402            mergeResult = node1; 
    411403        } 
    412404        else if (node2 instanceof ISelection) { 
    413             treeBuilder.addChild((ISelection) node2, node1); 
     405            taskTreeBuilder.addChild((ISelection) node2, node1); 
    414406            mergeResult = node2; 
    415407        } 
    416408        else if (node1 instanceof IIteration) { 
    417             mergeResult = mergeEqualTasks 
    418                 (((IIteration) node1).getChildren().get(0), node2, treeBuilder, nodeFactory); 
     409            mergeResult = mergeEqualTasks(((IIteration) node1).getChildren().get(0), node2); 
    419410             
    420411            if (mergeResult != null) { 
    421                 IIteration iteration = nodeFactory.createNewIteration(); 
    422                 treeBuilder.setChild(iteration, mergeResult); 
     412                IIteration iteration = taskTreeNodeFactory.createNewIteration(); 
     413                taskTreeBuilder.setChild(iteration, mergeResult); 
    423414                mergeResult = iteration; 
    424415            } 
    425416        } 
    426417        else if (node2 instanceof IIteration) { 
    427             mergeResult = mergeEqualTasks 
    428                 (((IIteration) node2).getChildren().get(0), node1, treeBuilder, nodeFactory); 
     418            mergeResult = mergeEqualTasks(((IIteration) node2).getChildren().get(0), node1); 
    429419             
    430420            if (mergeResult != null) { 
    431                 IIteration iteration = nodeFactory.createNewIteration(); 
    432                 treeBuilder.setChild(iteration, mergeResult); 
     421                IIteration iteration = taskTreeNodeFactory.createNewIteration(); 
     422                taskTreeBuilder.setChild(iteration, mergeResult); 
    433423                mergeResult = iteration; 
    434424            } 
     
    443433 
    444434        if (mergeResult == null) { 
    445             mergeResult = nodeFactory.createNewSelection(); 
    446             treeBuilder.addChild((ISelection) mergeResult, node1); 
    447             treeBuilder.addChild((ISelection) mergeResult, node2); 
     435            mergeResult = taskTreeNodeFactory.createNewSelection(); 
     436            taskTreeBuilder.addChild((ISelection) mergeResult, node1); 
     437            taskTreeBuilder.addChild((ISelection) mergeResult, node2); 
    448438        } 
    449439         
     
    463453     * @param sequence1   the first sequence to be merged 
    464454     * @param sequence2   the second sequence to be merged 
    465      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    466      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    467455     *  
    468456     * @return the result of the merge or null if merging was not possible 
    469457     */ 
    470     private ISequence mergeEqualSequences(ISequence             sequence1, 
    471                                           ISequence             sequence2, 
    472                                           ITaskTreeBuilder      treeBuilder, 
    473                                           ITaskTreeNodeFactory  nodeFactory) 
    474     { 
     458    private ISequence mergeEqualSequences(ISequence sequence1, ISequence sequence2) { 
    475459        ISequence mergeResult = null; 
    476460         
    477461        if (sequence1.getChildren().size() == sequence2.getChildren().size()) { 
    478             mergeResult = nodeFactory.createNewSequence(); 
     462            mergeResult = taskTreeNodeFactory.createNewSequence(); 
    479463             
    480464            for (int i = 0; i < sequence1.getChildren().size(); i++) { 
    481465                ITaskTreeNode mergedNode = mergeEqualTasks 
    482                     (sequence1.getChildren().get(i), sequence2.getChildren().get(i), 
    483                      treeBuilder, nodeFactory); 
     466                    (sequence1.getChildren().get(i), sequence2.getChildren().get(i)); 
    484467                 
    485468                if (mergedNode != null) { 
    486                     treeBuilder.addChild(mergeResult, mergedNode); 
     469                    taskTreeBuilder.addChild(mergeResult, mergedNode); 
    487470                } 
    488471                else { 
     
    506489     * @param selection1  the first selection to be merged 
    507490     * @param selection2  the second selection to be merged 
    508      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    509      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    510491     *  
    511492     * @return the result of the merge which is never null 
    512493     */ 
    513     private ITaskTreeNode mergeEqualSelections(ISelection            selection1, 
    514                                                ISelection            selection2, 
    515                                                ITaskTreeBuilder      treeBuilder, 
    516                                                ITaskTreeNodeFactory  nodeFactory) 
    517     { 
     494    private ITaskTreeNode mergeEqualSelections(ISelection selection1, ISelection selection2) { 
    518495        ISelection mergeResult = selection1; 
    519496         
     
    526503            childToMerge = selection2.getChildren().get(i); 
    527504            for (int j = 0; j < selection1.getChildren().size(); j++) { 
    528                 mergedChild = mergeEqualTasks 
    529                     (selection1.getChildren().get(j), childToMerge, treeBuilder, nodeFactory); 
     505                mergedChild = mergeEqualTasks(selection1.getChildren().get(j), childToMerge); 
    530506                 
    531507                // a merge must not be a selection, except it is one of the children. Otherwise 
     
    538514                    // we found a real merge. So replace the original child in selection 1 with 
    539515                    // the merged child 
    540                     treeBuilder.removeChild(selection1, selection1.getChildren().get(j)); 
    541                     treeBuilder.addChild(selection1, mergedChild); 
     516                    taskTreeBuilder.removeChild(selection1, selection1.getChildren().get(j)); 
     517                    taskTreeBuilder.addChild(selection1, mergedChild); 
    542518                    mergedChild = null; 
    543519                    childToMerge = null; 
     
    547523             
    548524            if (childToMerge != null) { 
    549                 treeBuilder.addChild(selection1, childToMerge); 
     525                taskTreeBuilder.addChild(selection1, childToMerge); 
    550526            } 
    551527        } 
     
    563539     * @param selection1  the first iteration to be merged 
    564540     * @param selection2  the second iteration to be merged 
    565      * @param treeBuilder the tree builder that can be used for connecting task tree nodes 
    566      * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    567541     *  
    568542     * @return the result of the merge or null if merging is not possible 
    569543     */ 
    570     private ITaskTreeNode mergeEqualIterations(IIteration            iteration1, 
    571                                                IIteration            iteration2, 
    572                                                ITaskTreeBuilder      treeBuilder, 
    573                                                ITaskTreeNodeFactory  nodeFactory) 
    574     { 
     544    private ITaskTreeNode mergeEqualIterations(IIteration iteration1, IIteration iteration2) { 
    575545        ITaskTreeNode mergedChild = mergeEqualTasks 
    576             (iteration1.getChildren().get(0), iteration2.getChildren().get(0), 
    577              treeBuilder, nodeFactory); 
     546            (iteration1.getChildren().get(0), iteration2.getChildren().get(0)); 
    578547         
    579548        IIteration mergeResult = null; 
    580549         
    581550        if (mergedChild != null) { 
    582             mergeResult = nodeFactory.createNewIteration(); 
    583             treeBuilder.setChild(mergeResult, mergedChild); 
     551            mergeResult = taskTreeNodeFactory.createNewIteration(); 
     552            taskTreeBuilder.setChild(mergeResult, mergedChild); 
    584553        } 
    585554         
     
    598567     * 
    599568     * @param subsequences the identified and already merged equal subsequences 
    600      * @param treeBuilder  the tree builder that can be used for connecting task tree nodes 
    601      * @param nodeFactory  the node factory that can be used for instantiating the iteration 
    602569     *  
    603570     * @return the resulting iteration 
    604571     */ 
    605572    private IIteration createIterationBasedOnIdentifiedVariants(SubSequences          subsequences, 
    606                                                                 ITaskTreeBuilder      treeBuilder, 
    607                                                                 ITaskTreeNodeFactory  nodeFactory, 
    608573                                                                RuleApplicationResult result) 
    609574    { 
    610         IIteration newIteration = nodeFactory.createNewIteration(); 
     575        IIteration newIteration = taskTreeNodeFactory.createNewIteration(); 
    611576        result.addNewlyCreatedParentNode(newIteration); 
    612577 
     
    616581                // there is only one equal variant and this has only one child. So create an 
    617582                // iteration of this child 
    618                 treeBuilder.setChild 
     583                taskTreeBuilder.setChild 
    619584                    (newIteration, subsequences.equalVariants.get(0).getChildren().get(0)); 
    620585            } 
    621586            else { 
    622587                // there was an iteration of one equal sequence 
    623                 treeBuilder.setChild(newIteration, subsequences.equalVariants.get(0)); 
     588                taskTreeBuilder.setChild(newIteration, subsequences.equalVariants.get(0)); 
    624589                result.addNewlyCreatedParentNode(subsequences.equalVariants.get(0)); 
    625590            } 
     
    628593            // there are distinct variants of equal subsequences or children --> create an 
    629594            // iterated selection 
    630             ISelection selection = nodeFactory.createNewSelection(); 
     595            ISelection selection = taskTreeNodeFactory.createNewSelection(); 
    631596            result.addNewlyCreatedParentNode(selection); 
    632597 
    633598            for (ITaskTreeNode variant : subsequences.equalVariants) { 
    634599                if (variant.getChildren().size() == 1) { 
    635                     treeBuilder.addChild(selection, variant.getChildren().get(0)); 
     600                    taskTreeBuilder.addChild(selection, variant.getChildren().get(0)); 
    636601                } 
    637602                else { 
    638                     treeBuilder.addChild(selection, variant); 
     603                    taskTreeBuilder.addChild(selection, variant); 
    639604                    result.addNewlyCreatedParentNode(variant); 
    640605                } 
    641606            } 
    642607 
    643             treeBuilder.setChild(newIteration, selection); 
     608            taskTreeBuilder.setChild(newIteration, selection); 
    644609        } 
    645610         
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRule.java

    r922 r1107  
    11package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    22 
    3 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    43import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    5 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
    64 
    75/** 
    86 * <p> 
    9  * a temporal relation ship is able to detected temporal relationships between the child nodes 
    10  * of the parent node provided to the 
    11  * {@link #apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} method. A rule 
    12  * created temporal relationships between the child nodes, i.e. substructures in the task tree, if 
     7 * a temporal relationship rule is able to detected temporal relationships between the child nodes 
     8 * of the parent node provided to the {@link #apply(ITaskTreeNode, boolean)} method. A rule 
     9 * creates temporal relationships between the child nodes, i.e. substructures in the task tree, if 
    1310 * it detects a temporal relationship and it can be sure that it is complete. Incomplete but 
    1411 * detected temporal relationships may occur, if there can be more children expected to be added 
     
    2320  /** 
    2421   * <p> 
    25    * applies the rule to the given parent node. The provided builder and node factory are used 
    26    * to create substructures in the task tree for the identified temporal relationships. The 
    27    * finalize parameter is used to command the rule to finish rule applications, in the case it 
    28    * is known that no further data will be available.  
     22   * applies the rule to the given parent node. The finalize parameter is used to command the rule 
     23   * to finish rule applications, in the case it is known that no further data will be available.  
    2924   * </p> 
    3025   * <p> 
     
    3833   * </p> 
    3934   *  
    40    * @param parent      the parent node with the children to apply the rule on 
    41    * @param builder     the builder to be used for creating substructures for the identified 
    42    *                    temporal relationships 
    43    * @param nodeFactory the node factory to be used for creating substructures for the identified 
    44    *                    temporal relationships 
    45    * @param finalize    true, if the rule shall not expect further children to come and that it 
    46    *                    should therefore be applied in any case 
     35   * @param parent   the parent node with the children to apply the rule on 
     36   * @param finalize true, if the rule shall not expect further children to come and that it 
     37   *                 should therefore be applied in any case 
    4738   *                     
    4839   * @return the rule application result as described. 
    4940   */ 
    50   RuleApplicationResult apply(ITaskTreeNode        parent, 
    51                               ITaskTreeBuilder     builder, 
    52                               ITaskTreeNodeFactory nodeFactory, 
    53                               boolean              finalize); 
     41  RuleApplicationResult apply(ITaskTreeNode parent, 
     42                              boolean       finalize); 
    5443   
    5544} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java

    r987 r1107  
    7979    /** 
    8080     * <p> 
    81      * the temporal relationship rule known to the manager. The rules are applied in the order 
    82      * they occur in this list. 
    83      * </p> 
    84      */ 
    85     private List<TemporalRelationshipRule> rules = new ArrayList<TemporalRelationshipRule>(); 
    86  
    87     /** 
    88      * <p> 
    89      * initialize the manager with a node equality rule manager to be used by the known rules 
    90      * for task tree node comparison. 
    91      * </p> 
    92      */ 
    93     public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) { 
     81     * the task tree node factory to be used during rule application 
     82     * </p> 
     83     */ 
     84    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     85 
     86    /** 
     87     * <p> 
     88     * the task tree builder to be used during rule application 
     89     * </p> 
     90     */ 
     91    private ITaskTreeBuilder taskTreeBuilder; 
     92 
     93    /** 
     94     * <p> 
     95     * the temporal relationship rules known to the manager that are executed on whole sub trees. 
     96     * The rules are applied in the order they occur in this list. 
     97     * </p> 
     98     */ 
     99    private TemporalRelationshipRule[] treeScopeRules; 
     100 
     101    /** 
     102     * <p> 
     103     * the temporal relationship rules known to the manager that are executed on whole sub trees. 
     104     * The rules are applied in the order they occur in this list. 
     105     * </p> 
     106     */ 
     107    private TemporalRelationshipRule[] nodeScopeRules; 
     108 
     109    /** 
     110     * <p> 
     111     * initialize the manager 
     112     * </p> 
     113     *  
     114     * @param nodeEqualityRuleManager the node equality rule manager to be used by the known rules 
     115     *                                for task tree node comparison during rule application 
     116     * @param taskTreeNodeFactory     the node factory to be used for instantiating new task tree 
     117     *                                nodes during rule application 
     118     * @param taskTreeBuilder         the task tree builder to be used for linking task tree nodes 
     119     *                                with each other during rule application 
     120     */ 
     121    public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager, 
     122                                           ITaskTreeNodeFactory    taskTreeNodeFactory, 
     123                                           ITaskTreeBuilder        taskTreeBuilder) 
     124    { 
    94125        super(); 
    95126        this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
     127        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     128        this.taskTreeBuilder = taskTreeBuilder; 
    96129    } 
    97130 
     
    107140        frameFilter.add(IFrame.class); 
    108141        frameFilter.add(IDialog.class); 
    109  
    110         rules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 
    111         rules.add(new DefaultGuiElementSequenceDetectionRule()); 
    112         rules.add(new DefaultEventTargetSequenceDetectionRule()); 
    113         rules.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager)); 
    114         //rules.add(new DefaultGuiEventSequenceDetectionRule()); 
     142        //frameFilter.add(ICanvas.class); 
     143 
     144        treeScopeRules = new TemporalRelationshipRule[] { 
     145            new DefaultTaskSequenceDetectionRule 
     146                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
     147                 taskTreeNodeFactory, taskTreeBuilder) 
     148        }; 
    115149         
    116         rules.add(new DefaultIterationDetectionRule 
    117                       (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL)); 
    118         rules.add(new DefaultIterationDetectionRule 
    119                       (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL)); 
    120         rules.add(new DefaultIterationDetectionRule 
    121                       (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL)); 
     150        //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 
     151 
     152        nodeScopeRules = new TemporalRelationshipRule[] { 
     153            //new DefaultGuiElementSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     154            //new DefaultEventTargetSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     155            new TrackBarSelectionDetectionRule 
     156                (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder), 
     157            //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     158            new DefaultIterationDetectionRule 
     159                (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
     160                 taskTreeNodeFactory, taskTreeBuilder), 
     161            new DefaultIterationDetectionRule 
     162                (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
     163                 taskTreeNodeFactory, taskTreeBuilder), 
     164            new DefaultIterationDetectionRule 
     165                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
     166                 taskTreeNodeFactory, taskTreeBuilder) 
     167        }; 
     168 
     169    } 
     170 
     171    /** 
     172     * <p> 
     173     * applies the known rules to the provided parent node. For the creation of further nodes, 
     174     * the provided builder and node factory are utilized. The method expectes, that no more data 
     175     * is available and, therefore, finalizes the rule application. 
     176     * </p> 
     177     *  
     178     * @param nodeFactory  the node factory to be used for instantiating new task tree nodes. 
     179     */ 
     180    public void applyRules(ITaskTreeNode parent) { 
     181        applyRules(parent, true); 
    122182    } 
    123183 
     
    132192     *  
    133193     * @param parent       the parent node to apply the rules on 
    134      * @param builder      the task tree builder to be used for linking task tree nodes with each 
    135      *                     other 
    136      * @param nodeFactory  the node factory to be used for instantiating new task tree nodes. 
    137194     * @param finalize     used to indicate, if the rule application shall break up if a rule would 
    138195     *                     be feasible if further data was available, or not. 
    139196     */ 
    140     public void applyRules(ITaskTreeNode        parent, 
    141                            ITaskTreeBuilder     builder, 
    142                            ITaskTreeNodeFactory nodeFactory, 
    143                            boolean              finalize) 
    144     { 
    145         applyRules(parent, builder, nodeFactory, finalize, ""); 
     197    public void applyRules(ITaskTreeNode parent, boolean finalize) { 
     198        applyRules(treeScopeRules, parent, finalize, ""); 
    146199    } 
    147200 
     
    157210     *  
    158211     * @param parent       the parent node to apply the rules on 
    159      * @param builder      the task tree builder to be used for linking task tree nodes with each 
    160      *                     other 
    161      * @param nodeFactory  the node factory to be used for instantiating new task tree nodes. 
    162212     * @param finalize     used to indicate, if the rule application shall break up if a rule would 
    163213     *                     be feasible if further data was available, or not. 
     
    165215     *                     on the recursion depth of calling this method. 
    166216     */ 
    167     private int applyRules(ITaskTreeNode        parent, 
    168                            ITaskTreeBuilder     builder, 
    169                            ITaskTreeNodeFactory nodeFactory, 
    170                            boolean              finalize, 
    171                            String               logIndent) 
     217    private int applyRules(TemporalRelationshipRule[] rules, 
     218                           ITaskTreeNode              parent, 
     219                           boolean                    finalize, 
     220                           String                     logIndent) 
    172221    { 
    173222        Console.traceln(Level.FINER, logIndent + "applying rules for " + parent); 
     
    179228            do { 
    180229                Console.traceln(Level.FINER, logIndent + "trying rule " + rule + " on " + parent); 
    181                 result = rule.apply(parent, builder, nodeFactory, finalize); 
     230                result = rule.apply(parent, finalize); 
    182231 
    183232                if ((result != null) && 
     
    193242                    for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 
    194243                        noOfRuleApplications += 
    195                             applyRules(newParent, builder, nodeFactory, true, logIndent + "  "); 
     244                            applyRules(nodeScopeRules, newParent, true, logIndent + "  "); 
    196245                    } 
    197246                } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java

    r1099 r1107  
    1919 * @author 2012, last modified by $Author: patrick$ 
    2020 */ 
    21 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule { 
     21class TrackBarSelectionDetectionRule implements TemporalRelationshipRule { 
     22    /** 
     23     * <p> 
     24     * the task tree node factory to be used for creating substructures for the temporal 
     25     * relationships identified during rule 
     26     * </p> 
     27     */ 
     28    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     29    /** 
     30     * <p> 
     31     * the task tree builder to be used for creating substructures for the temporal relationships 
     32     * identified during rule application 
     33     * </p> 
     34     */ 
     35    private ITaskTreeBuilder taskTreeBuilder; 
    2236 
    23     /** */ 
     37    /** 
     38     * <p> 
     39     * the node equality manager needed for comparing task tree nodes with each other 
     40     * </p> 
     41     */ 
    2442    private NodeEqualityRuleManager nodeEqualityRuleManager; 
    2543 
    2644    /** 
    27      * 
     45     * <p> 
     46     * instantiates the rule and initializes it with a node equality rule manager and the minimal 
     47     * node equality identified sublist must have to consider them as iterated. 
     48     * </p> 
    2849     */ 
    29     TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 
    30         super(); 
     50    TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager, 
     51                                   ITaskTreeNodeFactory    taskTreeNodeFactory, 
     52                                   ITaskTreeBuilder        taskTreeBuilder) 
     53    { 
    3154        this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
     55        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     56        this.taskTreeBuilder = taskTreeBuilder; 
    3257    } 
    3358 
     
    3560     * (non-Javadoc) 
    3661     *  
    37      * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 
     62     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
     63     * boolean) 
    3864     */ 
    3965    @Override 
    40     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    41                                        ITaskTreeBuilder     builder, 
    42                                        ITaskTreeNodeFactory nodeFactory, 
    43                                        boolean              finalize) 
    44     { 
     66    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    4567        if (!(parent instanceof ISequence)) { 
    4668            return null; 
     
    7294                // Therefore, 
    7395                // create an iteration with the different selectable values as selection children 
    74                 handleValueSelections(parent, currentTrackBar, valueSelectionStartIndex, index - 1, 
    75                                       builder, nodeFactory, result); 
     96                handleValueSelections 
     97                    (parent, currentTrackBar, valueSelectionStartIndex, index - 1, result); 
    7698 
    7799                return result; 
     
    84106            if (finalize) { 
    85107                handleValueSelections(parent, currentTrackBar, valueSelectionStartIndex, 
    86                                       parent.getChildren().size() - 1, builder, nodeFactory, result); 
     108                                      parent.getChildren().size() - 1, result); 
    87109            } 
    88110            else { 
     
    101123                                       int                   startIndex, 
    102124                                       int                   endIndex, 
    103                                        ITaskTreeBuilder      builder, 
    104                                        ITaskTreeNodeFactory  nodeFactory, 
    105125                                       RuleApplicationResult result) 
    106126    { 
    107         IIteration iteration = nodeFactory.createNewIteration(); 
    108         builder.setDescription(iteration, "value selection on " + trackbar.getStringIdentifier()); 
     127        IIteration iteration = taskTreeNodeFactory.createNewIteration(); 
     128        taskTreeBuilder.setDescription 
     129            (iteration, "value selection on " + trackbar.getStringIdentifier()); 
    109130        result.addNewlyCreatedParentNode(iteration); 
    110131 
    111         ISelection selection = nodeFactory.createNewSelection(); 
     132        ISelection selection = taskTreeNodeFactory.createNewSelection(); 
    112133        result.addNewlyCreatedParentNode(selection); 
    113         builder.setChild(iteration, selection); 
     134        taskTreeBuilder.setChild(iteration, selection); 
    114135 
    115136        for (int i = endIndex - startIndex; i >= 0; i--) { 
    116             addChildIfNecessary(selection, parent.getChildren().get(startIndex), builder, 
    117                                 nodeFactory, result); 
    118             builder.removeChild((ISequence) parent, startIndex); 
     137            addChildIfNecessary(selection, parent.getChildren().get(startIndex), result); 
     138            taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    119139        } 
    120140 
    121         builder.addChild((ISequence) parent, startIndex, iteration); 
     141        taskTreeBuilder.addChild((ISequence) parent, startIndex, iteration); 
    122142 
    123143        result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 
     
    129149    private void addChildIfNecessary(ISelection            parentSelection, 
    130150                                     ITaskTreeNode         node, 
    131                                      ITaskTreeBuilder      builder, 
    132                                      ITaskTreeNodeFactory  nodeFactory, 
    133151                                     RuleApplicationResult result) 
    134152    { 
     
    144162 
    145163        // if we did not return in the previous checks, then the node must be added 
    146         builder.addChild(parentSelection, node); 
     164        taskTreeBuilder.addChild(parentSelection, node); 
    147165    } 
    148166 
Note: See TracChangeset for help on using the changeset viewer.