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/10 01:48:53 UTC
svn commit: r1180746 - in
/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder:
EntityContentProvider.java NameFinderViewPage.java
Author: joern
Date: Sun Oct 9 23:48:53 2011
New Revision: 1180746
URL: http://svn.apache.org/viewvc?rev=1180746&view=rev
Log:
OPENNLP-312 Confirmed entities are now directly removed from the list of new potential entities.
Modified:
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/NameFinderViewPage.java
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=1180746&r1=1180745&r2=1180746&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 Sun Oct 9 23:48:53 2011
@@ -117,9 +117,13 @@ public class EntityContentProvider imple
// TODO: Check that type matches ...
AnnotationFS annotation = (AnnotationFS) fs;
- List<Entity> entityList = searchEntities(EntityContentProvider.this.knownEntities,
+ List<Entity> entityList = searchEntities(EntityContentProvider.this.candidateEntities,
annotation.getBegin(), annotation.getEnd());
+ // Remove all entities from the view and candidate list
+ // TODO: Refactor this code branch ...
+ // Now it only needs to remove all intersecting entites from the
+ // candidate list and add the entity itself to the confirmed list
if (!entityList.isEmpty()) {
Entity entity = entityList.get(0);
entity.setBeginIndex(annotation.getBegin());
@@ -129,15 +133,18 @@ public class EntityContentProvider imple
entity.setLinkedAnnotation(annotation);
entity.setConfidence(null);
- EntityContentProvider.this.entityListViewer.refresh(entity);
+ EntityContentProvider.this.entityListViewer.remove(entity);
+ EntityContentProvider.this.candidateEntities.remove(entity);
+ EntityContentProvider.this.confirmedEntities.add(entity);
+
// Delete all other entities which match
for (int i = 1; i < entityList.size(); i++) {
Entity removeEntity = entityList.get(i);
if (!removeEntity.isConfirmed()) {
EntityContentProvider.this.entityListViewer.remove(removeEntity);
- EntityContentProvider.this.knownEntities.remove(removeEntity);
+ EntityContentProvider.this.candidateEntities.remove(removeEntity);
}
}
}
@@ -145,8 +152,7 @@ public class EntityContentProvider imple
Entity newEntity = new Entity(annotation.getBegin(), annotation.getEnd(),
annotation.getCoveredText(), null, true, annotation.getType().getName());
- EntityContentProvider.this.entityListViewer.add(newEntity);
- EntityContentProvider.this.knownEntities.add(newEntity);
+ EntityContentProvider.this.confirmedEntities.add(newEntity);
}
}
}
@@ -169,17 +175,13 @@ public class EntityContentProvider imple
if (fs instanceof AnnotationFS && contains(nameTypeNames, fs.getType().getName())) {
AnnotationFS annotation = (AnnotationFS) fs;
- Entity confirmedEntity = searchEntity(EntityContentProvider.this.knownEntities,
+ Entity confirmedEntity = searchEntity(EntityContentProvider.this.confirmedEntities,
annotation.getBegin(), annotation.getEnd(), annotation.getType().getName());
if (confirmedEntity != null) {
- EntityContentProvider.this.knownEntities.remove(confirmedEntity);
- EntityContentProvider.this.entityListViewer.remove(confirmedEntity);
+ EntityContentProvider.this.confirmedEntities.remove(confirmedEntity);
}
}
-
- // TODO: Eventually add it to a black list, so tokens in this
- // area cannot be detected as a name
}
@Override
@@ -216,7 +218,8 @@ public class EntityContentProvider imple
// contains all existing entity annotations and is synchronized!
// needed by name finder to calculate updates ...
- private List<Entity> knownEntities = new ArrayList<Entity>();
+ private List<Entity> candidateEntities = new ArrayList<Entity>();
+ private List<Entity> confirmedEntities = new ArrayList<Entity>();
private String nameTypeNames[];
@@ -246,7 +249,7 @@ public class EntityContentProvider imple
List<Entity> detectedEntities = EntityContentProvider.this.nameFinder.getNames();
// Remove all detected entities from the last run which are not detected anymore
- for (Iterator<Entity> it = knownEntities.iterator(); it.hasNext();) {
+ for (Iterator<Entity> it = candidateEntities.iterator(); it.hasNext();) {
Entity entity = it.next();
if (searchEntity(detectedEntities, entity.getBeginIndex(),
entity.getEndIndex(), entity.getType()) == null) {
@@ -268,7 +271,7 @@ public class EntityContentProvider imple
// Case: One entity spanning two tokens replaces
- Entity entity = searchEntity(knownEntities, detectedEntity.getBeginIndex(),
+ Entity entity = searchEntity(candidateEntities, detectedEntity.getBeginIndex(),
detectedEntity.getEndIndex(), detectedEntity.getType());
// A confirmed entity already exists, update its confidence score
@@ -288,8 +291,12 @@ public class EntityContentProvider imple
}
}
else {
- EntityContentProvider.this.entityListViewer.add(detectedEntity);
- knownEntities.add(detectedEntity);
+ // Only add if it is not a confirmed entity!
+ if (searchEntity(confirmedEntities, detectedEntity.getBeginIndex(),
+ detectedEntity.getEndIndex(), detectedEntity.getType()) == null) {
+ EntityContentProvider.this.entityListViewer.add(detectedEntity);
+ candidateEntities.add(detectedEntity);
+ }
}
}
}
@@ -342,7 +349,7 @@ public class EntityContentProvider imple
nameAnnotation.getEnd(), nameAnnotation.getCoveredText(), null, true,
nameAnnotation.getType().getName());
entity.setLinkedAnnotation(nameAnnotation);
- knownEntities.add(entity);
+ confirmedEntities.add(entity); // TODO: This needs to go into a second list!
}
}
@@ -460,7 +467,7 @@ public class EntityContentProvider imple
// Called directly after showing the view, the
// name finder is triggered to produce names
// which will be added to the viewer
- return knownEntities.toArray();
+ return candidateEntities.toArray();
}
public void dispose() {
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=1180746&r1=1180745&r2=1180746&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 Sun Oct 9 23:48:53 2011
@@ -17,7 +17,6 @@
package org.apache.opennlp.caseditor.namefinder;
-import org.apache.opennlp.caseditor.OpenNLPPreferencePage;
import org.apache.opennlp.caseditor.OpenPreferenceDialog;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.caseditor.CasEditorPlugin;
@@ -25,18 +24,9 @@ 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.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;
@@ -52,8 +42,6 @@ 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;
@@ -99,11 +87,6 @@ class NameFinderViewPage extends Page im
typeColumn.setText("Type");
typeColumn.setWidth(40);
- TableViewerColumn confirmedViewerColumn = new TableViewerColumn(entityList, SWT.NONE);
- TableColumn confirmedColumn = confirmedViewerColumn.getColumn();
- confirmedColumn.setText("Confirmed");
- confirmedColumn.setWidth(60);
-
entityList.setLabelProvider(new EntityLabelProvider());
entityList.setContentProvider(new EntityContentProvider((AnnotationEditor) editor, new NameFinderJob(), entityList));
getSite().setSelectionProvider(entityList);