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/13 13:15:02 UTC

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

Author: joern
Date: Thu Oct 13 11:15:02 2011
New Revision: 1182783

URL: http://svn.apache.org/viewvc?rev=1182783&view=rev
Log:
OPENNLP-315 Now reports an error if sentence annotation is invalid.

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=1182783&r1=1182782&r2=1182783&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 Thu Oct 13 11:15:02 2011
@@ -23,7 +23,6 @@ import java.util.List;
 
 import opennlp.tools.util.Span;
 
-import org.apache.opennlp.caseditor.OpenNLPPlugin;
 import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
 import org.apache.opennlp.caseditor.namefinder.Entity;
 import org.apache.uima.cas.CAS;
@@ -52,8 +51,6 @@ public class SentenceContentProvider imp
   
   private TableViewer sentenceList;
 
-
-  
   public SentenceContentProvider(SentenceDetectorViewPage sentenceDetectorView, AnnotationEditor editor,
       SentenceDetectorJob sentenceDetector, TableViewer sentenceList) {
     this.sentenceDetectorView = sentenceDetectorView;
@@ -101,15 +98,19 @@ public class SentenceContentProvider imp
   void triggerSentenceDetector() {
     IPreferenceStore store = editor.getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput());
     
-    String paragraphTypeName = store.getString(OpenNLPPreferenceConstants.PARAGRAPH_TYPE);
-    
     CAS cas = document.getCAS();
     
+    String paragraphTypeName = store.getString(OpenNLPPreferenceConstants.PARAGRAPH_TYPE);
+
     List<Span> paragraphSpans = new ArrayList<Span>();
     
-    Type paragraphType = cas.getTypeSystem().getType(paragraphTypeName); 
-    
-    if (paragraphType != null) {
+    if (!paragraphTypeName.isEmpty()) {
+      Type paragraphType = cas.getTypeSystem().getType(paragraphTypeName);
+      
+      if (paragraphType == null) {
+        sentenceDetectorView.setMessage("Paragraph type cannot be found in type system!");
+        return;
+      }
       
       FSIndex<AnnotationFS> paragraphAnnotations = cas
           .getAnnotationIndex(paragraphType);
@@ -128,15 +129,28 @@ public class SentenceContentProvider imp
       paragraphSpans.add(new Span(0, cas.getDocumentText().length()));
     }
     
+    
     String modelPath = store.getString(OpenNLPPreferenceConstants.SENTENCE_DETECTOR_MODEL_PATH);
     
     sentenceDetector.setModelPath(modelPath);
     sentenceDetector.setParagraphs(paragraphSpans);
     sentenceDetector.setText(document.getCAS().getDocumentText());
     
-    // TODO: Check if sentence type is valid and set!
+    String sentenceTypeName = store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE);
+    
+    if (sentenceTypeName.isEmpty()) {
+      sentenceDetectorView.setMessage("Sentence type name is not set!");
+      return;
+    }
+      
+    Type sentenceType = cas.getTypeSystem().getType(sentenceTypeName);
+    
+    if (sentenceType == null) {
+      sentenceDetectorView.setMessage("Type system does not contain sentence type!");
+      return;
+    }
     
-    sentenceDetector.setSentenceType(store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE));
+    sentenceDetector.setSentenceType(sentenceType.getName());
     
     sentenceDetector.schedule();
   }