Package opennlp.tools.postag
Class POSDictionary
- java.lang.Object
-
- opennlp.tools.postag.POSDictionary
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
,MutableTagDictionary
,TagDictionary
,SerializableArtifact
public class POSDictionary extends java.lang.Object implements java.lang.Iterable<java.lang.String>, MutableTagDictionary, SerializableArtifact
Provides a means of determining which tags are valid for a particular word based on a tag dictionary read from a file.
-
-
Constructor Summary
Constructors Constructor Description POSDictionary()
Initializes an empty case sensitivePOSDictionary
.POSDictionary(boolean caseSensitive)
Initializes an emptyPOSDictionary
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static POSDictionary
create(java.io.InputStream in)
Creates a newPOSDictionary
from a providedInputStream
.boolean
equals(java.lang.Object obj)
java.lang.Class<?>
getArtifactSerializerClass()
Retrieves the class which can serialize and recreate this artifact.java.lang.String[]
getTags(java.lang.String word)
Returns a list of valid tags for the specified word.int
hashCode()
boolean
isCaseSensitive()
Whether if the dictionary is case sensitive or notjava.util.Iterator<java.lang.String>
iterator()
Retrieves an iterator over all words in the dictionary.java.lang.String[]
put(java.lang.String word, java.lang.String... tags)
Associates the specified tags with the specified word.void
serialize(java.io.OutputStream out)
Writes thePOSDictionary
to the givenOutputStream
; After the serialization is finished the providedOutputStream
remains open.java.lang.String
toString()
-
-
-
Constructor Detail
-
POSDictionary
public POSDictionary()
Initializes an empty case sensitivePOSDictionary
.
-
POSDictionary
public POSDictionary(boolean caseSensitive)
Initializes an emptyPOSDictionary
.- Parameters:
caseSensitive
- thePOSDictionary
case sensitivity
-
-
Method Detail
-
getTags
public java.lang.String[] getTags(java.lang.String word)
Returns a list of valid tags for the specified word.- Specified by:
getTags
in interfaceTagDictionary
- Parameters:
word
- The word.- Returns:
- A list of valid tags for the specified word or null if no information is available for that word.
-
iterator
public java.util.Iterator<java.lang.String> iterator()
Retrieves an iterator over all words in the dictionary.- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
-
serialize
public void serialize(java.io.OutputStream out) throws java.io.IOException
Writes thePOSDictionary
to the givenOutputStream
; After the serialization is finished the providedOutputStream
remains open.- Parameters:
out
- theOutputStream
to write the dictionary into.- Throws:
java.io.IOException
- if writing to theOutputStream
fails
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
create
public static POSDictionary create(java.io.InputStream in) throws java.io.IOException
Creates a newPOSDictionary
from a providedInputStream
. After creation is finished the providedInputStream
is closed.- Parameters:
in
-- Returns:
- the pos dictionary
- Throws:
java.io.IOException
InvalidFormatException
-
put
public java.lang.String[] put(java.lang.String word, java.lang.String... tags)
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:MutableTagDictionary
Whether if the dictionary is case sensitive or not- Specified by:
isCaseSensitive
in interfaceMutableTagDictionary
- Returns:
- true if the dictionary is case sensitive
-
getArtifactSerializerClass
public java.lang.Class<?> 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.
-
-