Ignore:
Timestamp:
02/21/13 18:39:48 (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/manager
Files:
2 edited

Legend:

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

    r1099 r1109  
    8484        nodeEqualityRuleManager.init(); 
    8585 
    86         temporalRelationshipRuleManager = 
    87             new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 
    88         temporalRelationshipRuleManager.init(); 
    89  
    9086        taskTreeBuilder = new TaskTreeBuilder(); 
    9187        taskTreeNodeFactory = new TaskTreeNodeFactory(); 
     88 
     89        temporalRelationshipRuleManager = new TemporalRelationshipRuleManager 
     90            (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder); 
     91        temporalRelationshipRuleManager.init(); 
    9292    } 
    9393 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java

    r922 r1109  
    22 
    33import java.util.Collection; 
     4import java.util.LinkedList; 
    45import java.util.List; 
    56import java.util.logging.Level; 
    67 
    78import de.ugoe.cs.autoquest.eventcore.Event; 
    8 import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange; 
    99import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    1010import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    1111import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 
    1212import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    13 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    1413import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
    1514import de.ugoe.cs.util.console.Console; 
     
    2423     
    2524    /** */ 
    26     private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100; 
    27  
    28     /** */ 
    2925    private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 
    3026 
     
    3430 
    3531    /** */ 
    36     private int eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 
     32    private List<List<IEventTask>> sessions = null; 
    3733 
    3834    /** */ 
    39     private ISequence rootSequence; 
     35    private List<IEventTask> currentSession = null; 
    4036 
    4137    /** 
    42      * TODO: comment 
    43      *  
     38     * 
    4439     */ 
    4540    public TaskTreeManager() { 
    46         rootSequence = taskTreeNodeFactory.createNewSequence(); 
     41        sessions = new LinkedList<List<IEventTask>>(); 
    4742    } 
    4843 
    4944    /** 
    50      * <p> 
    51      * TODO: comment 
    52      * </p> 
    5345     * 
    54      * @param sequences 
    55      * @return 
    5646     */ 
    57     public synchronized ITaskTree createTaskTree(Collection<List<Event>> sequences) { 
     47    public synchronized ITaskTree createTaskTree(Collection<List<Event>> newSessions) { 
     48        if ((currentSession != null) || (sessions.size() > 0)) { 
     49            throw new IllegalStateException("do not mix calls to this method with calls to the " + 
     50                                            "other methods for handling tasks. Use only one " + 
     51                                            "variant instead."); 
     52        } 
    5853         
    59         for (List<Event> sequence : sequences) { 
    60             for (Event event : sequence) { 
    61                 handleNewEvent(event); 
     54        for (List<Event> newSession : newSessions) { 
     55            if (newSession.size() > 0) { 
     56                for (Event event : newSession) { 
     57                    handleNewEvent(event); 
     58                } 
     59                finishSession(); 
    6260            } 
    6361        } 
     
    7068     */ 
    7169    public void handleNewEvent(Event event) { 
    72         handleEventTask(taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 
     70        assertSessionSequence(); 
     71        currentSession.add 
     72            (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 
     73    } 
     74 
     75    /** 
     76     *  
     77     */ 
     78    public void finishSession() { 
     79        if ((currentSession != null) && (currentSession.size() > 0)) { 
     80            sessions.add(currentSession); 
     81            currentSession = null; 
     82        } 
    7383    } 
    7484 
     
    7787     */ 
    7888    public synchronized ITaskTree getTaskTree() { 
     89        finishSession(); 
     90         
    7991        Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 
     92         
     93        ISequence rootSequence = taskTreeNodeFactory.createNewSequence(); 
     94        taskTreeBuilder.setDescription(rootSequence, "root"); 
     95         
     96        for (List<IEventTask> session : sessions) { 
     97            ISequence sequence = taskTreeNodeFactory.createNewSequence(); 
     98            taskTreeBuilder.setDescription(sequence, "session"); 
     99             
     100            for (IEventTask eventTask : session) { 
     101                taskTreeBuilder.addChild(sequence, eventTask); 
     102            } 
     103             
     104            taskTreeBuilder.addChild(rootSequence, sequence); 
     105        } 
     106         
     107         
     108        ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence); 
    80109 
    81         ISequence currentRootSequence = rootSequence.clone(); 
    82         ComponentManager.getTemporalRelationshipRuleManager().applyRules 
    83           (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true); 
    84  
    85         return taskTreeNodeFactory.createTaskTree(currentRootSequence); 
    86     } 
    87  
    88     /** 
    89      * adds the task to the current or the new sequence. The decision depends on the type of task. 
    90      * If the task finishes the current sequence, the sequence is marked as finished If the task 
    91      * does not start a new sequence, it is added to the current sequence, before it is marked s 
    92      * finished. Otherwise it is added to a new sequence. 
    93      */ 
    94     private synchronized void handleEventTask(IEventTask eventTask) { 
    95         if (!(eventTask.getEventType() instanceof KeyboardFocusChange)) { 
    96             Console.traceln(Level.INFO, "handling interaction event task \"" + eventTask + "\""); 
    97             addTaskToSequence(eventTask); 
    98         } 
     110        return taskTreeNodeFactory.createTaskTree(rootSequence); 
    99111    } 
    100112 
     
    102114     * 
    103115     */ 
    104     private void addTaskToSequence(ITaskTreeNode task) 
    105     { 
    106         taskTreeBuilder.addChild(rootSequence, task); 
    107  
    108         if (--eventsTillRuleApplication == 0) { 
    109             eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 
    110  
    111             Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 
    112             ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence, 
    113                                                                              taskTreeBuilder, 
    114                                                                              taskTreeNodeFactory, 
    115                                                                              false); 
     116    private void assertSessionSequence() { 
     117        if (currentSession == null) { 
     118            currentSession = new LinkedList<IEventTask>(); 
    116119        } 
    117120    } 
Note: See TracChangeset for help on using the changeset viewer.