Changeset 2132


Ignore:
Timestamp:
08/24/16 10:17:41 (8 years ago)
Author:
pharms
Message:
  • added possibility to select the minimal amount of action instances a detected sequence must cover
Location:
trunk
Files:
5 edited

Legend:

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

    r1889 r2132  
    1616 
    1717import java.util.Collection; 
     18import java.util.HashMap; 
    1819import java.util.LinkedList; 
    1920import java.util.List; 
     21import java.util.Map; 
    2022import java.util.logging.Level; 
    2123 
    2224import de.ugoe.cs.autoquest.eventcore.Event; 
     25import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
    2326import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2427import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
     
    7275    /** 
    7376     * <p> 
     77     * The default task equality considered when comparing task instances initially 
     78     * </p> 
     79     */ 
     80    private TaskEquality minimalTaskEquality = TaskEquality.SEMANTICALLY_EQUAL; 
     81 
     82    /** 
     83     * <p> 
     84     * If this flag is set, then the task tree manager will not create new event tasks for any 
     85     * events. Instead, it will check using the hashcode and equal methods of the provided events 
     86     * if a certain event has already occurred, and if so, the corresponding event task will be 
     87     * reused. 
     88     * </p> 
     89     */ 
     90    private boolean useEventEqualityForTaskComparison; 
     91     
     92    /** 
     93     * <p> 
     94     * the minimum number of event task instances a sequence must cover to still detect it as a 
     95     * representative task 
     96     * </p> 
     97     */ 
     98    private int minimumSequenceCoverage;; 
     99 
     100    /** 
     101     * <p> 
     102     * If the flag {@link #useEventEqualityForTaskComparison} is set, then here the task tree 
     103     * manager stores the already created event tasks. 
     104     * </p> 
     105     */ 
     106    private Map<Event, IEventTask> eventTasks = new HashMap<>(); 
     107 
     108    /** 
     109     * <p> 
    74110     * initializes the task tree manager 
    75111     * </p> 
    76112     */ 
    77113    public TaskTreeManager() { 
    78         sessions = new LinkedList<IUserSession>(); 
     114        this.sessions = new LinkedList<IUserSession>(); 
    79115    } 
    80116 
     
    96132     *                               single events 
    97133     */ 
    98     public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 
     134    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions, 
     135                                                   boolean useEventEqualityForTaskComparison, 
     136                                                   int     minimumSequenceCoverage) 
     137    { 
    99138        if ((currentSession != null) || (sessions.size() > 0)) { 
    100139            throw new IllegalStateException("do not mix calls to this method with calls to the " + 
     
    102141                                            "variant instead."); 
    103142        } 
     143         
     144        this.useEventEqualityForTaskComparison = useEventEqualityForTaskComparison; 
     145         
     146        if (useEventEqualityForTaskComparison) { 
     147            // if we do this, we also need to consider identity of event tasks afterwards 
     148            minimalTaskEquality = TaskEquality.IDENTICAL; 
     149        } 
     150         
     151        this.minimumSequenceCoverage = minimumSequenceCoverage; 
    104152         
    105153        for (List<Event> newSession : newSessions) { 
     
    117165    /** 
    118166     * <p> 
     167     * call {@link #createTaskModel(Collection, boolean, int)} with false for use event equality 
     168     * for comparison and 0 for the minimum number of covered events per sequence 
     169     * </p> 
     170     *  
     171     * @param newSessions the user sessions of which the task model shall be created 
     172     *  
     173     * @return the task model created from the user sessions 
     174     *  
     175     * @throws IllegalStateException if the task manager is already used by providing it with 
     176     *                               single events 
     177     */ 
     178    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 
     179        return createTaskModel(newSessions, false, 0); 
     180    } 
     181 
     182    /** 
     183     * <p> 
    119184     * handles a single event that occurred in a user session. 
    120185     * </p> 
     
    124189    public void handleNewEvent(Event event) { 
    125190        assertSessionSequence(); 
    126         String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 
    127         IEventTask eventTask = taskFactory.createNewEventTask(description); 
    128         taskBuilder.addExecutedTask 
    129             (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 
     191         
     192        if (!useEventEqualityForTaskComparison) { 
     193            String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 
     194            IEventTask eventTask = taskFactory.createNewEventTask(description); 
     195            taskBuilder.addExecutedTask 
     196                (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 
     197        } 
     198        else { 
     199            IEventTask eventTask = eventTasks.get(event); 
     200            if (eventTask == null) { 
     201                String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 
     202                eventTask = taskFactory.createNewEventTask(description); 
     203                eventTasks.put(event, eventTask); 
     204            } 
     205             
     206            taskBuilder.addExecutedTask 
     207                (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 
     208        } 
    130209    } 
    131210 
     
    157236            (Level.INFO, "applying temporal relationship generation rules for detecting tasks"); 
    158237         
    159         ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule(sessions); 
     238        ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule 
     239            (sessions, minimalTaskEquality, minimumSequenceCoverage); 
    160240 
    161241        return taskFactory.createTaskModel(sessions); 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/CondenseSimilarTasksRule.java

    r1982 r2132  
    444444         
    445445        new SequenceForTaskDetectionRule 
    446             (TaskEquality.IDENTICAL, taskFactory, taskBuilder).apply(flattenedSessionList); 
     446            (TaskEquality.IDENTICAL, taskFactory, taskBuilder, 0).apply(flattenedSessionList); 
    447447         
    448448        Map<ITaskInstance, ITaskInstance> replacements = new HashMap<ITaskInstance, ITaskInstance>(); 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java

    r1889 r2132  
    2525import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
    2626import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
    27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2827import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    2928import de.ugoe.cs.util.console.Console; 
     
    102101    /** 
    103102     * <p> 
    104      * the temporal relationship rules known to the manager that are executed on whole sessions. 
    105      * The rules are applied in the order they occur in this list. 
    106      * </p> 
    107      */ 
    108     private ISessionScopeRule[] sessionScopeRules; 
    109  
    110     /** 
    111      * <p> 
    112      * the temporal relationship rules known to the manager that are executed on whole sub trees. 
    113      * The rules are applied in the order they occur in this list. 
    114      * </p> 
    115      */ 
    116     private ITaskInstanceScopeRule[] taskScopeRules; 
    117  
    118     /** 
    119      * <p> 
    120103     * initialize the manager 
    121104     * </p> 
     
    144127        frameFilter.add(IDialog.class); 
    145128        //frameFilter.add(ICanvas.class); 
    146  
    147         sessionScopeRules = new ISessionScopeRule[] { 
    148             new SequenceForTaskDetectionRule 
    149                 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder), 
    150             new CondenseSimilarTasksRule 
    151                 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder), 
    152             /*new DefaultTaskSequenceDetectionRule 
    153                 (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder), 
    154             new DefaultTaskSequenceDetectionRule 
    155                 (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder),*/ 
    156             /*new TreeScopeWrapperRule 
    157                 (new DefaultIterationDetectionRule 
    158                     (NodeEquality.LEXICALLY_EQUAL, taskFactory, taskTreeBuilder)), 
    159             new TreeScopeWrapperRule 
    160                 (new DefaultIterationDetectionRule 
    161                     (NodeEquality.SYNTACTICALLY_EQUAL, taskFactory, taskTreeBuilder)), 
    162             new TreeScopeWrapperRule 
    163                 (new DefaultIterationDetectionRule 
    164                     (NodeEquality.SEMANTICALLY_EQUAL, taskFactory, taskTreeBuilder))*/ 
    165         }; 
    166          
    167         //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 
    168  
    169         taskScopeRules = new ITaskInstanceScopeRule[] { 
    170             //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 
    171             //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder), 
    172             //new TrackBarSelectionDetectionRule(taskFactory, taskBuilder), 
    173             //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder), 
    174         }; 
    175  
    176     } 
    177  
    178     /** 
    179      * <p> 
    180      * applies the known rules to the provided sessions. For the creation of further tasks, 
    181      * the provided builder and task factory are utilized. The method expects, that no more data 
    182      * is available and, therefore, finalizes the rule application. 
    183      * </p> 
    184      *  
    185      * @param sessions  the sessions to be processed 
    186      */ 
    187     public void applyRules(List<IUserSession> sessions) { 
    188         applyRules(sessionScopeRules, sessions, ""); 
    189129    } 
    190130 
     
    197137     * @param sessions  the sessions to be processed 
    198138     */ 
    199     public void applyTaskDetectionRule(List<IUserSession> sessions) { 
     139    public void applyTaskDetectionRule(List<IUserSession> sessions, 
     140                                       TaskEquality       minimalTaskEquality, 
     141                                       int                minimumSequenceCoverage) 
     142    { 
    200143        ISessionScopeRule[] rules = new ISessionScopeRule[] { 
    201             new SequenceForTaskDetectionRule 
    202                 (TaskEquality.SEMANTICALLY_EQUAL, taskFactory, taskBuilder) 
     144            new SequenceForTaskDetectionRule(minimalTaskEquality, taskFactory, taskBuilder, 
     145                                             minimumSequenceCoverage) 
    203146        }; 
    204147         
     
    261204                     
    262205                    //dumpTask(parent, ""); 
    263  
    264                     for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 
    265                         noOfRuleApplications += 
    266                             applyRules(taskScopeRules, newParent, logIndent + "  "); 
    267                     } 
    268206                } 
    269207            } 
     
    271209                   (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 
    272210 
    273         } 
    274  
    275         if (noOfRuleApplications <= 0) { 
    276             Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 
    277                             "relationship generated"); 
    278         } 
    279  
    280         return noOfRuleApplications; 
    281     } 
    282  
    283     /** 
    284      * <p> 
    285      * applies the known rules to the provided parent task. For the creation of further tasks, 
    286      * the provided builder and task factory are utilized. If the finalize parameter is true, the 
    287      * rule application is finalized as far as possible without waiting for further data. If it is 
    288      * false, the rule application is broken up at the first rule returning, that its application 
    289      * would be feasible. The method calls itself for each parent task created through the rule 
    290      * application. In this case, the finalize parameter is always true. 
    291      * </p> 
    292      *  
    293      * @param parent       the parent task to apply the rules on 
    294      * @param finalize     used to indicate, if the rule application shall break up if a rule would 
    295      *                     be feasible if further data was available, or not. 
    296      * @param logIndent    simply used for logging purposes to indent the log messages depending 
    297      *                     on the recursion depth of calling this method. 
    298      */ 
    299     private int applyRules(ITaskInstanceScopeRule[] rules, 
    300                            ITaskInstance                taskInstance, 
    301                            String                       logIndent) 
    302     { 
    303         Console.traceln(Level.FINER, logIndent + "applying rules on " + taskInstance); 
    304  
    305         int noOfRuleApplications = 0; 
    306  
    307         for (ITaskInstanceScopeRule rule : rules) { 
    308             RuleApplicationResult result; 
    309             do { 
    310                 Console.traceln 
    311                     (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstance); 
    312                 result = rule.apply(taskInstance); 
    313  
    314                 if ((result != null) && 
    315                     (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 
    316                 { 
    317                     Console.traceln 
    318                         (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstance); 
    319                     noOfRuleApplications++; 
    320                      
    321                     //dumpTask(parent, ""); 
    322  
    323                     for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 
    324                         noOfRuleApplications += 
    325                             applyRules(taskScopeRules, newParent, logIndent + "  "); 
    326                     } 
    327                 } 
    328             } 
    329             while ((result != null) && 
    330                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 
    331211        } 
    332212 
  • trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDgenerateTaskTree.java

    r1844 r2132  
    4545    @Override 
    4646    public String help() { 
    47         return "generateTaskTree <sequences> {<tasktree>}"; 
     47        return "generateTaskTree <sequences> {<tasktree>} {-considerEventEquality} " + 
     48            "{-minimumSequenceCoverage=<some integer>}"; 
    4849    } 
    4950 
     
    5657    @Override 
    5758    public void run(List<Object> parameters) { 
    58         String sequencesName; 
    59         String tasktreeName; 
     59        String sequencesName = null; 
     60        String tasktreeName = null; 
     61        boolean useEventEqualityForTaskComparison = false; 
     62        int minimumSequenceCoverage = 0; 
     63         
    6064        try { 
    61             sequencesName = (String) parameters.get(0); 
    62             if (parameters.size() > 1) { 
    63                 tasktreeName = (String) parameters.get(1); 
    64             } 
    65             else { 
    66                 tasktreeName = "tasktree"; 
     65            for (int i = 0; i < parameters.size(); i++) { 
     66                String parameter = (String) parameters.get(i); 
     67                if (!parameter.startsWith("-")) { 
     68                    if (sequencesName == null) { 
     69                        sequencesName = parameter; 
     70                    } 
     71                    else if (tasktreeName == null) { 
     72                        tasktreeName = parameter; 
     73                    } 
     74                    else { 
     75                        throw new IllegalArgumentException("unrecognized parameter: " + parameter); 
     76                    } 
     77                } 
     78                else { 
     79                    if ("-considerEventEquality".equals(parameter)) { 
     80                        useEventEqualityForTaskComparison = true; 
     81                    } 
     82                    else if (parameter.startsWith("-minimumSequenceCoverage=")) { 
     83                        try { 
     84                            minimumSequenceCoverage = Integer.parseInt 
     85                                (parameter.substring("-minimumSequenceCoverage=".length())); 
     86                        } 
     87                        catch (Exception e) { 
     88                            throw new IllegalArgumentException 
     89                                ("invalid value for parameter minimumSequenceCoverage: " + 
     90                                 parameter.substring("-minimumSequenceCoverage=".length())); 
     91                        } 
     92                    } 
     93                    else { 
     94                        throw new IllegalArgumentException("unrecognized parameter: " + parameter); 
     95                    } 
     96                } 
    6797            } 
    6898        } 
     99        catch (IllegalArgumentException e) { 
     100            throw e; 
     101        } 
    69102        catch (Exception e) { 
     103            throw new IllegalArgumentException("could not process parameters", e); 
     104        } 
     105         
     106        if (sequencesName == null) { 
    70107            throw new IllegalArgumentException("must provide a sequences name"); 
     108        } 
     109         
     110        if (tasktreeName == null) { 
     111            tasktreeName = "tasktree"; 
    71112        } 
    72113 
     
    84125        sequences = (Collection<List<Event>>) dataObject; 
    85126         
    86         ITaskModel taskModel = new TaskTreeManager().createTaskModel(sequences); 
     127        ITaskModel taskModel = new TaskTreeManager().createTaskModel 
     128            (sequences, useEventEqualityForTaskComparison, minimumSequenceCoverage); 
    87129         
    88130        if (GlobalDataContainer.getInstance().addData(tasktreeName, taskModel)) { 
  • trunk/autoquest-ui-core/src/main/resources/manuals/generateTaskTree

    r1877 r2132  
    55<tasktree> name of the object to store the task model in (defaults to "tasktree") 
    66 
     7-considerEventEquality 
     8    to be provided if the events equal method shall be used for event comparison. This can 
     9    accelerate the comparison process 
     10 
     11-minimumSequenceCoverage=<some integer> 
     12    can be used to define a minimum number of events that shall be covered by the detected 
     13    sequences. This prevents the detection of sequences that mainly represent noise. 
     14 
    715Example(s) 
    816generateTaskTree sequences tasktree 
     17generateTaskTree sequences -considerEventEquality 
     18generateTaskTree sequences tasktree -considerEventEquality -minimumSequenceCoverage=10 
Note: See TracChangeset for help on using the changeset viewer.