com.aliasi.lm
Class ScaleTrieReader

java.lang.Object
  extended by com.aliasi.lm.ScaleTrieReader
All Implemented Interfaces:
TrieReader

public class ScaleTrieReader
extends Object

A ScaleTrieReader filters a contained trie reader by scaling all counts by a given multiple, removing all subtrees with zero root counts. Counts are rounded after multiplication using Math.round(double). Thus pruning will only occur if the scaling factor is less than 0.5, because 0.5 rounds to 1.

Since:
LingPipe2.3
Version:
2.3
Author:
Bob Carpenter

Constructor Summary
ScaleTrieReader(TrieReader reader, double scale)
          Construct a scaling trie reader wrapping the specified reader and scaling counts with the specified value.
 
Method Summary
 long readCount()
          Returns the count of the next tree.
 long readSymbol()
          Returns the identifier of the symbol leading from the root of the current tree to the daughter subtree for the symbol, or -1 if there are no more subtrees for the current node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaleTrieReader

public ScaleTrieReader(TrieReader reader,
                       double scale)
                throws IOException
Construct a scaling trie reader wrapping the specified reader and scaling counts with the specified value.

Parameters:
reader - Contained reader.
scale - Scaling factor.
Throws:
IllegalArgumentException - If the scale is not a positive, non-infinite value.
IOException
Method Detail

readCount

public long readCount()
Description copied from interface: TrieReader
Returns the count of the next tree.

Specified by:
readCount in interface TrieReader
Returns:
The count of the next tree.

readSymbol

public long readSymbol()
                throws IOException
Description copied from interface: TrieReader
Returns the identifier of the symbol leading from the root of the current tree to the daughter subtree for the symbol, or -1 if there are no more subtrees for the current node.

Specified by:
readSymbol in interface TrieReader
Returns:
The symbol leading to the next subtree.
Throws:
IOException - If there is an underlying I/O error.