Package opennlp.tools.postag
Class POSDictionary
java.lang.Object
opennlp.tools.postag.POSDictionary
- All Implemented Interfaces:
Iterable<String>
,MutableTagDictionary
,TagDictionary
,SerializableArtifact
public class POSDictionary
extends Object
implements Iterable<String>, MutableTagDictionary, SerializableArtifact
Provides a means of determining which tags are valid for a particular word
based on a
TagDictionary
read from a file.-
Constructor Summary
ConstructorDescriptionInitializes an empty case sensitivePOSDictionary
.POSDictionary
(boolean caseSensitive) Initializes an emptyPOSDictionary
. -
Method Summary
Modifier and TypeMethodDescriptionstatic POSDictionary
create
(InputStream in) Creates a newPOSDictionary
from anInputStream
.boolean
Class<?>
Retrieves the class which can serialize and recreate this artifact.String[]
Returns a list of valid tags for the specifiedword
.int
hashCode()
boolean
Whether the dictionary is case-sensitive or not.iterator()
Retrieves anIterator
over all words in the dictionary.String[]
Associates the specified tags with the specified word.void
serialize
(OutputStream out) Writes thePOSDictionary
to the givenOutputStream
;toString()
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
POSDictionary
public POSDictionary()Initializes an empty case sensitivePOSDictionary
. -
POSDictionary
public POSDictionary(boolean caseSensitive) Initializes an emptyPOSDictionary
.- Parameters:
caseSensitive
-true
if thePOSDictionary
is case sensitive,false
otherwise.
-
-
Method Details
-
getTags
Returns a list of valid tags for the specifiedword
.- Specified by:
getTags
in interfaceTagDictionary
- Parameters:
word
- The word.- Returns:
- An array of valid tags for the specified word or
null
if no information is available for that word.
-
iterator
Retrieves anIterator
over all words in the dictionary. -
serialize
Writes thePOSDictionary
to the givenOutputStream
;After the serialization is finished the provided
OutputStream
remains open.- Parameters:
out
- theOutputStream
to write the dictionary into.- Throws:
IOException
- Throw if writing to theOutputStream
fails
-
hashCode
public int hashCode() -
equals
-
toString
-
create
Creates a newPOSDictionary
from anInputStream
.After creation is finished the provided
InputStream
is closed.- Parameters:
in
- TheInputStream
used for creating thePOSDictionary
. The stream must be open and have bytes available to read from.- Returns:
- A valid
POSDictionary
instance. - Throws:
IOException
- Thrown if IO errors occurred during creation.InvalidFormatException
- Thrown if the entries don't have exactly one token.
-
put
Description copied from interface:MutableTagDictionary
Associates the specified tags with the specified word. If the dictionary previously contained keys for the word, the old tags are replaced by the specified tags.- Specified by:
put
in interfaceMutableTagDictionary
- Parameters:
word
- word with which the specified tags is to be associatedtags
- tags to be associated with the specified word- Returns:
- the previous tags associated with the word, or null if there was no mapping for word.
-
isCaseSensitive
public boolean isCaseSensitive()Description copied from interface:TagDictionary
Whether the dictionary is case-sensitive or not.- Specified by:
isCaseSensitive
in interfaceTagDictionary
- Returns:
true
if the dictionary is case-sensitive, elsefalse
.
-
getArtifactSerializerClass
Description copied from interface:SerializableArtifact
Retrieves the class which can serialize and recreate this artifact.Note: The serializer class must have a
public zero argument constructor
or an exception is thrown during model serialization/loading.- Specified by:
getArtifactSerializerClass
in interfaceSerializableArtifact
- Returns:
- The corresponding
ArtifactSerializer
class.
-