public final class DictionaryLookup extends java.lang.Object implements IStemmer, java.lang.Iterable<WordData>
Important: finite state automatons in Jan Daciuk's implementation use bytes not unicode characters. Therefore objects of this class always have to be constructed with an encoding used to convert Java strings to byte arrays and the other way around. You can use UTF-8 encoding, as it should not conflict with any control sequences and separator characters.
| Modifier and Type | Field and Description |
|---|---|
private java.nio.ByteBuffer |
byteBuffer
Internal reusable buffer for encoding words into byte arrays using
encoder. |
private java.nio.CharBuffer |
charBuffer
Internal reusable buffer for encoding words into byte arrays using
encoder. |
private java.nio.charset.CharsetDecoder |
decoder
Charset decoder for the FSA.
|
private Dictionary |
dictionary
The
Dictionary this lookup is using. |
private DictionaryMetadata |
dictionaryMetadata
Features of the compiled dictionary.
|
private java.nio.charset.CharsetEncoder |
encoder
Charset encoder for the FSA.
|
private static int |
EXPAND_SIZE
Expand buffers and arrays by this constant.
|
private ByteSequenceIterator |
finalStatesIterator
An iterator for walking along the final states of
fsa. |
private WordData[] |
forms
Private internal array of reusable word data objects.
|
private ArrayViewList<WordData> |
formsList
A "view" over an array implementing
|
private FSA |
fsa
The FSA we are using.
|
private FSATraversal |
matcher
An FSA used for lookups.
|
private MatchResult |
matchResult
Reusable match result.
|
private int |
rootNode
FSA's root node.
|
private char |
separatorChar |
private ISequenceEncoder |
sequenceEncoder |
| Constructor and Description |
|---|
DictionaryLookup(Dictionary dictionary)
Creates a new object of this class using the given FSA for word lookups
and encoding for converting characters to bytes.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
applyReplacements(java.lang.CharSequence word,
java.util.LinkedHashMap<java.lang.String,java.lang.String> replacements)
Apply partial string replacements from a given map.
|
private java.nio.ByteBuffer |
charsToBytes(java.nio.CharBuffer chars,
java.nio.ByteBuffer bytes)
Encode a character sequence into a byte buffer, optionally expanding
buffer.
|
Dictionary |
getDictionary() |
char |
getSeparatorChar() |
java.util.Iterator<WordData> |
iterator()
Return an iterator over all
WordData entries available in the
embedded Dictionary. |
java.util.List<WordData> |
lookup(java.lang.CharSequence word)
Searches the automaton for a symbol sequence equal to
word,
followed by a separator. |
private final FSATraversal matcher
private final ByteSequenceIterator finalStatesIterator
fsa.private final int rootNode
private static final int EXPAND_SIZE
private WordData[] forms
private final ArrayViewList<WordData> formsList
private final DictionaryMetadata dictionaryMetadata
DictionaryMetadataprivate final java.nio.charset.CharsetEncoder encoder
private final java.nio.charset.CharsetDecoder decoder
private final FSA fsa
private final char separatorChar
getSeparatorChar()private java.nio.ByteBuffer byteBuffer
encoder.private java.nio.CharBuffer charBuffer
encoder.private final MatchResult matchResult
private final Dictionary dictionary
Dictionary this lookup is using.private final ISequenceEncoder sequenceEncoder
public DictionaryLookup(Dictionary dictionary) throws java.lang.IllegalArgumentException
dictionary - The dictionary to use for lookups.java.lang.IllegalArgumentException - if FSA's root node cannot be acquired (dictionary is empty).public java.util.List<WordData> lookup(java.lang.CharSequence word)
word,
followed by a separator. The result is a stem (decompressed accordingly
to the dictionary's specification) and an optional tag data.public static java.lang.String applyReplacements(java.lang.CharSequence word,
java.util.LinkedHashMap<java.lang.String,java.lang.String> replacements)
word - The word to apply replacements to.replacements - A map of replacements (from->to).private java.nio.ByteBuffer charsToBytes(java.nio.CharBuffer chars,
java.nio.ByteBuffer bytes)
public java.util.Iterator<WordData> iterator()
WordData entries available in the
embedded Dictionary.iterator in interface java.lang.Iterable<WordData>public Dictionary getDictionary()
Dictionary used by this object.public char getSeparatorChar()
DictionaryMetadata.separator and
may not be valid in the target encoding (although this is highly unlikely).