You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2015/07/29 10:26:02 UTC

svn commit: r1693208 - in /opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java

Author: joern
Date: Wed Jul 29 08:26:01 2015
New Revision: 1693208

URL: http://svn.apache.org/r1693208
Log:
OPENNLP-799 

The NewlineSentenceDetector does not work because of a small comparison error.
The patch fixes the problem, and also adds a class with some tests.

Thanks to Gustavo Knuppe for providing a patch.

Added:
    opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java   (with props)
Modified:
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java?rev=1693208&r1=1693207&r2=1693208&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java Wed Jul 29 08:26:01 2015
@@ -42,7 +42,7 @@ public class NewlineSentenceDetector imp
       char c = s.charAt(i);
 
       if (c == '\n' || c == '\r') {
-        if (start - i > 0) {
+        if (i - start > 0) {
           Span span = new Span(start, i).trim(s);
           if (span.length() > 0) {
             sentences.add(span);

Added: opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java?rev=1693208&view=auto
==============================================================================
--- opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java (added)
+++ opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java Wed Jul 29 08:26:01 2015
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.sentdetect;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the {@link NewlineSentenceDetector} class.
+ */
+public class NewlineSentenceDetectorTest {
+
+
+  private static void testSentenceValues(String sentences){
+    NewlineSentenceDetector sd = new NewlineSentenceDetector();
+
+    String results[] = sd.sentDetect(sentences);
+
+    assertEquals(3, results.length);
+    assertEquals("one.", results[0]);
+    assertEquals("two.", results[1]);
+    assertEquals("three.", results[2]);
+  }
+
+  @Test
+  public void testNewlineCr() {
+    testSentenceValues("one.\rtwo. \r\r three.\r");
+  }
+
+  @Test
+  public void testNewlineLf() {
+    testSentenceValues("one.\ntwo. \n\n three.\n");
+  }
+
+  @Test
+  public void testNewlineCrLf() {
+    testSentenceValues("one.\r\ntwo. \r\n\r\n three.\r\n");
+  }
+}

Propchange: opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/sentdetect/NewlineSentenceDetectorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain