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 2013/05/17 14:16:34 UTC
svn commit: r1483762 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
Author: joern
Date: Fri May 17 12:16:33 2013
New Revision: 1483762
URL: http://svn.apache.org/r1483762
Log:
OPENNLP-560 Initial check in of brat format parsing code for the name finder.
Added:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java (with props)
Added: 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=1483762&view=auto
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java (added)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java Fri May 17 12:16:33 2013
@@ -0,0 +1,65 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import opennlp.tools.util.Span;
+
+/**
+ * The Newline Sentence Detector assumes that sentences are line delimited and
+ * recognizes one sentence per non-empty line.
+ */
+public class NewlineSentenceDetector implements SentenceDetector {
+
+ public String[] sentDetect(String s) {
+ return Span.spansToStrings(sentPosDetect(s), s);
+ }
+
+ public Span[] sentPosDetect(String s) {
+
+ List<Span> sentences = new ArrayList<Span>();
+
+ int start = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+
+ if (c == '\n' || c == '\r') {
+ if (start - i > 0) {
+ Span span = new Span(start, i).trim(s);
+ if (span.length() > 0) {
+ sentences.add(span);
+ }
+
+ start = i + 1;
+ }
+ }
+ }
+
+ if (s.length() - start > 0) {
+ Span span = new Span(start, s.length()).trim(s);
+ if (span.length() > 0) {
+ sentences.add(span);
+ }
+ }
+
+ return sentences.toArray(new Span[sentences.size()]);
+ }
+}
Propchange: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain