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/06 23:27:22 UTC

svn commit: r1179859 - in /incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor: ./ namefinder/

Author: joern
Date: Thu Oct  6 21:27:22 2011
New Revision: 1179859

URL: http://svn.apache.org/viewvc?rev=1179859&view=rev
Log:
OPENNLP-310 Firsts changes to use new preference store. Also added a bit error handling to avoid exception, but further work is needed.

Modified:
    incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java
    incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
    incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
    incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java

Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java?rev=1179859&r1=1179858&r2=1179859&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java Thu Oct  6 21:27:22 2011
@@ -26,7 +26,7 @@ public class OpenNLPPreferencePage exten
     implements IWorkbenchPreferencePage {
 
   public OpenNLPPreferencePage() {
-    setPreferenceStore(OpenNLPPlugin.getDefault().getPreferenceStore());
+//    setPreferenceStore(OpenNLPPlugin.getDefault().getPreferenceStore());
     setDescription("OpenNLP Common Preferences.");  }
   
   @Override

Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java?rev=1179859&r1=1179858&r2=1179859&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java Thu Oct  6 21:27:22 2011
@@ -34,6 +34,7 @@ import org.apache.uima.cas.FSIndex;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.editor.AnnotationEditor;
 import org.apache.uima.caseditor.editor.ICasDocument;
 import org.apache.uima.caseditor.editor.ICasDocumentListener;
 import org.eclipse.core.runtime.IStatus;
@@ -211,17 +212,20 @@ public class EntityContentProvider imple
   
   private ICasDocument input;
   
+  private AnnotationEditor editor;
+  
   // contains all existing entity annotations and is synchronized!
   // needed by name finder to calculate updates ... 
   private List<Entity> knownEntities = new ArrayList<Entity>();
   
   private String nameTypeNames[];
   
-  EntityContentProvider(NameFinderJob nameFinder, TableViewer entityList) {
+  EntityContentProvider(AnnotationEditor editor, NameFinderJob nameFinder, TableViewer entityList) {
     this.nameFinder = nameFinder;
     this.entityListViewer = entityList;
+    this.editor = editor;
     
-    IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
+    IPreferenceStore store = editor.getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput());
     nameTypeNames = store.getString(OpenNLPPreferenceConstants.NAME_TYPE).split(",");
     
     for (int i = 0; i < nameTypeNames.length; i++) {
@@ -321,6 +325,10 @@ public class EntityContentProvider imple
       for (String nameTypeName : nameTypeNames) {
         Type nameType = input.getCAS().getTypeSystem().getType(nameTypeName); 
         
+        // TODO: Do error handling!
+        if (nameType == null)
+          return;
+        
         FSIndex<AnnotationFS> nameAnnotations = input.getCAS()
             .getAnnotationIndex(nameType);
         
@@ -343,15 +351,27 @@ public class EntityContentProvider imple
   }
   
   void runNameFinder() {
-    IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
+    IPreferenceStore store = editor.getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput());
     String sentenceTypeName = store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE);
+    
+    // TODO: Add check for sentence type name
+    if (sentenceTypeName.isEmpty())
+      return;
+    
     String additionalSentenceTypes = store.getString(OpenNLPPreferenceConstants.ADDITIONAL_SENTENCE_TYPE);
-   
+
+    // TODO: Add check for additional sentence type names
+    
     String modelPathes[] = store.getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH).split(",");
     
     for (int i = 0; i < modelPathes.length; i++) {
       modelPathes[i] = modelPathes[i].trim();
+      
+      // TODO: Add checks for model path names
+      if (modelPathes[i].isEmpty())
+        return;
     }
+
     
     CAS cas = input.getCAS();
     

Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java?rev=1179859&r1=1179858&r2=1179859&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java Thu Oct  6 21:27:22 2011
@@ -28,7 +28,7 @@ public class NameFinderPreferencePage ex
     implements IWorkbenchPreferencePage {
 
   public NameFinderPreferencePage() {
-    setPreferenceStore(OpenNLPPlugin.getDefault().getPreferenceStore());
+//    setPreferenceStore();
     setDescription("Name Finder Preferences.");
   }
 

Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java?rev=1179859&r1=1179858&r2=1179859&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java Thu Oct  6 21:27:22 2011
@@ -17,17 +17,25 @@
 
 package org.apache.opennlp.caseditor.namefinder;
 
-import org.apache.opennlp.caseditor.OpenNLPPlugin;
-import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
+import org.apache.opennlp.caseditor.OpenNLPPreferencePage;
 import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.Images;
 import org.apache.uima.caseditor.editor.AnnotationEditor;
 import org.apache.uima.caseditor.editor.ICasDocument;
 import org.apache.uima.caseditor.editor.ICasEditor;
+import org.apache.uima.caseditor.editor.styleview.AnnotationTypeNode;
 import org.apache.uima.caseditor.editor.util.AnnotationSelection;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IStatusLineManager;
+import org.apache.uima.caseditor.ui.property.EditorAnnotationPropertyPage;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceNode;
+import org.eclipse.jface.preference.IPreferencePage;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceManager;
+import org.eclipse.jface.preference.PreferenceNode;
+import org.eclipse.jface.preference.PreferenceStore;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -43,6 +51,8 @@ import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.actions.BaseSelectionListenerAction;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.eclipse.ui.internal.dialogs.PropertyDialog;
 import org.eclipse.ui.part.Page;
 
 
@@ -94,7 +104,7 @@ class NameFinderViewPage extends Page im
     confirmedColumn.setWidth(60);
     
     entityList.setLabelProvider(new EntityLabelProvider());
-    entityList.setContentProvider(new EntityContentProvider(new NameFinderJob(), entityList));
+    entityList.setContentProvider(new EntityContentProvider((AnnotationEditor) editor, new NameFinderJob(), entityList));
     getSite().setSelectionProvider(entityList);
     
     entityList.setComparator(new EntityComperator());
@@ -176,5 +186,46 @@ class NameFinderViewPage extends Page im
     getSite().getSelectionProvider().addSelectionChangedListener(confirmAction); // need also to unregister!!!!
     
     toolBarManager.add(confirmAction);
+    
+    
+    // TODO: Create a preference action
+    // Open a dialog like already done for the annotation styles
+    // Provide the preference store to this dialog
+    // Provide a type system to this preference store
+    
+    IAction action = new Action() {
+      @Override
+      public void run() {
+        super.run();
+        
+        // TODO: Wire this to the type system preference store
+        
+        PreferenceManager mgr = new PreferenceManager();
+        
+        IPreferencePage opennlpPage = new OpenNLPPreferencePage();
+        opennlpPage.setTitle("OpenNLP");
+        mgr.addToRoot(new PreferenceNode("1", opennlpPage));
+        
+        IPreferencePage nameFinderPage = new NameFinderPreferencePage();
+        nameFinderPage.setTitle("Name Finder");
+        mgr.addToRoot(new PreferenceNode("1", nameFinderPage));
+        
+        
+        PropertyDialog dialog = new PropertyDialog(getSite().getShell(), mgr, null);
+        dialog.setPreferenceStore(((AnnotationEditor) editor).
+            getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput()));
+        dialog.create();
+        dialog.setMessage(nameFinderPage.getTitle());
+        dialog.open();
+        
+        // TODO: Need to save ts preferences ... or to announce the change.
+      }
+    };
+    
+    action.setImageDescriptor(CasEditorPlugin
+        .getTaeImageDescriptor(Images.MODEL_PROCESSOR_FOLDER));
+    
+    toolBarManager.add(action);
+    
   }
 }