Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java	(revision 1889)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java	(revision 2132)
@@ -16,9 +16,12 @@
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 
 import de.ugoe.cs.autoquest.eventcore.Event;
+import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
@@ -72,9 +75,42 @@
     /**
      * <p>
+     * The default task equality considered when comparing task instances initially
+     * </p>
+     */
+    private TaskEquality minimalTaskEquality = TaskEquality.SEMANTICALLY_EQUAL;
+
+    /**
+     * <p>
+     * If this flag is set, then the task tree manager will not create new event tasks for any
+     * events. Instead, it will check using the hashcode and equal methods of the provided events
+     * if a certain event has already occurred, and if so, the corresponding event task will be
+     * reused.
+     * </p>
+     */
+    private boolean useEventEqualityForTaskComparison;
+    
+    /**
+     * <p>
+     * the minimum number of event task instances a sequence must cover to still detect it as a
+     * representative task
+     * </p>
+     */
+    private int minimumSequenceCoverage;;
+
+    /**
+     * <p>
+     * If the flag {@link #useEventEqualityForTaskComparison} is set, then here the task tree
+     * manager stores the already created event tasks.
+     * </p>
+     */
+    private Map<Event, IEventTask> eventTasks = new HashMap<>();
+
+    /**
+     * <p>
      * initializes the task tree manager
      * </p>
      */
     public TaskTreeManager() {
-        sessions = new LinkedList<IUserSession>();
+        this.sessions = new LinkedList<IUserSession>();
     }
 
@@ -96,5 +132,8 @@
      *                               single events
      */
-    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) {
+    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions,
+                                                   boolean useEventEqualityForTaskComparison,
+                                                   int     minimumSequenceCoverage)
+    {
         if ((currentSession != null) || (sessions.size() > 0)) {
             throw new IllegalStateException("do not mix calls to this method with calls to the " +
@@ -102,4 +141,13 @@
                                             "variant instead.");
         }
+        
+        this.useEventEqualityForTaskComparison = useEventEqualityForTaskComparison;
+        
+        if (useEventEqualityForTaskComparison) {
+            // if we do this, we also need to consider identity of event tasks afterwards
+            minimalTaskEquality = TaskEquality.IDENTICAL;
+        }
+        
+        this.minimumSequenceCoverage = minimumSequenceCoverage;
         
         for (List<Event> newSession : newSessions) {
@@ -117,4 +165,21 @@
     /**
      * <p>
+     * call {@link #createTaskModel(Collection, boolean, int)} with false for use event equality
+     * for comparison and 0 for the minimum number of covered events per sequence
+     * </p>
+     * 
+     * @param newSessions the user sessions of which the task model shall be created
+     * 
+     * @return the task model created from the user sessions
+     * 
+     * @throws IllegalStateException if the task manager is already used by providing it with
+     *                               single events
+     */
+    public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) {
+        return createTaskModel(newSessions, false, 0);
+    }
+
+    /**
+     * <p>
      * handles a single event that occurred in a user session.
      * </p>
@@ -124,8 +189,22 @@
     public void handleNewEvent(Event event) {
         assertSessionSequence();
-        String description = event.getType().getName() + " \u21D2 " + event.getTarget();
-        IEventTask eventTask = taskFactory.createNewEventTask(description);
-        taskBuilder.addExecutedTask
-            (currentSession, taskFactory.createNewTaskInstance(eventTask, event));
+        
+        if (!useEventEqualityForTaskComparison) {
+            String description = event.getType().getName() + " \u21D2 " + event.getTarget();
+            IEventTask eventTask = taskFactory.createNewEventTask(description);
+            taskBuilder.addExecutedTask
+                (currentSession, taskFactory.createNewTaskInstance(eventTask, event));
+        }
+        else {
+            IEventTask eventTask = eventTasks.get(event);
+            if (eventTask == null) {
+                String description = event.getType().getName() + " \u21D2 " + event.getTarget();
+                eventTask = taskFactory.createNewEventTask(description);
+                eventTasks.put(event, eventTask);
+            }
+            
+            taskBuilder.addExecutedTask
+                (currentSession, taskFactory.createNewTaskInstance(eventTask, event));
+        }
     }
 
@@ -157,5 +236,6 @@
             (Level.INFO, "applying temporal relationship generation rules for detecting tasks");
         
-        ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule(sessions);
+        ComponentManager.getTemporalRelationshipRuleManager().applyTaskDetectionRule
+            (sessions, minimalTaskEquality, minimumSequenceCoverage);
 
         return taskFactory.createTaskModel(sessions);
