jsat.text.tokenizer
Class NaiveTokenizer
- java.lang.Object
-
- jsat.text.tokenizer.NaiveTokenizer
-
- All Implemented Interfaces:
- java.io.Serializable, Tokenizer
public class NaiveTokenizer extends java.lang.Object implements Tokenizer
A simple tokenizer. It converts everything to lower case, and splits on white space. Anything that is not a letter, digit, or space, is treated as white space. This behavior can be altered slightly, and allows for setting a minimum and maximum allowed length for tokens. This can be useful when dealing with noisy documents, and removing small words.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description NaiveTokenizer()Creates a new naive tokenizer that converts words to lower caseNaiveTokenizer(boolean useLowerCase)Creates a new naive tokenizer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetMaxTokenLength()Returns the maximum allowed token lengthintgetMinTokenLength()Returns the minimum allowed token lengthbooleanisNoDigits()Returnstrueif digits are not allowed in tokens,falseotherwise.booleanisOtherToWhiteSpace()Returns whether or not all other illegal characters are treated as whitespace, or ignored completely.booleanisUseLowerCase()Returnstrueif letters are converted to lower case,falsefor case sensitivevoidsetMaxTokenLength(int maxTokenLength)Sets the maximum allowed length for any token.voidsetMinTokenLength(int minTokenLength)Sets the minimum allowed token length.voidsetNoDigits(boolean noDigits)Sets whether digits will be accepted in tokens or treated as "other" (not white space and not character).voidsetOtherToWhiteSpace(boolean otherToWhiteSpace)Sets whether or not all non letter and digit characters are treated as white space, or ignored completely.voidsetUseLowerCase(boolean useLowerCase)Sets whether or not characters are made to be lower case or notjava.util.List<java.lang.String>tokenize(java.lang.String input)Breaks the input string into a series of tokens that may be used as features for a classifier.voidtokenize(java.lang.String input, java.lang.StringBuilder workSpace, java.util.List<java.lang.String> storageSpace)Breaks the input string into a series of tokens that may be used as features for a classifier.
-
-
-
Constructor Detail
-
NaiveTokenizer
public NaiveTokenizer()
Creates a new naive tokenizer that converts words to lower case
-
NaiveTokenizer
public NaiveTokenizer(boolean useLowerCase)
Creates a new naive tokenizer- Parameters:
useLowerCase-trueto convert everything to lower,falseto leave the case as is
-
-
Method Detail
-
setUseLowerCase
public void setUseLowerCase(boolean useLowerCase)
Sets whether or not characters are made to be lower case or not- Parameters:
useLowerCase-
-
isUseLowerCase
public boolean isUseLowerCase()
Returnstrueif letters are converted to lower case,falsefor case sensitive- Returns:
trueif letters are converted to lower case,
-
setOtherToWhiteSpace
public void setOtherToWhiteSpace(boolean otherToWhiteSpace)
Sets whether or not all non letter and digit characters are treated as white space, or ignored completely. If ignored, the tokenizer parses the string as if all non letter, digit, and whitespace characters did not exist in the original string.
Setting this tofalsecan result in a lower feature count, especially for noisy documents.- Parameters:
otherToWhiteSpace-trueto treat all "other" characters as white space,falseto ignore them
-
isOtherToWhiteSpace
public boolean isOtherToWhiteSpace()
Returns whether or not all other illegal characters are treated as whitespace, or ignored completely.- Returns:
trueif all other characters are treated as whitespace
-
tokenize
public java.util.List<java.lang.String> tokenize(java.lang.String input)
Description copied from interface:TokenizerBreaks the input string into a series of tokens that may be used as features for a classifier. The returned tokens must be either new string objects or interned strings. If a token is returned that is backed by the original document, memory may get leaked by processes consuming the token.
This method should be thread safe
-
tokenize
public void tokenize(java.lang.String input, java.lang.StringBuilder workSpace, java.util.List<java.lang.String> storageSpace)Description copied from interface:TokenizerBreaks the input string into a series of tokens that may be used as features for a classifier. The returned tokens must be either new string objects or interned strings. If a token is returned that is backed by the original document, memory may get leaked by processes consuming the token.
This method should be thread safe
-
setMaxTokenLength
public void setMaxTokenLength(int maxTokenLength)
Sets the maximum allowed length for any token. Any token discovered exceeding the length will not be accepted and skipped over. The default is unbounded.- Parameters:
maxTokenLength- the maximum token length to accept as a valid token
-
getMaxTokenLength
public int getMaxTokenLength()
Returns the maximum allowed token length- Returns:
- the maximum allowed token length
-
setMinTokenLength
public void setMinTokenLength(int minTokenLength)
Sets the minimum allowed token length. Any token discovered shorter than the minimum length will not be accepted and skipped over. The default is 0.- Parameters:
minTokenLength- the minimum length for a token to be used
-
getMinTokenLength
public int getMinTokenLength()
Returns the minimum allowed token length- Returns:
- the maximum allowed token length
-
setNoDigits
public void setNoDigits(boolean noDigits)
Sets whether digits will be accepted in tokens or treated as "other" (not white space and not character).
The default it to allow digits.- Parameters:
noDigits-trueto disallow numeric digits,falseto allow digits.
-
isNoDigits
public boolean isNoDigits()
Returnstrueif digits are not allowed in tokens,falseotherwise.- Returns:
trueif digits are not allowed in tokens,falseotherwise.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG