Ignore:
Timestamp:
03/06/13 23:38:19 (11 years ago)
Author:
pharms
Message:
  • added possibility to perform effective trie processing
  • removed bug that happens, if a trained sequences was shorter than the provided max order
Location:
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java

    r1110 r1118  
    121121    /** 
    122122     * <p> 
    123      * Trains the current trie using the given sequence and adds all subsequence of length 
     123     * Trains the current trie using the given sequence and adds all subsequences of length 
    124124     * {@code maxOrder}. 
    125125     * </p> 
     
    145145        } 
    146146        int sequenceLength = sequence.size(); 
    147         for (int j = maxOrder - 1; j > 0; j--) { 
    148             add(sequence.subList(sequenceLength - j, sequenceLength)); 
     147        int startIndex = Math.max(0, sequenceLength - maxOrder + 1); 
     148        for (int j = startIndex; j < sequenceLength; j++) { 
     149            add(sequence.subList(j, sequenceLength)); 
    149150        } 
    150151    } 
     
    320321 
    321322        return contextSuffix; 
     323    } 
     324     
     325    /** 
     326     *  
     327     */ 
     328    public void process(TrieProcessor<T> processor) { 
     329        LinkedList<T> context = new LinkedList<T>(); 
     330         
     331        for (TrieNode<T> child : rootNode.getChildren()) { 
     332            if (!process(context, child, processor)) { 
     333                break; 
     334            } 
     335        } 
     336    } 
     337 
     338    /** 
     339     * <p> 
     340     * TODO: comment 
     341     * </p> 
     342     * @param context  
     343     * 
     344     * @param child 
     345     * @param processor 
     346     */ 
     347    private boolean process(LinkedList<T>    context, 
     348                            TrieNode<T>      node, 
     349                            TrieProcessor<T> processor) 
     350    { 
     351        context.add(node.getSymbol()); 
     352         
     353        TrieProcessor.Result result = processor.process(context, node.getCount()); 
     354         
     355        if (result == TrieProcessor.Result.CONTINUE) { 
     356            for (TrieNode<T> child : node.getChildren()) { 
     357                if (!process(context, child, processor)) { 
     358                    break; 
     359                } 
     360            } 
     361        } 
     362         
     363        context.removeLast(); 
     364         
     365        return result != TrieProcessor.Result.BREAK; 
    322366    } 
    323367 
Note: See TracChangeset for help on using the changeset viewer.