Class EnglishUnknownWordModel
- java.lang.Object
-
- edu.stanford.nlp.parser.lexparser.BaseUnknownWordModel
-
- edu.stanford.nlp.parser.lexparser.EnglishUnknownWordModel
-
- All Implemented Interfaces:
UnknownWordModel,Serializable
public class EnglishUnknownWordModel extends BaseUnknownWordModel
This is a basic unknown word model for English. It supports 5 different types of feature modeling; seegetSignature(String, int). Implementation note: the contents of this class tend to overlap somewhat withArabicUnknownWordModeland were originally included inBaseLexicon.- Author:
- Dan Klein, Galen Andrew, Christopher Manning, Anna Rafferty
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleansmartMutationprotected intunknownPrefixSizeprotected intunknownSuffixSizeprotected StringwordClassesFile-
Fields inherited from class edu.stanford.nlp.parser.lexparser.BaseUnknownWordModel
NULL_ITW, nullTag, nullWord, tagHash, tagIndex, trainOptions, unknown, unknownLevel, unSeenCounter, useFirst, useGT, VERBOSE, wordIndex
-
-
Constructor Summary
Constructors Constructor Description EnglishUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex)This constructor creates an UWM with empty data structures.EnglishUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex, ClassicCounter<IntTaggedWord> unSeenCounter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetSignature(String word, int loc)This routine returns a String that is the "signature" of the class of a word.intgetSignatureIndex(int index, int sentencePosition, String word)Returns the index of the signature of the word numbered wordIndex, where the signature is the String representation of unknown word features.floatscore(IntTaggedWord iTW, int loc, double c_Tseen, double total, double smooth, String word)Currently we don't consider loc or the other parameters in determining score in the default implementation; only English uses them.doublescoreProbTagGivenWordSignature(IntTaggedWord iTW, int loc, double smooth, String word)Calculate P(Tag|Signature) with Bayesian smoothing via just P(Tag|Unknown)-
Methods inherited from class edu.stanford.nlp.parser.lexparser.BaseUnknownWordModel
addTagging, getLexicon, getUnknownLevel, score, scoreGT, unSeenCounter
-
-
-
-
Field Detail
-
smartMutation
protected final boolean smartMutation
-
unknownSuffixSize
protected final int unknownSuffixSize
-
unknownPrefixSize
protected final int unknownPrefixSize
-
wordClassesFile
protected final String wordClassesFile
-
-
Constructor Detail
-
EnglishUnknownWordModel
public EnglishUnknownWordModel(Options op, Lexicon lex, Index<String> wordIndex, Index<String> tagIndex, ClassicCounter<IntTaggedWord> unSeenCounter)
-
-
Method Detail
-
score
public float score(IntTaggedWord iTW, int loc, double c_Tseen, double total, double smooth, String word)
Description copied from class:BaseUnknownWordModelCurrently we don't consider loc or the other parameters in determining score in the default implementation; only English uses them.- Specified by:
scorein interfaceUnknownWordModel- Overrides:
scorein classBaseUnknownWordModel- Parameters:
iTW- An IntTaggedWord pairing a word and POS tagloc- The position in the sentence. In the default implementation this is used only for unknown words to change their probability distribution when sentence initial. Now, a negative valuec_Tseen- Total count of this tag (on seen words) in trainingtotal- Total count of word tokens in trainingsmooth- Weighting on prior P(T|U) in estimateword- The word itself; useful so we don't look it up in the index- Returns:
- A double valued score, usually - log P(word|tag)
-
scoreProbTagGivenWordSignature
public double scoreProbTagGivenWordSignature(IntTaggedWord iTW, int loc, double smooth, String word)
Calculate P(Tag|Signature) with Bayesian smoothing via just P(Tag|Unknown)- Specified by:
scoreProbTagGivenWordSignaturein interfaceUnknownWordModel- Overrides:
scoreProbTagGivenWordSignaturein classBaseUnknownWordModel
-
getSignatureIndex
public int getSignatureIndex(int index, int sentencePosition, String word)Returns the index of the signature of the word numbered wordIndex, where the signature is the String representation of unknown word features.- Specified by:
getSignatureIndexin interfaceUnknownWordModel- Overrides:
getSignatureIndexin classBaseUnknownWordModel
-
getSignature
public String getSignature(String word, int loc)
This routine returns a String that is the "signature" of the class of a word. For, example, it might represent whether it is a number of ends in -s. The strings returned by convention matches the pattern UNK(-.+)? , which is just assumed to not match any real word. Behavior depends on the unknownLevel (-uwm flag) passed in to the class. The recognized numbers are 1-5: 5 is fairly English-specific; 4, 3, and 2 look for various word features (digits, dashes, etc.) which are only vaguely English-specific; 1 uses the last two characters combined with a simple classification by capitalization.- Specified by:
getSignaturein interfaceUnknownWordModel- Overrides:
getSignaturein classBaseUnknownWordModel- Parameters:
word- The word to make a signature forloc- Its position in the sentence (mainly so sentence-initial capitalized words can be treated differently)- Returns:
- A String that is its signature (equivalence class)
-
-