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/08 21:52:57 UTC

svn commit: r1335722 - in /opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag: MutableTagDictionary.java POSDictionary.java

Author: colen
Date: Tue May  8 19:52:57 2012
New Revision: 1335722

URL: http://svn.apache.org/viewvc?rev=1335722&view=rev
Log:
OPENNLP-508 Added MutableTagDictionary interface and modified POSDictionary to implement it.

Added:
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java   (with props)
Modified:
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java

Added: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java?rev=1335722&view=auto
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java (added)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java Tue May  8 19:52:57 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreemnets.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package opennlp.tools.postag;
+
+/**
+ * Interface that allows {@link TagDictionary} entries to be added and removed.
+ * This can be used to induce the dictionary from training data.
+ */
+public interface MutableTagDictionary extends TagDictionary {
+
+  /**
+   * 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.
+   * 
+   * @param word
+   *          word with which the specified tags is to be associated
+   * @param tags
+   *          tags to be associated with the specified word
+   * 
+   * @return the previous tags associated with the word, or null if there was no
+   *         mapping for word.
+   */
+  public String[] put(String word, String... tags);
+
+  /**
+   * Whether if the dictionary is case sensitive or not
+   * 
+   * @return true if the dictionary is case sensitive
+   */
+  // TODO: move to TagDictionary, can't do it now because of backward
+  // compatibility.
+  public boolean isCaseSensitive();
+
+}

Propchange: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java?rev=1335722&r1=1335721&r2=1335722&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java Tue May  8 19:52:57 2012
@@ -42,7 +42,7 @@ import opennlp.tools.util.StringUtil;
  * Provides a means of determining which tags are valid for a particular word
  * based on a tag dictionary read from a file.
  */
-public class POSDictionary implements Iterable<String>, TagDictionary {
+public class POSDictionary implements Iterable<String>, MutableTagDictionary {
 
   private Map<String, String[]> dictionary;
 
@@ -158,13 +158,19 @@ public class POSDictionary implements It
   }
 
   /**
-   * Adds the tags for the word.
-   *
-   * @param word The word to be added to the dictionary.
-   * @param tags The set of tags associated with the specified word.
+   * Associates the specified tags with the specified word. If the dictionary
+   * previously contained the word, the old tags are replaced by the specified
+   * ones.
+   * 
+   * @param word
+   *          The word to be added to the dictionary.
+   * @param tags
+   *          The set of tags associated with the specified word.
+   * 
+   * @deprecated Use {@link #put(String, String[])} instead
    */
   void addTags(String word, String... tags) {
-    dictionary.put(word, tags);
+    put(word, tags);
   }
 
   /**
@@ -314,4 +320,16 @@ public class POSDictionary implements It
     
     return newPosDict;
   }
+
+  public String[] put(String word, String... tags) {
+    if (this.caseSensitive) {
+      return dictionary.put(word, tags);
+    } else {
+      return dictionary.put(word.toLowerCase(), tags);
+    }
+  }
+
+  public boolean isCaseSensitive() {
+    return this.caseSensitive;
+  }
 }