Package org.apache.lucene.analysis.th
Class ThaiTokenizer
java.lang.Object
org.apache.lucene.util.AttributeSource
org.apache.lucene.analysis.TokenStream
org.apache.lucene.analysis.Tokenizer
org.apache.lucene.analysis.util.SegmentingTokenizerBase
org.apache.lucene.analysis.th.ThaiTokenizer
- All Implemented Interfaces:
Closeable,AutoCloseable
Tokenizer that uses
BreakIterator to tokenize Thai text.
Supports an optional user dictionary (CharArraySet) for custom or domain-specific
words. When a user dictionary word matches, it takes precedence over default segmentation
boundaries.
WARNING: this tokenizer may not be supported by all JREs. It is known to work with Sun/Oracle and Harmony JREs. If your application needs to be fully portable, consider using ICUTokenizer instead, which uses an ICU Thai BreakIterator that will always be available.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
AttributeSource.State -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanTrue if the JRE supports a working dictionary-based breakiterator for Thai.static final intDefault buffer size in characters for Thai sentence segmentationFields inherited from class org.apache.lucene.analysis.util.SegmentingTokenizerBase
buffer, BUFFERMAX, offsetFields inherited from class org.apache.lucene.analysis.TokenStream
DEFAULT_TOKEN_ATTRIBUTE_FACTORY -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ThaiTokenizerThaiTokenizer(int bufferSize) Creates a new ThaiTokenizer with a custom buffer size.ThaiTokenizer(CharArraySet userDictionary) Creates a new ThaiTokenizer with a user dictionary.ThaiTokenizer(CharArraySet userDictionary, int bufferSize) Creates a new ThaiTokenizer with a user dictionary and custom buffer size.ThaiTokenizer(AttributeFactory factory) Creates a new ThaiTokenizer, supplying the AttributeFactoryThaiTokenizer(AttributeFactory factory, CharArraySet userDictionary) Creates a new ThaiTokenizer, supplying the AttributeFactory and user dictionary.ThaiTokenizer(AttributeFactory factory, CharArraySet userDictionary, int bufferSize) Creates a new ThaiTokenizer, supplying the AttributeFactory, user dictionary, and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReturns true if another word is availableprotected booleanisSafeEnd(char ch) For sentence tokenization, these are the unambiguous break positions.protected voidsetNextSentence(int sentenceStart, int sentenceEnd) Provides the next input sentence for analysisMethods inherited from class org.apache.lucene.analysis.util.SegmentingTokenizerBase
end, incrementToken, resetMethods inherited from class org.apache.lucene.analysis.Tokenizer
close, correctOffset, setReader, setReaderTestPointMethods inherited from class org.apache.lucene.util.AttributeSource
addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString
-
Field Details
-
DBBI_AVAILABLE
public static final boolean DBBI_AVAILABLETrue if the JRE supports a working dictionary-based breakiterator for Thai. If this is false, this tokenizer will not work at all! -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size in characters for Thai sentence segmentation- See Also:
-
-
Constructor Details
-
ThaiTokenizer
public ThaiTokenizer()Creates a new ThaiTokenizer -
ThaiTokenizer
Creates a new ThaiTokenizer with a user dictionary.- Parameters:
userDictionary- custom dictionary of words, or null for default dictionary only
-
ThaiTokenizer
public ThaiTokenizer(int bufferSize) Creates a new ThaiTokenizer with a custom buffer size.- Parameters:
bufferSize- internal buffer size in characters
-
ThaiTokenizer
Creates a new ThaiTokenizer with a user dictionary and custom buffer size.- Parameters:
userDictionary- custom dictionary of words, or null for default dictionary onlybufferSize- internal buffer size in characters
-
ThaiTokenizer
Creates a new ThaiTokenizer, supplying the AttributeFactory -
ThaiTokenizer
Creates a new ThaiTokenizer, supplying the AttributeFactory and user dictionary.- Parameters:
factory- AttributeFactory to useuserDictionary- custom dictionary of words, or null for default dictionary only
-
ThaiTokenizer
Creates a new ThaiTokenizer, supplying the AttributeFactory, user dictionary, and buffer size.- Parameters:
factory- AttributeFactory to useuserDictionary- custom dictionary of words, or null for default dictionary onlybufferSize- internal buffer size in characters
-
-
Method Details
-
isSafeEnd
protected boolean isSafeEnd(char ch) Description copied from class:SegmentingTokenizerBaseFor sentence tokenization, these are the unambiguous break positions.- Overrides:
isSafeEndin classSegmentingTokenizerBase
-
setNextSentence
protected void setNextSentence(int sentenceStart, int sentenceEnd) Description copied from class:SegmentingTokenizerBaseProvides the next input sentence for analysis- Specified by:
setNextSentencein classSegmentingTokenizerBase
-
incrementWord
protected boolean incrementWord()Description copied from class:SegmentingTokenizerBaseReturns true if another word is available- Specified by:
incrementWordin classSegmentingTokenizerBase
-