// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.tasktrees.temporalrelation; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; import de.ugoe.cs.autoquest.usageprofiles.Trie; import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor; /** *
* This trie implementation is a performance optimization for generating task trees. It does not * create a full trie but adds only those subsequences having a chance of occurring most often. * For this, it initially counts the number of occurrences of each task instance. Then, during * training, it regularly determines the number of the currently most often occurring sequence. If * this number is higher than the count of a task instance to be trained, the task instance is * skipped the not added to the trie. *
* * @author Patrick Harms */ class TaskInstanceTrie extends Trie* the task handling strategy to be used for comparing tasks *
*/ private TaskHandlingStrategy taskStrategy; /** ** instantiated the trie with the task handling strategy to be used *
* * @param taskStrategy the task handling strategy to be used for comparing tasks */ public TaskInstanceTrie(TaskHandlingStrategy taskStrategy) { super(taskStrategy); this.taskStrategy = taskStrategy; } /** ** trains this trie with the provided user sessions up to the provided maximum depth using * the optimization described in the description of this class. *
* * @param userSessions the sessions for which this trie is to be trained * @param maxOrder the depth of the trie */ public void trainSessions(List* internally used convenience method for implementing the training optimization *
*/ private void train(IUserSession userSession, int maxOrder, Map* determines the current maximum count of sequences of a minimal length of two. Task instances * occuring more seldom do not have to be considered anymore *
* * @return the current maximum count of sequences of a minimal length of two */ private int getCurrentSequenceMaxCount() { MaxSequenceCountFinder processor = new MaxSequenceCountFinder(); super.process(processor); return processor.getMaxCount(); } /** ** trie processor identifying the current maximum count of sequences of a minimal length of two *
* * @author Patrick Harms */ private static class MaxSequenceCountFinder implements TrieProcessor* the current maximum count *
*/ private int currentCount = 0; /* (non-Javadoc) * @see de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util.List, int) */ @Override public TrieProcessor.Result process(List* returns the current maximum count *
*/ private int getMaxCount() { return currentCount; } } /** ** counter object to be able to call something by the counters reference *
* * @author Patrick Harms */ private static class Counter { int count = 0; } }