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 2011/10/17 15:34:21 UTC

svn commit: r1185161 - /incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java

Author: joern
Date: Mon Oct 17 13:34:21 2011
New Revision: 1185161

URL: http://svn.apache.org/viewvc?rev=1185161&view=rev
Log:
OPENNLP-326 Now multiple paragraph types can be configured.

Modified:
    incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java

Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java?rev=1185161&r1=1185160&r2=1185161&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java Mon Oct 17 13:34:21 2011
@@ -25,8 +25,8 @@ import opennlp.tools.util.Span;
 
 import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
 import org.apache.opennlp.caseditor.namefinder.Entity;
+import org.apache.opennlp.caseditor.util.UIMAUtil;
 import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIndex;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.caseditor.editor.AnnotationEditor;
@@ -100,33 +100,30 @@ public class SentenceContentProvider imp
     
     CAS cas = document.getCAS();
     
-    String paragraphTypeName = store.getString(OpenNLPPreferenceConstants.PARAGRAPH_TYPE);
-
+    String paragraphTypeNames = store.getString(OpenNLPPreferenceConstants.PARAGRAPH_TYPE);
+    Type paragraphTypes[] = UIMAUtil.splitTypes(paragraphTypeNames, ',', cas.getTypeSystem());
+    
     List<Span> paragraphSpans = new ArrayList<Span>();
     
-    if (!paragraphTypeName.isEmpty()) {
-      Type paragraphType = cas.getTypeSystem().getType(paragraphTypeName);
-      
-      if (paragraphType == null) {
-        sentenceDetectorView.setMessage("Paragraph type cannot be found in type system!");
-        return;
-      }
+    if (paragraphTypes != null) {
       
-      FSIndex<AnnotationFS> paragraphAnnotations = cas
-          .getAnnotationIndex(paragraphType);
-      
-      for (Iterator<AnnotationFS> sentenceIterator = paragraphAnnotations
-          .iterator(); sentenceIterator.hasNext();) {
+      for (Iterator<AnnotationFS> sentenceIterator = UIMAUtil.createMultiTypeIterator(cas, paragraphTypes);
+            sentenceIterator.hasNext();) {
 
-        AnnotationFS paragraphAnnotation = (AnnotationFS) sentenceIterator
-            .next();
+        AnnotationFS paragraphAnnotation = sentenceIterator.next();
         
         paragraphSpans.add(
             new Span(paragraphAnnotation.getBegin(), paragraphAnnotation.getEnd()));
       }
     }
     else {
-      paragraphSpans.add(new Span(0, cas.getDocumentText().length()));
+      if (paragraphTypeNames.trim().isEmpty()) {
+        paragraphSpans.add(new Span(0, cas.getDocumentText().length()));
+      }
+      else {
+        sentenceDetectorView.setMessage("A paragraph type cannot be found in the type system!");
+        return;
+      }
     }