You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2012/05/23 03:18:56 UTC
svn commit: r1341700 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
Author: colen
Date: Wed May 23 01:18:56 2012
New Revision: 1341700
URL: http://svn.apache.org/viewvc?rev=1341700&view=rev
Log:
OPENNLP-309 The method POSMode.getTagDictionary should return POSDictionary for backward compatibility. The method, now deprecated, will throw an IllegalStateException if the dictionary is not an instance of POSDictionary.
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java?rev=1341700&r1=1341699&r2=1341700&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java Wed May 23 01:18:56 2012
@@ -108,12 +108,32 @@ public final class POSModel extends Base
/**
* Retrieves the tag dictionary.
- *
+ *
* @return tag dictionary or null if not used
+ *
+ * @deprecated Use {@link POSModel#getFactory()} to get a
+ * {@link POSTaggerFactory} and
+ * {@link POSTaggerFactory#getTagDictionary()} to get a
+ * {@link TagDictionary}.
+ *
+ * @throws IllegalStateException
+ * if the TagDictionary is not an instance of POSDictionary
*/
- public TagDictionary getTagDictionary() {
- if(getFactory() != null)
- return getFactory().getTagDictionary();
+ public POSDictionary getTagDictionary() {
+ if (getFactory() != null) {
+ TagDictionary dict = getFactory().getTagDictionary();
+ if (dict != null) {
+ if (dict instanceof POSDictionary) {
+ return (POSDictionary) dict;
+ }
+ String clazz = dict.getClass().getCanonicalName();
+ throw new IllegalStateException("Can not get a dictionary of type "
+ + clazz
+ + " using the deprecated method POSModel.getTagDictionary() "
+ + "because it can only return dictionaries of type POSDictionary. "
+ + "Use POSModel.getFactory().getTagDictionary() instead.");
+ }
+ }
return null;
}