Package morfologik.stemming
Class WordData
- java.lang.Object
-
- morfologik.stemming.WordData
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class WordData extends java.lang.Object implements java.lang.Cloneable
Stem and tag data associated with a given word. Instances of this class are reused and mutable (values returned fromgetStem()
,getWord()
and other related methods change on subsequent calls toDictionaryLookup
class that returned a given instance ofWordData
. If you need a copy of the stem or tag data for a given word, you have to create a custom buffer yourself and copy the associated data, performclone()
or create strings (they are immutable) usinggetStem()
and thenCharSequence.toString()
. For reasons above it makes no sense to use instances of this class in associative containers or lists. In fact, bothequals(Object)
andhashCode()
are overridden and throw exceptions to prevent accidental damage.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
COLLECTIONS_ERROR_MESSAGE
Error information if somebody puts us in a Java collection.private java.nio.charset.CharsetDecoder
decoder
Character encoding in internal buffers.(package private) java.nio.ByteBuffer
stemBuffer
Byte buffer holding stem data.private java.nio.CharBuffer
stemCharSequence
Character sequence after convertingstemBuffer
usingdecoder
.(package private) java.nio.ByteBuffer
tagBuffer
Byte buffer holding tag data.private java.nio.CharBuffer
tagCharSequence
(package private) java.nio.ByteBuffer
wordBuffer
Byte buffer holding the inflected word form data.private java.lang.CharSequence
wordCharSequence
Inflected word form data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WordData
clone()
Declare a covariant ofObject.clone()
that returns a deep copy of this object.private java.lang.CharSequence
cloneCharSequence(java.lang.CharSequence chs)
Clone char sequences only if not immutable.boolean
equals(java.lang.Object obj)
java.lang.CharSequence
getStem()
java.nio.ByteBuffer
getStemBytes(java.nio.ByteBuffer target)
Copy the stem's binary data (no charset decoding) to a custom byte buffer.java.lang.CharSequence
getTag()
java.nio.ByteBuffer
getTagBytes(java.nio.ByteBuffer target)
Copy the tag's binary data (no charset decoding) to a custom byte buffer.java.lang.CharSequence
getWord()
java.nio.ByteBuffer
getWordBytes(java.nio.ByteBuffer target)
Copy the inflected word's binary data (no charset decoding) to a custom byte buffer.int
hashCode()
java.lang.String
toString()
(package private) void
update(java.nio.ByteBuffer wordBuffer, java.lang.CharSequence word)
-
-
-
Field Detail
-
COLLECTIONS_ERROR_MESSAGE
private static final java.lang.String COLLECTIONS_ERROR_MESSAGE
Error information if somebody puts us in a Java collection.- See Also:
- Constant Field Values
-
decoder
private final java.nio.charset.CharsetDecoder decoder
Character encoding in internal buffers.
-
wordCharSequence
private java.lang.CharSequence wordCharSequence
Inflected word form data.
-
stemCharSequence
private java.nio.CharBuffer stemCharSequence
Character sequence after convertingstemBuffer
usingdecoder
.
-
tagCharSequence
private java.nio.CharBuffer tagCharSequence
-
wordBuffer
java.nio.ByteBuffer wordBuffer
Byte buffer holding the inflected word form data.
-
stemBuffer
java.nio.ByteBuffer stemBuffer
Byte buffer holding stem data.
-
tagBuffer
java.nio.ByteBuffer tagBuffer
Byte buffer holding tag data.
-
-
Method Detail
-
getStemBytes
public java.nio.ByteBuffer getStemBytes(java.nio.ByteBuffer target)
Copy the stem's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.- Parameters:
target
- Target byte buffer to copy the stem buffer to ornull
if a new buffer should be allocated.- Returns:
- Returns
target
or the new reallocated buffer.
-
getTagBytes
public java.nio.ByteBuffer getTagBytes(java.nio.ByteBuffer target)
Copy the tag's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.- Parameters:
target
- Target byte buffer to copy the tag buffer to ornull
if a new buffer should be allocated.- Returns:
- Returns
target
or the new reallocated buffer.
-
getWordBytes
public java.nio.ByteBuffer getWordBytes(java.nio.ByteBuffer target)
Copy the inflected word's binary data (no charset decoding) to a custom byte buffer. The buffer is cleared prior to copying and flipped for reading upon returning from this method. If the buffer is null or not large enough to hold the result, a new buffer is allocated.- Parameters:
target
- Target byte buffer to copy the word buffer to ornull
if a new buffer should be allocated.- Returns:
- Returns
target
or the new reallocated buffer.
-
getTag
public java.lang.CharSequence getTag()
- Returns:
- Return tag data decoded to a character sequence or
null
if no associated tag data exists.
-
getStem
public java.lang.CharSequence getStem()
- Returns:
- Return stem data decoded to a character sequence or
null
if no associated stem data exists.
-
getWord
public java.lang.CharSequence getWord()
- Returns:
- Return inflected word form data. Usually the parameter passed to
DictionaryLookup.lookup(CharSequence)
.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public WordData clone()
Declare a covariant ofObject.clone()
that returns a deep copy of this object. The content of all internal buffers is copied.- Overrides:
clone
in classjava.lang.Object
-
cloneCharSequence
private java.lang.CharSequence cloneCharSequence(java.lang.CharSequence chs)
Clone char sequences only if not immutable.
-
update
void update(java.nio.ByteBuffer wordBuffer, java.lang.CharSequence word)
-
-