Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
File:
1 edited

Legend:

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

    r1131 r1146  
    2222import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame; 
    2323import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
    24 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    25 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
     24import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
     25import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager; 
     26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     30import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    2931import de.ugoe.cs.util.console.Console; 
    3032 
    3133/** 
     34 * TODO update comment 
     35 *  
    3236 * <p> 
    3337 * This class is responsible for applying temporal relationship rules on a task tree. Through this, 
    3438 * a flat task tree is restructured to have more depth but to include more temporal relationships 
    35  * between task tree nodes which are not only a major sequence. I.e. through the application of 
    36  * rule iterations and selections of task tree nodes are detected. Which kind of temporal relations 
    37  * between task tree nodes are detected depends on the {@link TemporalRelationshipRule}s known to 
     39 * between tasks which are not only a major sequence. I.e. through the application of the 
     40 * rules iterations and selections of tasks are detected. Which kind of temporal relations 
     41 * between tasks are detected depends on the {@link ITaskInstanceListScopeRule}s known to 
    3842 * this class. 
    3943 * </p> 
    40  * <p>The class holds references to the appropriate {@link TemporalRelationshipRule}s and calls 
    41  * their {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} 
    42  * method for each node in the task tree it is needed for. The general behavior of this class is 
     44 * <p>The class holds references to the appropriate {@link ITaskInstanceListScopeRule}s and calls 
     45 * their {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
     46 * method for each task in the task tree it is needed for. The general behavior of this class is 
    4347 * the following: 
    4448 * <ol> 
     
    4852 *   </li> 
    4953 *   <li> 
    50  *     then the {@link #applyRules(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} 
    51  *     method is called for a so far unstructured task tree node 
     54 *     then the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 
     55 *     method is called for a so far unstructured task 
    5256 *   </li> 
    5357 *   <li> 
    5458 *     the class iterates its internal list of rules and calls their 
    55  *     {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} 
     59 *     {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
    5660 *     method. 
    5761 *   </li> 
     
    6973 *       <li> 
    7074 *         if a rule returns, that it was applied, the same rule is applied again until it returns 
    71  *         null or feasible. For each newly created parent node provided in the rule application 
    72  *         result, the {@link #applyRules(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} 
     75 *         null or feasible. For each newly created parent task provided in the rule application 
     76 *         result, the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 
    7377 *         method is called. 
    7478 *       </li> 
     
    7680 *   </li> 
    7781 * </ol> 
    78  * Through this, all rules are tried to be applied at least once to the provided parent node and 
    79  * all parent nodes created during the rule application. 
     82 * Through this, all rules are tried to be applied at least once to the provided parent task and 
     83 * all parent tasks created during the rule application. 
    8084 * </p> 
    8185 *  
     
    8690    /** 
    8791     * <p> 
    88      * the node equality manager needed by the rules to compare task tree nodes with each other 
    89      * </p> 
    90      */ 
    91     private NodeEqualityRuleManager nodeEqualityRuleManager; 
    92  
    93     /** 
    94      * <p> 
    95      * the task tree node factory to be used during rule application 
    96      * </p> 
    97      */ 
    98     private ITaskTreeNodeFactory taskTreeNodeFactory; 
    99  
    100     /** 
    101      * <p> 
    102      * the task tree builder to be used during rule application 
    103      * </p> 
    104      */ 
    105     private ITaskTreeBuilder taskTreeBuilder; 
     92     * the task equality manager needed by the rules to compare tasks with each other 
     93     * </p> 
     94     */ 
     95    private TaskEqualityRuleManager taskEqualityRuleManager; 
     96 
     97    /** 
     98     * <p> 
     99     * the task factory to be used during rule application 
     100     * </p> 
     101     */ 
     102    private ITaskFactory taskFactory; 
     103 
     104    /** 
     105     * <p> 
     106     * the task builder to be used during rule application 
     107     * </p> 
     108     */ 
     109    private ITaskBuilder taskBuilder; 
     110 
     111    /** 
     112     * <p> 
     113     * the temporal relationship rules known to the manager that are executed on whole sessions. 
     114     * The rules are applied in the order they occur in this list. 
     115     * </p> 
     116     */ 
     117    private ISessionScopeRule[] sessionScopeRules; 
    106118 
    107119    /** 
     
    111123     * </p> 
    112124     */ 
    113     private TemporalRelationshipRule[] treeScopeRules; 
    114  
    115     /** 
    116      * <p> 
    117      * the temporal relationship rules known to the manager that are executed on whole sub trees. 
    118      * The rules are applied in the order they occur in this list. 
    119      * </p> 
    120      */ 
    121     private TemporalRelationshipRule[] nodeScopeRules; 
     125    private ITaskInstanceListScopeRule[] taskScopeRules; 
    122126 
    123127    /** 
     
    126130     * </p> 
    127131     *  
    128      * @param nodeEqualityRuleManager the node equality rule manager to be used by the known rules 
    129      *                                for task tree node comparison during rule application 
    130      * @param taskTreeNodeFactory     the node factory to be used for instantiating new task tree 
    131      *                                nodes during rule application 
    132      * @param taskTreeBuilder         the task tree builder to be used for linking task tree nodes 
     132     * @param taskEqualityRuleManager the task equality rule manager to be used by the known rules 
     133     *                                for task comparison during rule application 
     134     * @param taskFactory             the task factory to be used for instantiating new task tree 
     135     *                                tasks during rule application 
     136     * @param taskBuilder             the task builder to be used for linking tasks 
    133137     *                                with each other during rule application 
    134138     */ 
    135     public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager, 
    136                                            ITaskTreeNodeFactory    taskTreeNodeFactory, 
    137                                            ITaskTreeBuilder        taskTreeBuilder) 
     139    public TemporalRelationshipRuleManager(TaskEqualityRuleManager taskEqualityRuleManager, 
     140                                           ITaskFactory            taskFactory, 
     141                                           ITaskBuilder            taskBuilder) 
    138142    { 
    139143        super(); 
    140         this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
    141         this.taskTreeNodeFactory = taskTreeNodeFactory; 
    142         this.taskTreeBuilder = taskTreeBuilder; 
     144        this.taskEqualityRuleManager = taskEqualityRuleManager; 
     145        this.taskFactory = taskFactory; 
     146        this.taskBuilder = taskBuilder; 
    143147    } 
    144148 
     
    146150     * <p> 
    147151     * initialized the temporal relationship rule manager by instantiating the known rules and 
    148      * providing them with a reference to the node equality manager or other information they need. 
     152     * providing them with a reference to the task equality manager or other information they need. 
    149153     * </p> 
    150154     */ 
     
    156160        //frameFilter.add(ICanvas.class); 
    157161 
    158         treeScopeRules = new TemporalRelationshipRule[] { 
     162        sessionScopeRules = new ISessionScopeRule[] { 
    159163            new SequenceForTaskDetectionRule 
    160                 (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
    161                  taskTreeNodeFactory, taskTreeBuilder), 
     164                (taskEqualityRuleManager, TaskEquality.SEMANTICALLY_EQUAL, 
     165                 taskFactory, taskBuilder), 
    162166            /*new DefaultTaskSequenceDetectionRule 
    163                 (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
    164                  taskTreeNodeFactory, taskTreeBuilder), 
     167                (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
     168                 taskFactory, taskTreeBuilder), 
    165169            new DefaultTaskSequenceDetectionRule 
    166                 (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
    167                  taskTreeNodeFactory, taskTreeBuilder),*/ 
     170                (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
     171                 taskFactory, taskTreeBuilder),*/ 
    168172            /*new TreeScopeWrapperRule 
    169173                (new DefaultIterationDetectionRule 
    170                     (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
    171                      taskTreeNodeFactory, taskTreeBuilder)), 
     174                    (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 
     175                     taskFactory, taskTreeBuilder)), 
    172176            new TreeScopeWrapperRule 
    173177                (new DefaultIterationDetectionRule 
    174                     (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
    175                      taskTreeNodeFactory, taskTreeBuilder)), 
     178                    (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 
     179                     taskFactory, taskTreeBuilder)), 
    176180            new TreeScopeWrapperRule 
    177181                (new DefaultIterationDetectionRule 
    178                     (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
    179                      taskTreeNodeFactory, taskTreeBuilder))*/ 
     182                    (taskEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 
     183                     taskFactory, taskTreeBuilder))*/ 
    180184        }; 
    181185         
    182186        //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 
    183187 
    184         nodeScopeRules = new TemporalRelationshipRule[] { 
    185             //new SequenceOnGuiElementDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
    186             //new EventSequenceOnSameTargetDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
    187             new TrackBarSelectionDetectionRule 
    188                 (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder), 
    189             //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 
     188        taskScopeRules = new ITaskInstanceListScopeRule[] { 
     189            //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 
     190            //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder), 
     191            //new TrackBarSelectionDetectionRule(taskEqualityRuleManager, taskFactory, taskBuilder), 
     192            //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder), 
    190193        }; 
    191194 
     
    194197    /** 
    195198     * <p> 
    196      * applies the known rules to the provided parent node. For the creation of further nodes, 
    197      * the provided builder and node factory are utilized. The method expectes, that no more data 
     199     * applies the known rules to the provided sessions. For the creation of further tasks, 
     200     * the provided builder and task factory are utilized. The method expects, that no more data 
    198201     * is available and, therefore, finalizes the rule application. 
    199202     * </p> 
    200203     *  
    201      * @param nodeFactory  the node factory to be used for instantiating new task tree nodes. 
    202      */ 
    203     public void applyRules(ITaskTreeNode parent) { 
    204         applyRules(parent, true); 
    205     } 
    206  
    207     /** 
    208      * <p> 
    209      * applies the known rules to the provided parent node. For the creation of further nodes, 
    210      * the provided builder and node factory are utilized. If the finalize parameter is true, the 
     204     * @param taskFactory  the task factory to be used for instantiating new tasks. 
     205     */ 
     206    public void applyRules(List<IUserSession> sessions) { 
     207        applyRules(sessionScopeRules, sessions, ""); 
     208    } 
     209 
     210    /** 
     211     * <p> 
     212     * applies the known rules to the provided parent task. For the creation of further tasks, 
     213     * the provided builder and task factory are utilized. If the finalize parameter is true, the 
    211214     * rule application is finalized as far as possible without waiting for further data. If it is 
    212215     * false, the rule application is broken up at the first rule returning, that its application 
    213      * would be feasible.  
     216     * would be feasible. The method calls itself for each parent task created through the rule 
     217     * application. In this case, the finalize parameter is always true. 
    214218     * </p> 
    215219     *  
    216      * @param parent       the parent node to apply the rules on 
    217      * @param finalize     used to indicate, if the rule application shall break up if a rule would 
    218      *                     be feasible if further data was available, or not. 
    219      */ 
    220     public void applyRules(ITaskTreeNode parent, boolean finalize) { 
    221         applyRules(treeScopeRules, parent, finalize, ""); 
    222     } 
    223  
    224     /** 
    225      * <p> 
    226      * applies the known rules to the provided parent node. For the creation of further nodes, 
    227      * the provided builder and node factory are utilized. If the finalize parameter is true, the 
    228      * rule application is finalized as far as possible without waiting for further data. If it is 
    229      * false, the rule application is broken up at the first rule returning, that its application 
    230      * would be feasible. The method calls itself for each parent node created through the rule 
    231      * application. In this case, the finalize parameter is always true. 
    232      * </p> 
    233      *  
    234      * @param parent       the parent node to apply the rules on 
     220     * @param parent       the parent task to apply the rules on 
    235221     * @param finalize     used to indicate, if the rule application shall break up if a rule would 
    236222     *                     be feasible if further data was available, or not. 
     
    238224     *                     on the recursion depth of calling this method. 
    239225     */ 
    240     private int applyRules(TemporalRelationshipRule[] rules, 
    241                            ITaskTreeNode              parent, 
    242                            boolean                    finalize, 
    243                            String                     logIndent) 
     226    private int applyRules(ISessionScopeRule[] rules, 
     227                           List<IUserSession>  sessions, 
     228                           String              logIndent) 
    244229    { 
    245         Console.traceln(Level.FINER, logIndent + "applying rules for " + parent); 
     230        Console.traceln 
     231            (Level.FINER, logIndent + "applying rules for " + sessions.size() + " sessions"); 
    246232 
    247233        int noOfRuleApplications = 0; 
    248234 
    249         for (TemporalRelationshipRule rule : rules) { 
     235        for (ISessionScopeRule rule : rules) { 
    250236            RuleApplicationResult result; 
    251237            do { 
    252                 Console.traceln(Level.FINER, logIndent + "trying rule " + rule + " on " + parent); 
    253                 result = rule.apply(parent, finalize); 
     238                Console.traceln(Level.FINER, logIndent + "trying rule " + rule); 
     239                result = rule.apply(sessions); 
    254240 
    255241                if ((result != null) && 
    256242                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 
    257243                { 
    258                     Console.traceln 
    259                         (Level.FINE, logIndent + "applied rule " + rule + " on " + parent); 
     244                    Console.traceln(Level.FINE, logIndent + "applied rule " + rule); 
    260245                    noOfRuleApplications++; 
    261246                     
    262247                    //dumpTask(parent, ""); 
    263248 
    264                     for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 
     249                    for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 
    265250                        noOfRuleApplications += 
    266                             applyRules(nodeScopeRules, newParent, true, logIndent + "  "); 
     251                            applyRules(taskScopeRules, newParent, logIndent + "  "); 
    267252                    } 
    268253                } 
     
    271256                   (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 
    272257 
    273             if ((!finalize) && 
    274                 (result != null) && 
    275                 (result.getRuleApplicationStatus() == RuleApplicationStatus.FEASIBLE)) 
    276             { 
    277                 // in this case, don't go on applying rules, which should not be applied yet 
    278                 break; 
    279             } 
    280258        } 
    281259 
     
    289267 
    290268    /** 
     269     * <p> 
     270     * applies the known rules to the provided parent task. For the creation of further tasks, 
     271     * the provided builder and task factory are utilized. If the finalize parameter is true, the 
     272     * rule application is finalized as far as possible without waiting for further data. If it is 
     273     * false, the rule application is broken up at the first rule returning, that its application 
     274     * would be feasible. The method calls itself for each parent task created through the rule 
     275     * application. In this case, the finalize parameter is always true. 
     276     * </p> 
     277     *  
     278     * @param parent       the parent task to apply the rules on 
     279     * @param finalize     used to indicate, if the rule application shall break up if a rule would 
     280     *                     be feasible if further data was available, or not. 
     281     * @param logIndent    simply used for logging purposes to indent the log messages depending 
     282     *                     on the recursion depth of calling this method. 
     283     */ 
     284    private int applyRules(ITaskInstanceListScopeRule[] rules, 
     285                           ITaskInstanceList            taskInstances, 
     286                           String                       logIndent) 
     287    { 
     288        Console.traceln(Level.FINER, logIndent + "applying rules for " + taskInstances.size() + 
     289                        " task instances"); 
     290 
     291        int noOfRuleApplications = 0; 
     292 
     293        for (ITaskInstanceListScopeRule rule : rules) { 
     294            RuleApplicationResult result; 
     295            do { 
     296                Console.traceln 
     297                    (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstances); 
     298                result = rule.apply(taskInstances); 
     299 
     300                if ((result != null) && 
     301                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 
     302                { 
     303                    Console.traceln 
     304                        (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstances); 
     305                    noOfRuleApplications++; 
     306                     
     307                    //dumpTask(parent, ""); 
     308 
     309                    for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 
     310                        noOfRuleApplications += 
     311                            applyRules(taskScopeRules, newParent, logIndent + "  "); 
     312                    } 
     313                } 
     314            } 
     315            while ((result != null) && 
     316                   (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 
     317        } 
     318 
     319        if (noOfRuleApplications <= 0) { 
     320            Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 
     321                            "relationship generated"); 
     322        } 
     323 
     324        return noOfRuleApplications; 
     325    } 
     326 
     327    /** 
    291328     * 
    292329     */ 
    293     /*private void dumpTask(ITaskTreeNode task, String indent) { 
     330    /*private void dumpTask(ITask task, String indent) { 
    294331        StringBuffer message = new StringBuffer(); 
    295332        message.append(indent); 
     
    304341         
    305342        if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 
    306             for (ITaskTreeNode child : task.getChildren()) { 
     343            for (ITask child : task.getChildren()) { 
    307344                dumpTask(child, indent + "  "); 
    308345            } 
Note: See TracChangeset for help on using the changeset viewer.