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/02/10 11:46:02 UTC

svn commit: r1242732 - in /incubator/opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/postag/POSDictionary.java test/java/opennlp/tools/postag/POSDictionaryTest.java

Author: colen
Date: Fri Feb 10 10:46:02 2012
New Revision: 1242732

URL: http://svn.apache.org/viewvc?rev=1242732&view=rev
Log:
OPENNLP-431: Changed the toString method to output something meaningful

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
    incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSDictionaryTest.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java?rev=1242732&r1=1242731&r2=1242732&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java Fri Feb 10 10:46:02 2012
@@ -260,25 +260,12 @@ public class POSDictionary implements It
 
   @Override
   public String toString() {
-    StringBuilder dictionaryString = new StringBuilder();
+    // it is time consuming to output the dictionary entries.
+    // will output something meaningful for debugging, like
+    // POSDictionary{size=100, caseSensitive=true}
 
-    int count = 0;
-    for (String word : dictionary.keySet()) {
-      dictionaryString.append(word).append(" -> ").append(tagsToString(getTags(word)));
-      dictionaryString.append("\n");
-      if (count++ > 3) {
-        // lets stop now because it takes a lot of time if we are working
-        // with a big dictionary
-        break;
-      }
-    }
-
-    // remove last new line
-    if (dictionaryString.length() > 0) {
-      dictionaryString.setLength(dictionaryString.length() -1);
-    }
-
-    return dictionaryString.toString();
+    return "POSDictionary{size=" + dictionary.size() + ", caseSensitive="
+        + this.caseSensitive + "}";
   }
 
   /**

Modified: incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSDictionaryTest.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSDictionaryTest.java?rev=1242732&r1=1242731&r2=1242732&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSDictionaryTest.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSDictionaryTest.java Fri Feb 10 10:46:02 2012
@@ -107,4 +107,12 @@ public class POSDictionaryTest {
     assertArrayEquals(new String[]{"NNP"}, dict.getTags("McKinsey"));
     assertArrayEquals(new String[]{"NNP"}, dict.getTags("Mckinsey"));
   }
+  
+  @Test
+  public void testToString() throws IOException {
+    POSDictionary dict = loadDictionary("TagDictionaryCaseInsensitive.xml");
+    assertEquals("POSDictionary{size=1, caseSensitive=false}", dict.toString());
+    dict = loadDictionary("TagDictionaryCaseSensitive.xml");
+    assertEquals("POSDictionary{size=1, caseSensitive=true}", dict.toString());
+  }
 }
\ No newline at end of file