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/09/05 16:48:00 UTC
svn commit: r1165305 -
/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
Author: joern
Date: Mon Sep 5 14:48:00 2011
New Revision: 1165305
URL: http://svn.apache.org/viewvc?rev=1165305&view=rev
Log:
OPENNLP-235 Improved inputChanged implementation, and added some comments.
Modified:
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.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=1165305&r1=1165304&r2=1165305&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 Mon Sep 5 14:48:00 2011
@@ -205,13 +205,12 @@ public class EntityContentProvider imple
if (status.getSeverity() == IStatus.OK) {
- //
List<Entity> newPotentialEntities = EntityContentProvider.this.nameFinder.getNames();
// Remove all potential annotations from list ?! Yes! Note: We should compute a delta here in the future ...
EntityContentProvider.this.entityList.remove(potentialEntities.toArray());
- // Then add like described below:
+ // Then add like described below:
for (Entity newPotentialEntity : newPotentialEntities) {
// A confirmed entity already exists, update its confidence score
@@ -223,7 +222,8 @@ public class EntityContentProvider imple
}
// potential entity should be added!
- // TODO: that is slow and should be done in a bulk update ...
+ // TODO: that is slow and should be done in a bulk update ... to do so remember all
+ // and do a bulk update after the for loop
EntityContentProvider.this.entityList.add(newPotentialEntity);
}
@@ -237,42 +237,43 @@ public class EntityContentProvider imple
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ // Problem: "The viewer should not be updated during this call, as it might be in
+ // the process of being disposed." (Javadoc)
+ // Does it mean that the name finder listener must check if the viewer is still alive?
+
+ if (oldInput != null) {
+ ICasDocument oldDocument = (ICasDocument) oldInput;
+ oldDocument.removeChangeListener(casChangeListener);
+ oldDocument.removeChangeListener(nameFinderTrigger);
+ }
- IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
- String nameTypeName = store.getString(OpenNLPPreferenceConstants.NAME_TYPE);
-
- if (input != newInput) {
+ if (newInput != null) {
+ IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
+ String nameTypeName = store.getString(OpenNLPPreferenceConstants.NAME_TYPE);
input = (ICasDocument) newInput;
- if (oldInput != null && oldInput != newInput) {
-
- ICasDocument oldDocument = (ICasDocument) oldInput;
- oldDocument.removeChangeListener(casChangeListener);
- oldDocument.removeChangeListener(nameFinderTrigger);
- }
+ // Note: Name Finder might run to often ...
+ input.addChangeListener(casChangeListener);
+ input.addChangeListener(nameFinderTrigger);
- if (newInput != null) {
- // Note: Name Finder might run to often ...
- input.addChangeListener(casChangeListener);
- input.addChangeListener(nameFinderTrigger);
-
- // Create initial list of confirmed entities ...
- Type nameType = input.getCAS().getTypeSystem().getType(nameTypeName);
+ // Create initial list of confirmed entities ...
+ Type nameType = input.getCAS().getTypeSystem().getType(nameTypeName);
+
+ FSIndex<AnnotationFS> nameAnnotations = input.getCAS()
+ .getAnnotationIndex(nameType);
+
+ for (Iterator<AnnotationFS> nameIterator = nameAnnotations
+ .iterator(); nameIterator.hasNext();) {
- FSIndex<AnnotationFS> nameAnnotations = input.getCAS()
- .getAnnotationIndex(nameType);
-
- for (Iterator<AnnotationFS> nameIterator = nameAnnotations
- .iterator(); nameIterator.hasNext();) {
-
- AnnotationFS nameAnnotation = (AnnotationFS) nameIterator.next();
-
- confirmedEntities.add(new Entity(nameAnnotation.getBegin(), nameAnnotation.getEnd(), nameAnnotation.getCoveredText(), null, true));
- }
+ AnnotationFS nameAnnotation = (AnnotationFS) nameIterator.next();
- runNameFinder();
+ confirmedEntities.add(new Entity(nameAnnotation.getBegin(),
+ nameAnnotation.getEnd(), nameAnnotation.getCoveredText(), null, true));
}
+
+ runNameFinder();
}
}
@@ -280,6 +281,7 @@ public class EntityContentProvider imple
IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
String sentenceTypeName = store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE);
String nameTypeName = store.getString(OpenNLPPreferenceConstants.NAME_TYPE);
+ String modelPath = store.getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH);
CAS cas = input.getCAS();
@@ -291,8 +293,7 @@ public class EntityContentProvider imple
if (text != null) {
- // get list of sentence annotations
- // get list of token annotations
+ // TODO: get list of token annotations
List<Span> sentences = new ArrayList<Span>();
List<Span> tokens = new ArrayList<Span>();
@@ -322,6 +323,8 @@ public class EntityContentProvider imple
}
}
+ // Note: When an annotation is removed, it might still be in the cas ...
+
List<Span> nameSpans = new ArrayList<Span>();
Type nameType = cas.getTypeSystem().getType(nameTypeName);
@@ -342,6 +345,7 @@ public class EntityContentProvider imple
nameFinder.setSentences(sentences.toArray(new Span[sentences.size()]));
nameFinder.setTokens(tokens.toArray(new Span[tokens.size()]));
nameFinder.setVerifiedNames(nameSpans.toArray(new Span[nameSpans.size()]));
+ nameFinder.setModelPath(modelPath);
nameFinder.schedule();
}