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/07/19 23:28:27 UTC
svn commit: r1148546 -
/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
Author: joern
Date: Tue Jul 19 21:28:27 2011
New Revision: 1148546
URL: http://svn.apache.org/viewvc?rev=1148546&view=rev
Log:
OPENNLP-235 Added confirm action. Right now only creates an annotation.
Modified:
incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
Modified: incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java?rev=1148546&r1=1148545&r2=1148546&view=diff
==============================================================================
--- incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java (original)
+++ incubator/opennlp/sandbox/opennlp-caseditor-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java Tue Jul 19 21:28:27 2011
@@ -17,9 +17,17 @@
package org.apache.opennlp.caseditor.namefinder;
+import org.apache.opennlp.caseditor.OpenNLPPlugin;
+import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
+import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.caseditor.editor.ICasDocument;
import org.apache.uima.caseditor.editor.ICasEditor;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
@@ -29,16 +37,28 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.part.Page;
+
+// TODO: Selected entities should be highlighted in the annotation editor!
+// How can that be done? Should we simply create feature structures, which are not added to the index!?
+
+// TODO: There should be a way to display error messages in this view, e.g.
+// when no names are detected. -> give an indication what could be wrong!
class NameFinderViewPage extends Page implements ISelectionListener {
private ICasEditor editor;
private TableViewer entityList;
+
+ private String nameTypeName;
NameFinderViewPage(ICasEditor editor, ICasDocument document) {
this.editor = editor;
+
+ IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
+ nameTypeName = store.getString(OpenNLPPreferenceConstants.NAME_TYPE);
}
public void createControl(Composite parent) {
@@ -67,6 +87,8 @@ class NameFinderViewPage extends Page im
entityList.setContentProvider(new EntityContentProvider(new NameFinderJob(), entityList));
getSite().setSelectionProvider(entityList);
+ // TODO: Do we need a sorter here?!
+
entityList.setInput(editor.getDocument());
}
@@ -80,4 +102,56 @@ class NameFinderViewPage extends Page im
public void setFocus() {
entityList.getControl().setFocus();
}
+
+ public void makeContributions(IMenuManager menuManager,
+ IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
+ super.makeContributions(menuManager, toolBarManager, statusLineManager);
+
+ // TODO: Action is missing keyboard shortcut
+ BaseSelectionListenerAction confirmAction = new BaseSelectionListenerAction("Confirm") {
+
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection) {
+
+ boolean result = false;
+
+ if (!selection.isEmpty()) {
+ Entity entity = (Entity) selection.getFirstElement();
+ return !entity.isConfirmed();
+ }
+
+ return result;
+ }
+
+ // Note: Action can only handle one element.
+ // Must be extended to handle "bulk" confirms
+ @Override
+ public void run() {
+ super.run();
+
+ // get selected entities and add annotations to the CAS
+ IStructuredSelection selection =
+ (IStructuredSelection) entityList.getSelection();
+
+ Object elements[] = selection.toArray();
+
+ if (elements.length > 0) {
+ Entity selectedEntity = (Entity) elements[0];
+ if (!selectedEntity.isConfirmed()) {
+ ICasDocument document = editor.getDocument();
+
+ FeatureStructure nameAnnotation = document.getCAS().createAnnotation(
+ document.getCAS().getTypeSystem().getType(nameTypeName),
+ selectedEntity.getBeginIndex(), selectedEntity.getEndIndex());
+ document.getCAS().addFsToIndexes(nameAnnotation);
+ document.addFeatureStructure(nameAnnotation);
+ }
+ }
+ }
+ };
+
+ getSite().getSelectionProvider().addSelectionChangedListener(confirmAction); // need also to unregister!!!!
+
+ toolBarManager.add(confirmAction);
+ }
}