opennlp.tools.postag
Class POSDictionary

java.lang.Object
  extended by opennlp.tools.postag.POSDictionary
All Implemented Interfaces:
Iterable<String>, MutableTagDictionary, TagDictionary

public class POSDictionary
extends Object
implements Iterable<String>, MutableTagDictionary

Provides a means of determining which tags are valid for a particular word based on a tag dictionary read from a file.


Constructor Summary
POSDictionary()
          Initializes an empty case sensitive POSDictionary.
POSDictionary(boolean caseSensitive)
          Initializes an empty POSDictionary.
POSDictionary(BufferedReader reader, boolean caseSensitive)
          Deprecated. Use create(InputStream) instead, old format might removed.
POSDictionary(String file)
          Deprecated. Use create(InputStream) instead, old format might removed.
POSDictionary(String file, boolean caseSensitive)
          Deprecated. Use create(InputStream) instead, old format might removed.
POSDictionary(String file, String encoding, boolean caseSensitive)
          Deprecated. Use create(InputStream) instead, old format might removed.
 
Method Summary
static POSDictionary create(InputStream in)
          Creates a new POSDictionary from a provided InputStream.
 boolean equals(Object o)
           
 String[] getTags(String word)
          Returns a list of valid tags for the specified word.
 boolean isCaseSensitive()
          Whether if the dictionary is case sensitive or not
 Iterator<String> iterator()
          Retrieves an iterator over all words in the dictionary.
 String[] put(String word, String... tags)
          Associates the specified tags with the specified word.
 void serialize(OutputStream out)
          Writes the POSDictionary to the given OutputStream; After the serialization is finished the provided OutputStream remains open.
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

POSDictionary

public POSDictionary()
Initializes an empty case sensitive POSDictionary.


POSDictionary

public POSDictionary(boolean caseSensitive)
Initializes an empty POSDictionary.

Parameters:
caseSensitive - the POSDictionary case sensitivity

POSDictionary

@Deprecated
public POSDictionary(String file)
              throws IOException
Deprecated. Use create(InputStream) instead, old format might removed.

Creates a tag dictionary with contents of specified file.

Parameters:
file - The file name for the tag dictionary.
Throws:
IOException - when the specified file can not be read.

POSDictionary

@Deprecated
public POSDictionary(String file,
                                boolean caseSensitive)
              throws IOException
Deprecated. Use create(InputStream) instead, old format might removed.

Creates a tag dictionary with contents of specified file and using specified case to determine how to access entries in the tag dictionary.

Parameters:
file - The file name for the tag dictionary.
caseSensitive - Specifies whether the tag dictionary is case sensitive or not.
Throws:
IOException - when the specified file can not be read.

POSDictionary

@Deprecated
public POSDictionary(String file,
                                String encoding,
                                boolean caseSensitive)
              throws IOException
Deprecated. Use create(InputStream) instead, old format might removed.

Creates a tag dictionary with contents of specified file and using specified case to determine how to access entries in the tag dictionary.

Parameters:
file - The file name for the tag dictionary.
encoding - The encoding of the tag dictionary file.
caseSensitive - Specifies whether the tag dictionary is case sensitive or not.
Throws:
IOException - when the specified file can not be read.

POSDictionary

@Deprecated
public POSDictionary(BufferedReader reader,
                                boolean caseSensitive)
              throws IOException
Deprecated. Use create(InputStream) instead, old format might removed.

Create tag dictionary object with contents of specified file and using specified case to determine how to access entries in the tag dictionary.

Parameters:
reader - A reader for the tag dictionary.
caseSensitive - Specifies whether the tag dictionary is case sensitive or not.
Throws:
IOException - when the specified file can not be read.
Method Detail

getTags

public String[] getTags(String word)
Returns a list of valid tags for the specified word.

Specified by:
getTags in interface TagDictionary
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 Iterator<String> iterator()
Retrieves an iterator over all words in the dictionary.

Specified by:
iterator in interface Iterable<String>

serialize

public void serialize(OutputStream out)
               throws IOException
Writes the POSDictionary to the given OutputStream; After the serialization is finished the provided OutputStream remains open.

Parameters:
out - the OutputStream to write the dictionary into.
Throws:
IOException - if writing to the OutputStream fails

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

create

public static POSDictionary create(InputStream in)
                            throws IOException,
                                   InvalidFormatException
Creates a new POSDictionary from a provided InputStream. After creation is finished the provided InputStream is closed.

Parameters:
in -
Returns:
the pos dictionary
Throws:
IOException
InvalidFormatException

put

public String[] put(String word,
                    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 interface MutableTagDictionary
Parameters:
word - word with which the specified tags is to be associated
tags - 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 interface MutableTagDictionary
Returns:
true if the dictionary is case sensitive


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.