public abstract class AbstractContextualSmoother extends IsCloseableObject implements ContextualSmoother, UsesLogger
An abstract contextual smoother which provides implementations of common service methods such as setting the lexicon and the transition probability matrix. Extend this class and override the abstract method "contextualProbability" to produce a new contextual smoother.
Modifier and Type | Field and Description |
---|---|
protected Map3D<java.lang.String,java.lang.String,java.lang.String,Probability> |
cachedContextualProbabilities
Cached contextual probabilities.
|
protected Logger |
logger
Logger used for output.
|
protected PartOfSpeechTagger |
partOfSpeechTagger
The part of speech tagger for which this smoother provides
amoother contextual probabilities.
|
Constructor and Description |
---|
AbstractContextualSmoother()
Create an abstract contextual smoother.
|
Modifier and Type | Method and Description |
---|---|
int |
cachedProbabilitiesCount()
Get the number of cached contextual probabilities.
|
void |
clearCachedProbabilities()
Clear cached probabilities..
|
abstract Probability |
contextualProbability(java.lang.String word,
java.lang.String tag)
Get contextually smoothed probability of a word given a tag.
|
Logger |
getLogger()
Get the logger.
|
void |
setLogger(Logger logger)
Set the logger.
|
void |
setPartOfSpeechTagger(PartOfSpeechTagger partOfSpeechTagger)
Set the part of speech tagger for this smoother.
|
close
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
contextualProbability
protected PartOfSpeechTagger partOfSpeechTagger
protected Map3D<java.lang.String,java.lang.String,java.lang.String,Probability> cachedContextualProbabilities
protected Logger logger
public AbstractContextualSmoother()
public Logger getLogger()
getLogger
in interface UsesLogger
public void setLogger(Logger logger)
setLogger
in interface UsesLogger
logger
- The logger.public void setPartOfSpeechTagger(PartOfSpeechTagger partOfSpeechTagger)
setPartOfSpeechTagger
in interface ContextualSmoother
partOfSpeechTagger
- Part of speech tagger for which
this smoother provides probabilities.public int cachedProbabilitiesCount()
cachedProbabilitiesCount
in interface ContextualSmoother
public void clearCachedProbabilities()
clearCachedProbabilities
in interface ContextualSmoother
public abstract Probability contextualProbability(java.lang.String word, java.lang.String tag)
contextualProbability
in interface ContextualSmoother
word
- The word.tag
- The part of speech tag.To avoid redoing potentially expensive probability calculations, you can use the "cachedContextualProbabilities" HashMap2D to store probabilities once they are calculated. Your contextualProbability method should look to see if the cache contains the needed contextual probability. If so, just retrieve it without recomputing it. If the cache does not contain the probability, compute it, and store it in the cache for future use.
Here is what a contextualProbability method should look like, using the cache.
protected Probability contextualProbability( String word , String tag ) { // See if the contextual probability // p( word | tag ) is in the cache. Probability result = (Probability)cachedContextualProbabilities.get( word , tag ); // If the probability isn't in the // cache, compute it. if ( result == null ) { double prob = compute smoothed probability value // Store computed probability in // the cache. result = new Probability( prob ); cachedContextualProbabilities.put( word , tag , result ); } return result; }