public abstract class AbstractLexicalSmoother extends IsCloseableObject implements LexicalSmoother, UsesLogger
An abstract lexical smoother which provides implementations of common service methods such as setting the lexicon and the transition proability matrix. Extend this class and override the abstract method "lexicalProbability" to produce a new lexical smoother.
Modifier and Type | Field and Description |
---|---|
protected Map2D<java.lang.String,java.lang.String,Probability> |
cachedLexicalProbabilities
Cached lexical probabilities for words.
|
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 |
---|
AbstractLexicalSmoother()
Create an abstract lexical smoother.
|
Modifier and Type | Method and Description |
---|---|
int |
cachedProbabilitiesCount()
Get the number of cached lexical probabilities.
|
void |
clearCachedProbabilities()
Clear cached probabilities..
|
Logger |
getLogger()
Get the logger.
|
abstract Probability |
lexicalProbability(java.lang.String word,
java.lang.String tag)
Get lexically smoothed probability of a word given a tag.
|
void |
setLogger(Logger logger)
Set the logger.
|
void |
setPartOfSpeechTagger(PartOfSpeechTagger partOfSpeechTagger)
Set the part of speech tagger for this smoother.
|
close
protected PartOfSpeechTagger partOfSpeechTagger
protected Map2D<java.lang.String,java.lang.String,Probability> cachedLexicalProbabilities
protected Logger logger
public AbstractLexicalSmoother()
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 LexicalSmoother
partOfSpeechTagger
- Part of speech tagger for which
this smoother provides probabilities.public int cachedProbabilitiesCount()
cachedProbabilitiesCount
in interface LexicalSmoother
public void clearCachedProbabilities()
clearCachedProbabilities
in interface LexicalSmoother
public abstract Probability lexicalProbability(java.lang.String word, java.lang.String tag)
lexicalProbability
in interface LexicalSmoother
word
- The word.tag
- The part of speech tag.To avoid redoing potentially expensive probability calculations, you can use the "cachedLexicalProbabilities" HashMap2D to store probabilities once they are calculated. Your lexicalProbability method should look to see if the cache contains the needed lexical 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 lexicalProbability method should look like, using the cache.
protected Probability lexicalProbability( String word , String tag ) { // See if the lexical probability // p( word | tag ) is in the cache. Probability result = (Probability)cachedLexicalProbabilities.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 ); cachedLexicalProbabilities.put( word , tag , result ); } return result; }