You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2023/01/20 15:18:47 UTC
[opennlp-sandbox] 01/01: updates sandbox component 'caseditor-opennlp-plugin' to be compatible with latest opennlp-tools release
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch migrate-caseditor-opennlp-plugin-to-opennlp-tools-2_1_0
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git
commit d124c5295c4fbeabf1d7a23ce610fa16d39a2409
Author: Martin Wiesner <ma...@hs-heilbronn.de>
AuthorDate: Fri Jan 20 16:18:38 2023 +0100
updates sandbox component 'caseditor-opennlp-plugin' to be compatible with latest opennlp-tools release
- adjusts opennlp-tools to 2.1.0
- adjusts parent project (org.apache.apache) to version 18
- adjusts Java language level to 11
- updates `uimaj` dependencies to version 2.10.4
- updates `maven-bundle-plugin` to version 5.1.8 so things work with class files compiled in Java 11 format
- adjusts some array declarations to comply with Java, not C style
- removes unused imports
---
caseditor-opennlp-plugin/pom.xml | 97 ++++++-------
.../opennlp/caseditor/ConfirmAnnotationAction.java | 6 +-
.../caseditor/OpenNLPPreferenceInitializer.java | 1 +
.../opennlp/caseditor/OpenNLPPreferencePage.java | 2 +-
.../opennlp/caseditor/OpenPreferenceDialog.java | 8 +-
.../opennlp/caseditor/PotentialAnnotation.java | 2 +-
...tor.java => PotentialAnnotationComparator.java} | 4 +-
.../apache/opennlp/caseditor/TypeFieldEditor.java | 2 +-
.../apache/opennlp/caseditor/TypeInputDialog.java | 2 +-
.../opennlp/caseditor/TypeListFieldEditor.java | 57 +++-----
.../ConfirmedNameDetectionFieldEditor.java | 8 +-
.../namefinder/EntityContentProvider.java | 60 ++++----
.../caseditor/namefinder/MultiModelNameFinder.java | 35 ++---
.../caseditor/namefinder/NameFinderJob.java | 64 ++++-----
.../namefinder/NameFinderModelFieldEditor.java | 79 ++++------
.../namefinder/NameFinderModelInputDialog.java | 19 +--
.../namefinder/NameFinderPreferencePage.java | 4 +-
.../caseditor/namefinder/NameFinderViewPage.java | 10 +-
.../PotentialEntityAnnotationLabelProvider.java | 12 +-
.../sentdetect/SentenceContentProvider.java | 160 ++++++++++-----------
.../caseditor/sentdetect/SentenceDetectorJob.java | 30 ++--
.../sentdetect/SentenceDetectorPreferencePage.java | 2 +-
.../sentdetect/SentenceDetectorViewPage.java | 42 +++---
.../sentdetect/SentenceLabelProvider.java | 10 +-
.../opennlp/caseditor/tokenize/TokenizerJob.java | 37 ++---
.../tokenize/TokenizerPreferencePage.java | 2 +-
.../opennlp/caseditor/tokenize/TokenizerView.java | 1 +
.../caseditor/tokenize/TokenizerViewPage.java | 10 +-
.../caseditor/util/ContainingConstraint.java | 19 +--
.../apache/opennlp/caseditor/util/UIMAUtil.java | 10 +-
30 files changed, 340 insertions(+), 455 deletions(-)
diff --git a/caseditor-opennlp-plugin/pom.xml b/caseditor-opennlp-plugin/pom.xml
index ff12a1b..23900e2 100644
--- a/caseditor-opennlp-plugin/pom.xml
+++ b/caseditor-opennlp-plugin/pom.xml
@@ -20,51 +20,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
- <version>9</version>
+ <!-- TODO OPENNLP-1452 once this is resolved, move to 29 as well. -->
+ <version>18</version>
<relativePath />
</parent>
<groupId>org.apache.opennlp</groupId>
-
- <artifactId>opennlp-caseditor</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <artifactId>caseditor-opennlp-plugin</artifactId>
+ <version>2.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
- <name>OpenNLP CasEditor Plugin</name>
-
+ <name>Apache OpenNLP CaseEditor Plugin</name>
+
<repositories>
- <repository>
- <id>eclipsePlugins</id>
- <name>Eclipse components</name>
- <layout>default</layout>
- <url>http://repo1.maven.org/eclipse</url>
-
- <releases>
- <updatePolicy>never</updatePolicy>
- <checksumPolicy>fail</checksumPolicy>
- </releases>
-
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
-
+ <repository>
+ <id>eclipsePlugins</id>
+ <name>Eclipse components</name>
+ <layout>default</layout>
+ <url>https://repo.eclipse.org</url>
+
+ <releases>
+ <updatePolicy>never</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </releases>
+
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
<dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.5</version>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
- <version>1.5.2-incubating</version>
+ <version>2.1.0</version>
</dependency>
<!-- UIMA dependencies -->
@@ -72,21 +64,21 @@
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-core</artifactId>
- <version>2.4.0</version>
+ <version>2.10.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-tools</artifactId>
- <version>2.4.0</version>
+ <version>2.10.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-ep-cas-editor</artifactId>
- <version>2.4.0</version>
+ <version>2.10.4</version>
<scope>compile</scope>
</dependency>
@@ -114,20 +106,11 @@
</dependency>
<dependency>
- <groupId>org.eclipse.swt</groupId>
- <artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
- <!-- changing the lower version number to 3.2.0, was 3.3.0 because only
- 3.2.0 and 3.2.1 are in repo -->
- <version>[3.2.0.0,4.0.0)</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- dependency>
- <groupId>org.eclipse.ui</groupId>
- <artifactId>ide</artifactId>
+ <groupId>org.eclipse.swt.win32.win32</groupId>
+ <artifactId>x86</artifactId>
<version>[3.3.0.0,4.0.0)</version>
<scope>provided</scope>
- </dependency -->
+ </dependency>
<dependency>
<groupId>org.eclipse.ui</groupId>
@@ -151,12 +134,19 @@
<version>[3.3.0.0,4.0.0)</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.13.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<!-- don't use artifactId as first part of finalName, follow instead the
eclipse convention -->
- <finalName>org.apache.opennlp.caseditor_0.0.1</finalName>
+ <finalName>org.apache.opennlp.caseditor_2.1.1</finalName>
<resources>
<resource>
<directory>.</directory>
@@ -175,8 +165,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>11</source>
+ <target>11</target>
+ <compilerArgument>-Xlint</compilerArgument>
</configuration>
</plugin>
<plugin>
@@ -190,10 +181,11 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
+ <version>5.1.8</version>
<executions>
<execution>
- <goals><goal>manifest</goal></goals>
- <phase>process-classes</phase>
+ <goals><goal>manifest</goal></goals>
+ <phase>process-classes</phase>
<configuration>
<manifestLocation>META-INF/</manifestLocation>
<instructions>
@@ -213,7 +205,6 @@
org.eclipse.ui.workbench,
org.eclipse.core.runtime,
org.eclipse.core.resources,
- org.junit4;bundle-version="4.5.0";resolution:=optional
</Require-Bundle>
<Import-Package>
!org.eclipse.jface.text,
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ConfirmAnnotationAction.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ConfirmAnnotationAction.java
index afbd2a5..3259d5a 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ConfirmAnnotationAction.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/ConfirmAnnotationAction.java
@@ -25,9 +25,9 @@ import org.eclipse.ui.actions.BaseSelectionListenerAction;
public class ConfirmAnnotationAction extends BaseSelectionListenerAction {
- private TableViewer entityList;
+ private final TableViewer entityList;
- private ICasEditor editor;
+ private final ICasEditor editor;
public ConfirmAnnotationAction(TableViewer entityList, ICasEditor editor) {
super("Confirm");
@@ -54,7 +54,7 @@ public class ConfirmAnnotationAction extends BaseSelectionListenerAction {
IStructuredSelection selection =
(IStructuredSelection) entityList.getSelection();
- Object elements[] = selection.toArray();
+ Object[] elements = selection.toArray();
if (elements.length > 0) {
PotentialAnnotation selectedEntity = (PotentialAnnotation) elements[0];
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceInitializer.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceInitializer.java
index 9bde2a5..9c485ec 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceInitializer.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceInitializer.java
@@ -22,6 +22,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
public class OpenNLPPreferenceInitializer extends AbstractPreferenceInitializer {
+ @Override
public void initializeDefaultPreferences() {
IPreferenceStore store = OpenNLPPlugin.getDefault().getPreferenceStore();
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java
index 5f458cc..d299b1b 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferencePage.java
@@ -25,7 +25,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class OpenNLPPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
- private TypeSystem ts;
+ private final TypeSystem ts;
public OpenNLPPreferencePage(TypeSystem ts) {
this.ts = ts;
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenPreferenceDialog.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenPreferenceDialog.java
index 39f152d..db18273 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenPreferenceDialog.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenPreferenceDialog.java
@@ -31,8 +31,8 @@ import org.eclipse.ui.internal.dialogs.PropertyDialog;
public class OpenPreferenceDialog extends Action {
- private Shell shell;
- private AnnotationEditor editor;
+ private final Shell shell;
+ private final AnnotationEditor editor;
public OpenPreferenceDialog(Shell shell, ICasEditor editor) {
this.shell = shell;
@@ -65,8 +65,8 @@ public class OpenPreferenceDialog extends Action {
mgr.addToRoot(new PreferenceNode("1", nameFinderPage));
PropertyDialog dialog = new PropertyDialog(shell, mgr, null);
- dialog.setPreferenceStore(((AnnotationEditor) editor).
- getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput()));
+ dialog.setPreferenceStore(( editor).getCasDocumentProvider().
+ getTypeSystemPreferenceStore(editor.getEditorInput()));
dialog.create();
dialog.setMessage(nameFinderPage.getTitle());
dialog.open();
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotation.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotation.java
index 6156f3a..c640e49 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotation.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotation.java
@@ -30,7 +30,7 @@ public class PotentialAnnotation {
private Double confidence;
- private String type;
+ private final String type;
public PotentialAnnotation(int beginIndex, int endIndex, String entityText,
Double confidence, String type) {
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComperator.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComparator.java
similarity index 92%
rename from caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComperator.java
rename to caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComparator.java
index b43ee19..30bdba3 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComperator.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/PotentialAnnotationComparator.java
@@ -22,10 +22,10 @@ import org.eclipse.jface.viewers.ViewerComparator;
/**
* Compares two entities. Entities which have a smaller begin index are ordered first.
- * If entities have an identical begin index the one with the higher confidence score
+ * If entities have an identical start index the one with the higher confidence score
* is ordered first.
*/
-public class PotentialAnnotationComperator extends ViewerComparator {
+public class PotentialAnnotationComparator extends ViewerComparator {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeFieldEditor.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeFieldEditor.java
index 33936bd..2c44c9b 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeFieldEditor.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeFieldEditor.java
@@ -27,7 +27,7 @@ import org.eclipse.swt.widgets.Composite;
*/
public class TypeFieldEditor extends StringButtonFieldEditor {
- private TypeSystem ts;
+ private final TypeSystem ts;
public TypeFieldEditor(String name, String labelText, TypeSystem ts, Composite parent) {
super(name, labelText, parent);
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeInputDialog.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeInputDialog.java
index f16112f..f9b92ec 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeInputDialog.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeInputDialog.java
@@ -39,7 +39,7 @@ public class TypeInputDialog extends InputDialog {
String result = null;
if (ts.getType(value) == null) {
- return "Type does not exist in type sysetm!";
+ return "Type does not exist in type system!";
}
return result;
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java
index 5406024..fd89fab 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java
@@ -25,10 +25,8 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Listener;
/**
* Field Editor for a list of UIMA type names.
@@ -37,7 +35,7 @@ import org.eclipse.swt.widgets.Listener;
public class TypeListFieldEditor extends FieldEditor {
private List typeList;
- private TypeSystem ts;
+ private final TypeSystem ts;
private Button removeButton;
public TypeListFieldEditor(String name, String labelText,
@@ -72,12 +70,7 @@ public class TypeListFieldEditor extends FieldEditor {
gd.verticalAlignment = GridData.FILL;
typeList.setLayoutData(gd);
- typeList.addListener(SWT.Selection, new Listener(){
-
- @Override
- public void handleEvent(Event event) {
- checkState();
- }});
+ typeList.addListener(SWT.Selection, event -> checkState());
Composite buttonGroup = new Composite(parent, SWT.NONE);
GridLayout buttonLayout = new GridLayout();
@@ -85,20 +78,16 @@ public class TypeListFieldEditor extends FieldEditor {
Button addButton = new Button(buttonGroup, SWT.PUSH);
addButton.setText("Add");
- addButton.addListener(SWT.Selection, new Listener() {
+ addButton.addListener(SWT.Selection, event -> {
+ // We need a reference to the type system here ...
+ // open dialog to ask for new type ...
+ // dialog should contain a list of existing types ...
+ TypeInputDialog dialog = new TypeInputDialog(parent.getShell(), ts);
+ dialog.open();
+ String typeName = dialog.getValue();
- @Override
- public void handleEvent(Event event) {
- // We need a reference to the type system here ...
- // open dialog to ask for new type ...
- // dialog should contain a list of existing types ...
- TypeInputDialog dialog = new TypeInputDialog(parent.getShell(), ts);
- dialog.open();
- String typeName = dialog.getValue();
-
- if (typeName != null) {
- typeList.add(typeName);
- }
+ if (typeName != null) {
+ typeList.add(typeName);
}
});
@@ -107,18 +96,14 @@ public class TypeListFieldEditor extends FieldEditor {
// TODO: only enabled when an item in the list is selected
removeButton = new Button(buttonGroup, SWT.PUSH);
removeButton.setText("Remove");
- removeButton.addListener(SWT.Selection, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- int selectedItem = typeList.getSelectionIndex();
- if (selectedItem != -1) {
- typeList.remove(selectedItem);
- }
-
- checkState();
-
+ removeButton.addListener(SWT.Selection, event -> {
+ int selectedItem = typeList.getSelectionIndex();
+ if (selectedItem != -1) {
+ typeList.remove(selectedItem);
}
+
+ checkState();
+
});
removeButton.setLayoutData(GridDataFactory.fillDefaults().create());
@@ -131,7 +116,7 @@ public class TypeListFieldEditor extends FieldEditor {
if (typeList != null) {
String value = getPreferenceStore().getString(getPreferenceName());
- String types[] = getTypeList(value);
+ String[] types = getTypeList(value);
for (String type : types) {
typeList.add(type);
@@ -154,7 +139,7 @@ public class TypeListFieldEditor extends FieldEditor {
return 3;
}
- public static String listToString(String types[]) {
+ public static String listToString(String[] types) {
StringBuilder typeListString = new StringBuilder();
for (String type : types) {
@@ -170,7 +155,7 @@ public class TypeListFieldEditor extends FieldEditor {
}
public static String[] getTypeList(String typeListString) {
- String types[] = typeListString.split(",");
+ String[] types = typeListString.split(",");
for (int i = 0; i < types.length; i++) {
types[i] = types[i].trim();
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java
index 7bca2b0..2402dc3 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java
@@ -17,8 +17,6 @@
package org.apache.opennlp.caseditor.namefinder;
-
-import static org.apache.opennlp.caseditor.OpenNLPPreferenceConstants.*;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.SWT;
@@ -29,12 +27,12 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
+import static org.apache.opennlp.caseditor.OpenNLPPreferenceConstants.*;
+
public class ConfirmedNameDetectionFieldEditor extends FieldEditor {
private Button forceDetectionButton;
- private Composite optionButtons;
-
private Button ignoreShortTokensButton;
private Button onlyConsiderAllLetterTokensButton;
private Button onlyConsiderInitialCapitalTokensButton;
@@ -70,7 +68,7 @@ public class ConfirmedNameDetectionFieldEditor extends FieldEditor {
checkState();
}});
- optionButtons = new Composite(buttonGroup, SWT.NONE);
+ Composite optionButtons = new Composite(buttonGroup, SWT.NONE);
optionButtons.setLayout(new GridLayout());
// Ignore short tokens
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
index d36c67e..7c0a621 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/EntityContentProvider.java
@@ -22,8 +22,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import opennlp.tools.util.Span;
-
import org.apache.opennlp.caseditor.AbstractCasChangeTrigger;
import org.apache.opennlp.caseditor.OpenNLPPlugin;
import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
@@ -50,6 +48,8 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
+import opennlp.tools.util.Span;
+
/**
* The EntityContentProvider is responsible to trigger the detection of entities
* and turn these into potential entity annotations.
@@ -276,26 +276,26 @@ public class EntityContentProvider implements IStructuredContentProvider {
};
}
- private NameFinderJob nameFinder;
+ private final NameFinderJob nameFinder;
- private CasChangeNameFinderTrigger casChangeTrigger = new CasChangeNameFinderTrigger();
- private PreferenceChangeNameFinderTrigger preferenceChangeTrigger = new PreferenceChangeNameFinderTrigger();
- private ConfirmedEntityListener casChangeListener = new ConfirmedEntityListener();
+ private final CasChangeNameFinderTrigger casChangeTrigger = new CasChangeNameFinderTrigger();
+ private final PreferenceChangeNameFinderTrigger preferenceChangeTrigger = new PreferenceChangeNameFinderTrigger();
+ private final ConfirmedEntityListener casChangeListener = new ConfirmedEntityListener();
- private TableViewer entityListViewer;
+ private final TableViewer entityListViewer;
private ICasDocument input;
- private AnnotationEditor editor;
+ private final AnnotationEditor editor;
// contains all existing entity annotations and is synchronized!
// needed by name finder to calculate updates ...
- private List<PotentialAnnotation> candidateEntities = new ArrayList<PotentialAnnotation>();
- private List<PotentialAnnotation> confirmedEntities = new ArrayList<PotentialAnnotation>();
+ private final List<PotentialAnnotation> candidateEntities = new ArrayList<>();
+ private final List<PotentialAnnotation> confirmedEntities = new ArrayList<>();
- private String nameTypeNames[];
+ private String[] nameTypeNames;
- private NameFinderViewPage nameFinderView;
+ private final NameFinderViewPage nameFinderView;
EntityContentProvider(NameFinderViewPage nameFinderView, AnnotationEditor editor, TableViewer entityList) {
this.nameFinder = new NameFinderJob();
@@ -308,7 +308,7 @@ public class EntityContentProvider implements IStructuredContentProvider {
store.addPropertyChangeListener(preferenceChangeTrigger);
}
- private static boolean contains(String array[], String element) {
+ private static boolean contains(String[] array, String element) {
for (String arrayElement : array) {
if (element.equals(arrayElement))
@@ -317,7 +317,8 @@ public class EntityContentProvider implements IStructuredContentProvider {
return false;
}
-
+
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// Problem: "The viewer should not be updated during this call, as it might be in
@@ -396,7 +397,7 @@ public class EntityContentProvider implements IStructuredContentProvider {
return;
}
- String modelPathes[] = store.getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH).split(",");
+ String[] modelPathes = store.getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH).split(",");
for (int i = 0; i < modelPathes.length; i++) {
modelPathes[i] = modelPathes[i].trim();
@@ -415,7 +416,7 @@ public class EntityContentProvider implements IStructuredContentProvider {
if (text != null) {
- Type sentenceTypes[] = UIMAUtil.splitTypes(
+ Type[] sentenceTypes = UIMAUtil.splitTypes(
sentenceTypeName + "," + additionalSentenceTypes, ',', cas.getTypeSystem());
if (sentenceTypes == null) {
@@ -437,15 +438,14 @@ public class EntityContentProvider implements IStructuredContentProvider {
return;
}
- List<Span> sentences = new ArrayList<Span>();
- List<Span> tokens = new ArrayList<Span>();
+ List<Span> sentences = new ArrayList<>();
+ List<Span> tokens = new ArrayList<>();
for (Iterator<AnnotationFS> sentenceIterator =
UIMAUtil.createMultiTypeIterator(cas, sentenceTypes);
sentenceIterator.hasNext();) {
- AnnotationFS sentenceAnnotation = (AnnotationFS) sentenceIterator
- .next();
+ AnnotationFS sentenceAnnotation = sentenceIterator.next();
// TODO: Add code to detect overlapping sentences ... not allowed!
@@ -464,13 +464,13 @@ public class EntityContentProvider implements IStructuredContentProvider {
allTokens.iterator(), containingConstraint);
while (containingTokens.hasNext()) {
- AnnotationFS token = (AnnotationFS) containingTokens.next();
+ AnnotationFS token = containingTokens.next();
tokens.add(new Span(token.getBegin(), token.getEnd()));
}
}
- List<Span> nameSpans = new ArrayList<Span>();
+ List<Span> nameSpans = new ArrayList<>();
for (String nameTypeName : nameTypeNames) {
@@ -483,14 +483,10 @@ public class EntityContentProvider implements IStructuredContentProvider {
FSIndex<AnnotationFS> nameAnnotations = cas
.getAnnotationIndex(nameType);
-
- for (Iterator<AnnotationFS> nameIterator = nameAnnotations
- .iterator(); nameIterator.hasNext();) {
-
- AnnotationFS nameAnnotation = (AnnotationFS) nameIterator.next();
-
+
+ for (AnnotationFS nameAnnotation : nameAnnotations) {
nameSpans.add(new Span(nameAnnotation.getBegin(), nameAnnotation.getEnd(),
- nameAnnotation.getType().getName()));
+ nameAnnotation.getType().getName()));
}
}
@@ -539,7 +535,8 @@ public class EntityContentProvider implements IStructuredContentProvider {
nameFinder.schedule();
}
}
-
+
+ @Override
public Object[] getElements(Object inputElement) {
// Note:
// Called directly after showing the view, the
@@ -547,7 +544,8 @@ public class EntityContentProvider implements IStructuredContentProvider {
// which will be added to the viewer
return candidateEntities.toArray();
}
-
+
+ @Override
public void dispose() {
IPreferenceStore store = editor.getCasDocumentProvider().getTypeSystemPreferenceStore(editor.getEditorInput());
store.removePropertyChangeListener(preferenceChangeTrigger);
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
index dec49d1..5c205b1 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
@@ -37,9 +37,9 @@ public class MultiModelNameFinder implements TokenNameFinder {
static class RestrictedSequencesValidator extends NameFinderSequenceValidator {
- private String modelType;
+ private final String modelType;
- private Map<Integer, String> nameIndex = new HashMap<Integer, String>();
+ private Map<Integer, String> nameIndex = new HashMap<>();
private Set<String> nameOnlyTokens;
@@ -87,14 +87,13 @@ public class MultiModelNameFinder implements TokenNameFinder {
}
}
-
- private NameFinderME nameFinders[];
- private String modelTypes[];
+ private final NameFinderME[] nameFinders;
+ private final String[] modelTypes;
// TODO: We need one per name finder instance ...
- private RestrictedSequencesValidator sequenceValidators[];
+ private final RestrictedSequencesValidator[] sequenceValidators;
- MultiModelNameFinder(String modelPathes[], String modelTypes[]) throws IOException {
+ MultiModelNameFinder(String[] modelPathes, String[] modelTypes) throws IOException {
this.modelTypes = modelTypes;
@@ -104,27 +103,17 @@ public class MultiModelNameFinder implements TokenNameFinder {
for (int i = 0; i < modelPathes.length; i++) {
String modelPath = modelPathes[i];
-
- InputStream modelIn = ModelUtil.openModelIn(modelPath);
-
- try {
+
+ try (InputStream modelIn = ModelUtil.openModelIn(modelPath)) {
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
sequenceValidators[i] = new RestrictedSequencesValidator(modelTypes[i]);
- nameFinders[i] = new NameFinderME(model, null, 5, sequenceValidators[i]);
+ nameFinders[i] = new NameFinderME(model);
}
catch (IOException e) {
// Error message should include model type
throw new IOException("Failed to load a model, path:\n" + modelPathes[i] +
"\nError Message:\n" + e.getMessage());
}
- finally {
- if (modelIn != null) {
- try {
- modelIn.close();
- } catch (IOException e) {
- }
- }
- }
}
}
@@ -153,12 +142,12 @@ public class MultiModelNameFinder implements TokenNameFinder {
@Override
public ConfidenceSpan[] find(String[] sentence) {
- List<ConfidenceSpan> names = new ArrayList<ConfidenceSpan>();
+ List<ConfidenceSpan> names = new ArrayList<>();
for (int i = 0; i < nameFinders.length; i++) {
NameFinderME nameFinder = nameFinders[i];
- Span detectedNames[] = nameFinder.find(sentence);
- double confidence[] = nameFinder.probs();
+ Span[] detectedNames = nameFinder.find(sentence);
+ double[] confidence = nameFinder.probs();
for (int j = 0; j < detectedNames.length; j++) {
// TODO: Also add type ...
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
index 5bd20d8..a20e29a 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
@@ -25,10 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import opennlp.tools.namefind.NameFinderME;
-import opennlp.tools.util.Span;
-import opennlp.tools.util.featuregen.StringPattern;
-
import org.apache.opennlp.caseditor.OpenNLPPlugin;
import org.apache.opennlp.caseditor.PotentialAnnotation;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -36,6 +32,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import opennlp.tools.namefind.NameFinderME;
+import opennlp.tools.util.Span;
+import opennlp.tools.util.featuregen.StringPattern;
+
// Add error handling, if something goes wrong, an error should be reported!
// Need a rule, only one name finder job at a time ...
// don't change setting, while job is running!
@@ -44,14 +44,14 @@ public class NameFinderJob extends Job {
private MultiModelNameFinder nameFinder;
- private String modelPath[];
+ private String[] modelPath;
- private String modelTypes[];
+ private String[] modelTypes;
private String text;
- private Span sentences[];
- private Span tokens[];
- private Span verifiedNames[] = new Span[0];
+ private Span[] sentences;
+ private Span[] tokens;
+ private Span[] verifiedNames = new Span[0];
private List<PotentialAnnotation> nameList;
@@ -65,11 +65,8 @@ public class NameFinderJob extends Job {
super("Name Finder Job");
}
- /**
- * @param modelPath
- */
- synchronized void setModelPath(String modelPathes[], String modelTypes[]) {
- this.modelPath = modelPathes;
+ synchronized void setModelPath(String[] modelPath, String[] modelTypes) {
+ this.modelPath = modelPath;
this.modelTypes = modelTypes;
}
@@ -77,15 +74,15 @@ public class NameFinderJob extends Job {
this.text = text;
}
- synchronized void setSentences(Span sentences[]) {
+ synchronized void setSentences(Span[] sentences) {
this.sentences = sentences;
}
- synchronized void setTokens(Span tokens[]) {
+ synchronized void setTokens(Span[] tokens) {
this.tokens = tokens;
}
- synchronized void setVerifiedNames(Span verifiedNames[]) {
+ synchronized void setVerifiedNames(Span[] verifiedNames) {
this.verifiedNames = verifiedNames;
}
@@ -121,16 +118,16 @@ public class NameFinderJob extends Job {
if (nameFinder != null) {
nameFinder.clearAdaptiveData(); // TODO: If model loading fails we get a NPE here!
- nameList = new ArrayList<PotentialAnnotation>();
+ nameList = new ArrayList<>();
// TODO: Name tokens, should be for the entire text,
// not just the prev sentences ...
- Set<String> nameTokens = new HashSet<String>();
+ Set<String> nameTokens = new HashSet<>();
for (Span sentence : sentences) {
// Create token list for sentence
- List<Span> sentenceTokens = new ArrayList<Span>();
+ List<Span> sentenceTokens = new ArrayList<>();
for (Span token : tokens) {
if (sentence.contains(token)) {
@@ -138,14 +135,14 @@ public class NameFinderJob extends Job {
}
}
- String tokenStrings[] = new String[sentenceTokens.size()];
+ String[] tokenStrings = new String[sentenceTokens.size()];
for (int i = 0; i < sentenceTokens.size(); i++) {
Span token = sentenceTokens.get(i);
tokenStrings[i] = token.getCoveredText(text).toString();
}
- Map<Integer, String> verifiedNameTokens = new HashMap<Integer, String>();
+ Map<Integer, String> verifiedNameTokens = new HashMap<>();
// Note: This is slow!
// iterate over names, to find token indexes
@@ -198,19 +195,18 @@ public class NameFinderJob extends Job {
nameFinder.setNameOnlyTokens(nameTokens);
// TODO: Use multiple name finders here ....
- ConfidenceSpan names[] = nameFinder.find(tokenStrings);
-
- for (int i = 0; i < names.length; i++) {
-
+ ConfidenceSpan[] names = nameFinder.find(tokenStrings);
+
+ for (ConfidenceSpan name : names) {
+
// add sentence offset here ...
-
- int beginIndex = sentenceTokens.get(names[i].getStart()).getStart();
- int endIndex = sentenceTokens.get(names[i].getEnd() - 1).getEnd();
-
+ int beginIndex = sentenceTokens.get(name.getStart()).getStart();
+ int endIndex = sentenceTokens.get(name.getEnd() - 1).getEnd();
+
String coveredText = text.substring(beginIndex, endIndex);
-
+
nameList.add(new PotentialAnnotation(beginIndex, endIndex, coveredText,
- names[i].getConfidence(), names[i].getType()));
+ name.getConfidence(), name.getType()));
}
}
}
@@ -222,8 +218,6 @@ public class NameFinderJob extends Job {
}
public List<PotentialAnnotation> getNames() {
- List<PotentialAnnotation> names = new ArrayList<PotentialAnnotation>();
- names.addAll(nameList);
- return names;
+ return new ArrayList<>(nameList);
}
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java
index 7f4731b..590eb79 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java
@@ -31,9 +31,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
@@ -51,7 +49,7 @@ class NameFinderModelFieldEditor extends FieldEditor {
private static final String MODEL_PATH_KEY = "ModelPathKey";
private static final String TYPE_NAME_KEY = "TypeNameKey";
- private TypeSystem ts;
+ private final TypeSystem ts;
private Table modelTypeTable;
private Button editButton;
@@ -100,12 +98,7 @@ class NameFinderModelFieldEditor extends FieldEditor {
modelTypeTable.setLinesVisible(true);
modelTypeTable.setHeaderVisible(true);
- modelTypeTable.addListener(SWT.Selection, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- checkState();
- }});
+ modelTypeTable.addListener(SWT.Selection, event -> checkState());
TableColumn modelColumn = new TableColumn(modelTypeTable, SWT.NONE);
modelColumn.setText("Model Path");
@@ -123,57 +116,45 @@ class NameFinderModelFieldEditor extends FieldEditor {
addButton.setLayoutData(GridDataFactory.fillDefaults().create());
addButton.setText("Add");
- addButton.addListener(SWT.Selection, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
-
- NameFinderModelInputDialog dialog = new NameFinderModelInputDialog(
- parent.getShell(), "Add a name finder model", ts);
+ addButton.addListener(SWT.Selection, event -> {
+ NameFinderModelInputDialog dialog = new NameFinderModelInputDialog(
+ parent.getShell(), "Add a name finder model", ts);
- if (Dialog.OK == dialog.open()) {
- createTableItem(dialog.getModelPath(), dialog.getTypeName());
- }
- }});
+ if (Dialog.OK == dialog.open()) {
+ createTableItem(dialog.getModelPath(), dialog.getTypeName());
+ }
+ });
editButton = new Button(buttonGroup, SWT.PUSH);
editButton.setLayoutData(GridDataFactory.fillDefaults().create());
editButton.setText("Edit");
- editButton.addListener(SWT.Selection, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- NameFinderModelInputDialog dialog = new NameFinderModelInputDialog(parent.getShell(),
- "Edit name finder model", ts);
+ editButton.addListener(SWT.Selection, event -> {
+ NameFinderModelInputDialog dialog = new NameFinderModelInputDialog(parent.getShell(),
+ "Edit name finder model", ts);
- TableItem item = modelTypeTable.getItem(modelTypeTable.getSelectionIndex());
+ TableItem item = modelTypeTable.getItem(modelTypeTable.getSelectionIndex());
- dialog.setModelPath((String) item.getData(MODEL_PATH_KEY));
- dialog.setTypeName((String) item.getData(TYPE_NAME_KEY));
+ dialog.setModelPath((String) item.getData(MODEL_PATH_KEY));
+ dialog.setTypeName((String) item.getData(TYPE_NAME_KEY));
- if (Dialog.OK == dialog.open()) {
- item.setData(MODEL_PATH_KEY, dialog.getModelPath());
- item.setText(0, dialog.getModelPath());
+ if (Dialog.OK == dialog.open()) {
+ item.setData(MODEL_PATH_KEY, dialog.getModelPath());
+ item.setText(0, dialog.getModelPath());
- item.setData(TYPE_NAME_KEY, dialog.getTypeName());
- item.setText(1, dialog.getTypeName());
- }
- }});
+ item.setData(TYPE_NAME_KEY, dialog.getTypeName());
+ item.setText(1, dialog.getTypeName());
+ }
+ });
removeButton = new Button(buttonGroup, SWT.PUSH);
removeButton.setLayoutData(GridDataFactory.fillDefaults().create());
removeButton.setText("Remove");
- removeButton.addListener(SWT.Selection, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
-
- modelTypeTable.remove(modelTypeTable.getSelectionIndex());
-
- checkState();
- }});
+ removeButton.addListener(SWT.Selection, event -> {
+ modelTypeTable.remove(modelTypeTable.getSelectionIndex());
+ checkState();
+ });
checkState();
}
@@ -182,10 +163,10 @@ class NameFinderModelFieldEditor extends FieldEditor {
protected void doLoad() {
if (modelTypeTable != null) {
String modelPathsString = getPreferenceStore().getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH);
- String modelPaths[] = TypeListFieldEditor.getTypeList(modelPathsString);
+ String[] modelPaths = TypeListFieldEditor.getTypeList(modelPathsString);
String typeNamesString = getPreferenceStore().getString(OpenNLPPreferenceConstants.NAME_TYPE);
- String typeNames[] = TypeListFieldEditor.getTypeList(typeNamesString);
+ String[] typeNames = TypeListFieldEditor.getTypeList(typeNamesString);
// Don't load anything ...
if (modelPaths.length != typeNames.length) {
@@ -207,8 +188,8 @@ class NameFinderModelFieldEditor extends FieldEditor {
@Override
protected void doStore() {
- List<String> modelPaths = new ArrayList<String>();
- List<String> typeNames = new ArrayList<String>();
+ List<String> modelPaths = new ArrayList<>();
+ List<String> typeNames = new ArrayList<>();
// iterate over table
for (int i = 0; i < modelTypeTable.getItemCount(); i++) {
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java
index 3f36085..0593a25 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java
@@ -36,9 +36,9 @@ import org.eclipse.swt.widgets.Text;
// TODO: Add validation
public class NameFinderModelInputDialog extends Dialog {
- private TypeSystem ts;
+ private final TypeSystem ts;
- private String dialogTitle;
+ private final String dialogTitle;
private String modelTextValue = "";
private String typeNameTextValue = "";
@@ -81,12 +81,7 @@ public class NameFinderModelInputDialog extends Dialog {
modelText.setLayoutData(GridDataFactory.swtDefaults().
align(SWT.FILL, SWT.CENTER).grab(true, false).create());
modelText.setText(modelTextValue);
- modelText.addListener(SWT.Modify, new Listener(){
-
- @Override
- public void handleEvent(Event event) {
- modelTextValue = modelText.getText();
- }});
+ modelText.addListener(SWT.Modify, event -> modelTextValue = modelText.getText());
// TODO: Implement browse button
// Button browseButton = new Button(dialogArea, SWT.PUSH);
@@ -99,13 +94,7 @@ public class NameFinderModelInputDialog extends Dialog {
typeNameText.setLayoutData(GridDataFactory.swtDefaults().
align(SWT.FILL, SWT.CENTER).grab(true, false).create());
typeNameText.setText(typeNameTextValue);
- typeNameText.addListener(SWT.Modify, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- typeNameTextValue = typeNameText.getText();
- }
- });
+ typeNameText.addListener(SWT.Modify, event -> typeNameTextValue = typeNameText.getText());
return dialogArea;
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
index fcfc536..0b5c73a 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
@@ -27,7 +27,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class NameFinderPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
- private TypeSystem ts;
+ private final TypeSystem ts;
public NameFinderPreferencePage(TypeSystem ts) {
setDescription("Name Finder Preferences.");
@@ -64,6 +64,6 @@ public class NameFinderPreferencePage extends FieldEditorPreferencePage
new ConfirmedNameDetectionFieldEditor(getFieldEditorParent());
addField(forceNameDetection);
// Add a group
- // Other options should be have an indent ...
+ // Other options should have an indent ...
}
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
index 9bab024..570501d 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderViewPage.java
@@ -20,14 +20,13 @@ package org.apache.opennlp.caseditor.namefinder;
import org.apache.opennlp.caseditor.ConfirmAnnotationAction;
import org.apache.opennlp.caseditor.OpenPreferenceDialog;
import org.apache.opennlp.caseditor.PotentialAnnotation;
-import org.apache.opennlp.caseditor.PotentialAnnotationComperator;
+import org.apache.opennlp.caseditor.PotentialAnnotationComparator;
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.ICasEditorInputListener;
import org.apache.uima.caseditor.editor.util.AnnotationSelection;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
@@ -45,7 +44,6 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
@@ -62,9 +60,9 @@ class NameFinderViewPage extends Page implements ISelectionListener {
private static final String QUICK_ANNOTATE_ACTION_ID = "QuickAnnotate";
- private NameFinderView nameFinderView;
+ private final NameFinderView nameFinderView;
- private ICasEditor editor;
+ private final ICasEditor editor;
private PageBook book;
@@ -111,7 +109,7 @@ class NameFinderViewPage extends Page implements ISelectionListener {
entityList.setContentProvider(new EntityContentProvider(this, (AnnotationEditor) editor, entityList));
getSite().setSelectionProvider(entityList);
- entityList.setComparator(new PotentialAnnotationComperator());
+ entityList.setComparator(new PotentialAnnotationComparator());
entityList.setInput(editor.getDocument());
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/PotentialEntityAnnotationLabelProvider.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/PotentialEntityAnnotationLabelProvider.java
index 9dbb196..e25e4ca 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/PotentialEntityAnnotationLabelProvider.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/PotentialEntityAnnotationLabelProvider.java
@@ -26,22 +26,27 @@ import org.eclipse.swt.graphics.Image;
public class PotentialEntityAnnotationLabelProvider implements ITableLabelProvider {
- private DecimalFormat df = new DecimalFormat("#.#");
-
+ private final DecimalFormat df = new DecimalFormat("#.#");
+
+ @Override
public void addListener(ILabelProviderListener listener) {
}
+ @Override
public void removeListener(ILabelProviderListener listener) {
}
+ @Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
+ @Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
+ @Override
public String getColumnText(Object element, int columnIndex) {
String result = null;
@@ -59,7 +64,7 @@ public class PotentialEntityAnnotationLabelProvider implements ITableLabelProvid
else if (columnIndex == 2) {
// TODO: Improve this ...
if (entity.getType() != null && entity.getType() != null) {
- String parts[] = entity.getType().split("\\.");
+ String[] parts = entity.getType().split("\\.");
result = parts[parts.length - 1];
} else
result = "";
@@ -68,6 +73,7 @@ public class PotentialEntityAnnotationLabelProvider implements ITableLabelProvid
return result;
}
+ @Override
public void dispose() {
}
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java
index 6a84085..1fc5e03 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceContentProvider.java
@@ -71,16 +71,16 @@ public class SentenceContentProvider implements IStructuredContentProvider {
}
}
- private SentenceDetectorViewPage sentenceDetectorView;
+ private final SentenceDetectorViewPage sentenceDetectorView;
- private AnnotationEditor editor;
+ private final AnnotationEditor editor;
private ICasDocumentListener casChangedTrigger;
- private PreferenceChangeTrigger preferenceChangeTrigger = new PreferenceChangeTrigger();
+ private final PreferenceChangeTrigger preferenceChangeTrigger = new PreferenceChangeTrigger();
- private SentenceDetectorJob sentenceDetector;
+ private final SentenceDetectorJob sentenceDetector;
- private TableViewer sentenceList;
+ private final TableViewer sentenceList;
public SentenceContentProvider(SentenceDetectorViewPage sentenceDetectorView, AnnotationEditor editor,
SentenceDetectorJob sentenceDetector, TableViewer sentenceList) {
@@ -91,87 +91,81 @@ public class SentenceContentProvider implements IStructuredContentProvider {
sentenceDetector.addJobChangeListener(new JobChangeAdapter() {
public void done(final IJobChangeEvent event) {
- Display.getDefault().asyncExec(new Runnable() {
+ Display.getDefault().asyncExec(() -> {
+ if (event.getResult().isOK()) {
- @Override
- public void run() {
- if (event.getResult().isOK()) {
-
- SentenceContentProvider.this.sentenceDetectorView.setMessage(null);
-
- List<PotentialAnnotation> confirmedSentences = new ArrayList<PotentialAnnotation>();
- // TODO: Create a list of existing sentence annotations.
-
- // get sentence annotation index ...
- CAS cas = SentenceContentProvider.this.editor.getDocument().getCAS();
-
- IPreferenceStore store = SentenceContentProvider.this.editor.
- getCasDocumentProvider().getTypeSystemPreferenceStore(
- SentenceContentProvider.this.editor.getEditorInput());
-
- String sentenceTypeName = store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE);;
- Type sentenceType = cas.getTypeSystem().getType(sentenceTypeName);
-
- for (Iterator<AnnotationFS> it = cas.getAnnotationIndex(sentenceType).iterator();
- it.hasNext(); ) {
- AnnotationFS sentenceAnnotation = it.next();
- confirmedSentences.add(new PotentialAnnotation(sentenceAnnotation.getBegin(),
- sentenceAnnotation.getEnd(), sentenceAnnotation.getCoveredText(), 1d, sentenceTypeName));
+ SentenceContentProvider.this.sentenceDetectorView.setMessage(null);
+
+ List<PotentialAnnotation> confirmedSentences = new ArrayList<>();
+ // TODO: Create a list of existing sentence annotations.
+
+ // get sentence annotation index ...
+ CAS cas = SentenceContentProvider.this.editor.getDocument().getCAS();
+
+ IPreferenceStore store = SentenceContentProvider.this.editor.
+ getCasDocumentProvider().getTypeSystemPreferenceStore(
+ SentenceContentProvider.this.editor.getEditorInput());
+
+ String sentenceTypeName = store.getString(OpenNLPPreferenceConstants.SENTENCE_TYPE);
+ Type sentenceType = cas.getTypeSystem().getType(sentenceTypeName);
+
+ for (AnnotationFS sentenceAnnotation : cas.getAnnotationIndex(sentenceType)) {
+ confirmedSentences.add(new PotentialAnnotation(sentenceAnnotation.getBegin(),
+ sentenceAnnotation.getEnd(), sentenceAnnotation.getCoveredText(), 1d, sentenceTypeName));
+ }
+
+
+ PotentialAnnotation[] sentences = SentenceContentProvider.this.
+ sentenceDetector.getDetectedSentences();
+
+ // TODO:
+ // Remove all detected sentences from the last run which are not detected anymore
+ Table sentenceTable = SentenceContentProvider.this.sentenceList.getTable();
+
+ int selectionIndex = sentenceTable.getSelectionIndex();
+
+ SentenceContentProvider.this.sentenceList.refresh();
+
+ // TODO: Update sentence if it already exist
+
+ // Add a new potential sentence
+ // Only add if it is not a confirmed sentence yet!
+ // for each annotation, search confirmed sentence array above ...
+ for (PotentialAnnotation sentence : sentences) {
+ if (EntityContentProvider.searchEntity(confirmedSentences,
+ sentence.getBeginIndex(), sentence.getEndIndex(),
+ sentence.getType()) == null) {
+ SentenceContentProvider.this.sentenceList.add(sentence);
}
-
-
- PotentialAnnotation sentences[] = SentenceContentProvider.this.
- sentenceDetector.getDetectedSentences();
-
- // TODO:
- // Remove all detected sentences from the last run which are not detected anymore
- Table sentenceTable = SentenceContentProvider.this.sentenceList.getTable();
-
- int selectionIndex = sentenceTable.getSelectionIndex();
-
- SentenceContentProvider.this.sentenceList.refresh();
-
- // TODO: Update sentence if it already exist
-
- // Add a new potential sentence
- // Only add if it is not a confirmed sentence yet!
- // for each annotation, search confirmed sentence array above ...
- for (PotentialAnnotation sentence : sentences) {
- if (EntityContentProvider.searchEntity(confirmedSentences,
- sentence.getBeginIndex(), sentence.getEndIndex(),
- sentence.getType()) == null) {
- SentenceContentProvider.this.sentenceList.add(sentence);
+ }
+
+ // TODO: Try to reuse selection computation code
+
+ // is sentence detector view active ?!
+ if (SentenceContentProvider.this.sentenceDetectorView.isActive()) {
+ int newSelectionIndex = -1;
+
+ if (sentenceTable.getItemCount() > 0) {
+ if (sentenceTable.getSelectionIndex() == -1) {
+ newSelectionIndex = 0;
}
- }
-
- // TODO: Try to reuse selection computation code
-
- // is sentence detector view active ?!
- if (SentenceContentProvider.this.sentenceDetectorView.isActive()) {
- int newSelectionIndex = -1;
-
- if (sentenceTable.getItemCount() > 0) {
- if (sentenceTable.getSelectionIndex() == -1) {
- newSelectionIndex = 0;
- }
-
- if (selectionIndex < sentenceTable.getItemCount()) {
- newSelectionIndex = selectionIndex;
- }
- else if (selectionIndex >= sentenceTable.getItemCount()) {
- newSelectionIndex = sentenceTable.getItemCount() - 1;
- }
+
+ if (selectionIndex < sentenceTable.getItemCount()) {
+ newSelectionIndex = selectionIndex;
}
-
- if (newSelectionIndex != -1) {
- SentenceContentProvider.this.sentenceList.setSelection(
- new StructuredSelection(SentenceContentProvider.this.sentenceList.getElementAt(newSelectionIndex)));
+ else if (selectionIndex >= sentenceTable.getItemCount()) {
+ newSelectionIndex = sentenceTable.getItemCount() - 1;
}
}
+
+ if (newSelectionIndex != -1) {
+ SentenceContentProvider.this.sentenceList.setSelection(
+ new StructuredSelection(SentenceContentProvider.this.sentenceList.getElementAt(newSelectionIndex)));
+ }
}
- else {
- SentenceContentProvider.this.sentenceDetectorView.setMessage(event.getResult().getMessage());
- }
+ }
+ else {
+ SentenceContentProvider.this.sentenceDetectorView.setMessage(event.getResult().getMessage());
}
});
}
@@ -209,9 +203,9 @@ public class SentenceContentProvider implements IStructuredContentProvider {
CAS cas = editor.getDocument().getCAS();
String paragraphTypeNames = store.getString(OpenNLPPreferenceConstants.PARAGRAPH_TYPE);
- Type paragraphTypes[] = UIMAUtil.splitTypes(paragraphTypeNames, ',', cas.getTypeSystem());
+ Type[] paragraphTypes = UIMAUtil.splitTypes(paragraphTypeNames, ',', cas.getTypeSystem());
- List<Span> paragraphSpans = new ArrayList<Span>();
+ List<Span> paragraphSpans = new ArrayList<>();
if (paragraphTypes != null) {
@@ -256,7 +250,7 @@ public class SentenceContentProvider implements IStructuredContentProvider {
String exclusionSpanTypeNames = store.getString(OpenNLPPreferenceConstants.SENT_EXCLUSION_TYPE);
- Type exclusionSpanTypes[] = UIMAUtil.splitTypes(exclusionSpanTypeNames, ',', cas.getTypeSystem());
+ Type[] exclusionSpanTypes = UIMAUtil.splitTypes(exclusionSpanTypeNames, ',', cas.getTypeSystem());
if (exclusionSpanTypes == null) {
exclusionSpanTypes = new Type[0];
@@ -267,7 +261,7 @@ public class SentenceContentProvider implements IStructuredContentProvider {
exclusionSpanTypes[exclusionSpanTypes.length - 1] = sentenceType;
}
- List<Span> exclusionSpans = new ArrayList<Span>();
+ List<Span> exclusionSpans = new ArrayList<>();
for (Iterator<AnnotationFS> exclusionAnnIterator = UIMAUtil.createMultiTypeIterator(cas, exclusionSpanTypes);
exclusionAnnIterator.hasNext();) {
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
index 2253fc9..e1c1e8c 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorJob.java
@@ -23,10 +23,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import opennlp.tools.sentdetect.SentenceDetectorME;
-import opennlp.tools.sentdetect.SentenceModel;
-import opennlp.tools.util.Span;
-
import org.apache.opennlp.caseditor.ModelUtil;
import org.apache.opennlp.caseditor.OpenNLPPlugin;
import org.apache.opennlp.caseditor.PotentialAnnotation;
@@ -35,6 +31,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import opennlp.tools.sentdetect.SentenceDetectorME;
+import opennlp.tools.sentdetect.SentenceModel;
+import opennlp.tools.util.Span;
+
public class SentenceDetectorJob extends Job {
private SentenceDetectorME sentenceDetector;
@@ -73,7 +73,7 @@ public class SentenceDetectorJob extends Job {
public void setExclusionSpans(List<Span> exclusionSpans) {
- this.exclusionSpans = new ArrayList<Span>();
+ this.exclusionSpans = new ArrayList<>();
this.exclusionSpans.addAll(exclusionSpans);
Collections.sort(this.exclusionSpans);
}
@@ -83,28 +83,18 @@ public class SentenceDetectorJob extends Job {
// lazy load model
if (sentenceDetector == null) {
- InputStream modelIn = null;
- try {
- modelIn = ModelUtil.openModelIn(modelPath);
+ try (InputStream modelIn = ModelUtil.openModelIn(modelPath)) {
SentenceModel model = new SentenceModel(modelIn);
sentenceDetector = new SentenceDetectorME(model);
} catch (IOException e1) {
return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, "Failed to load sentence detector model!");
}
- finally {
- if (modelIn != null) {
- try {
- modelIn.close();
- } catch (IOException e) {
- }
- }
- }
}
- detectedSentences = new ArrayList<PotentialAnnotation>();
+ detectedSentences = new ArrayList<>();
for (Span para : paragraphs) {
- List<Span> textBlocks = new ArrayList<Span>();
+ List<Span> textBlocks = new ArrayList<>();
int textBlockBeginIndex = 0;
@@ -126,10 +116,10 @@ public class SentenceDetectorJob extends Job {
}
for (Span textBlock : textBlocks) {
- Span sentenceSpans[] = sentenceDetector.sentPosDetect(
+ Span[] sentenceSpans = sentenceDetector.sentPosDetect(
textBlock.getCoveredText(text).toString());
- double confidence[] = sentenceDetector.getSentenceProbabilities();
+ double[] confidence = sentenceDetector.getSentenceProbabilities();
for (int i = 0; i < sentenceSpans.length; i++) {
Span sentenceSpan = sentenceSpans[i];
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorPreferencePage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorPreferencePage.java
index a5098aa..ac8d61d 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorPreferencePage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorPreferencePage.java
@@ -28,7 +28,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class SentenceDetectorPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
- private TypeSystem ts;
+ private final TypeSystem ts;
public SentenceDetectorPreferencePage(TypeSystem ts) {
setDescription("Sentence Detector Preferences.");
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorViewPage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorViewPage.java
index f8c7200..8288102 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorViewPage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceDetectorViewPage.java
@@ -26,8 +26,6 @@ import org.apache.uima.caseditor.editor.AnnotationEditor;
import org.apache.uima.caseditor.editor.ICasEditor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
@@ -47,17 +45,15 @@ public class SentenceDetectorViewPage extends Page {
private static final String QUICK_ANNOTATE_ACTION_ID = "QuickAnnotate";
- private ICasEditor editor;
+ private final ICasEditor editor;
private PageBook book;
private Text messageText;
- private TableViewer sentenceList;
-
- private SentenceContentProvider contentProvider;
+ private TableViewer sentenceList;
- private SentenceDetectorView sentenceDetectorView;
+ private final SentenceDetectorView sentenceDetectorView;
public SentenceDetectorViewPage(SentenceDetectorView sentenceDetectorView, ICasEditor editor) {
this.sentenceDetectorView = sentenceDetectorView;
@@ -93,31 +89,27 @@ public class SentenceDetectorViewPage extends Page {
sentenceList.setLabelProvider(new SentenceLabelProvider());
SentenceDetectorJob sentenceDetector = new SentenceDetectorJob();
-
- contentProvider = new SentenceContentProvider(this, (AnnotationEditor) editor,
- sentenceDetector, sentenceList);
+
+ SentenceContentProvider contentProvider = new SentenceContentProvider(this, (AnnotationEditor) editor,
+ sentenceDetector, sentenceList);
sentenceList.setContentProvider(contentProvider);
getSite().setSelectionProvider(sentenceList);
sentenceList.setInput(editor.getDocument());
- sentenceList.addSelectionChangedListener(new ISelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- // if confirmed, send selection event for FS
- // else, do selectAndReveal
- StructuredSelection selection = (StructuredSelection) event
- .getSelection();
+ sentenceList.addSelectionChangedListener(event -> {
+ // if confirmed, send selection event for FS
+ // else, do selectAndReveal
+ StructuredSelection selection = (StructuredSelection) event
+ .getSelection();
- if (!selection.isEmpty()) {
- PotentialAnnotation entity = (PotentialAnnotation) selection.getFirstElement();
+ if (!selection.isEmpty()) {
+ PotentialAnnotation entity = (PotentialAnnotation) selection.getFirstElement();
- if (editor instanceof AnnotationEditor) {
- ((AnnotationEditor) editor).selectAndReveal(
- entity.getBeginIndex(),
- entity.getEndIndex() - entity.getBeginIndex());
- }
+ if (editor instanceof AnnotationEditor) {
+ ((AnnotationEditor) editor).selectAndReveal(
+ entity.getBeginIndex(),
+ entity.getEndIndex() - entity.getBeginIndex());
}
}
});
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceLabelProvider.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceLabelProvider.java
index 6bfd18d..fd35ba5 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceLabelProvider.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/sentdetect/SentenceLabelProvider.java
@@ -25,22 +25,27 @@ import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
public class SentenceLabelProvider implements ITableLabelProvider {
- private DecimalFormat df = new DecimalFormat("#.#");
-
+ private final DecimalFormat df = new DecimalFormat("#.#");
+
+ @Override
public void addListener(ILabelProviderListener listener) {
}
+ @Override
public void removeListener(ILabelProviderListener listener) {
}
+ @Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
+ @Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
+ @Override
public String getColumnText(Object element, int columnIndex) {
String result = null;
@@ -67,6 +72,7 @@ public class SentenceLabelProvider implements ITableLabelProvider {
return result;
}
+ @Override
public void dispose() {
}
}
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
index 1dbe16c..e8d1119 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerJob.java
@@ -20,13 +20,6 @@ package org.apache.opennlp.caseditor.tokenize;
import java.io.IOException;
import java.io.InputStream;
-import opennlp.tools.tokenize.SimpleTokenizer;
-import opennlp.tools.tokenize.Tokenizer;
-import opennlp.tools.tokenize.TokenizerME;
-import opennlp.tools.tokenize.TokenizerModel;
-import opennlp.tools.tokenize.WhitespaceTokenizer;
-import opennlp.tools.util.Span;
-
import org.apache.opennlp.caseditor.ModelUtil;
import org.apache.opennlp.caseditor.OpenNLPPlugin;
import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
@@ -35,6 +28,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import opennlp.tools.tokenize.SimpleTokenizer;
+import opennlp.tools.tokenize.Tokenizer;
+import opennlp.tools.tokenize.TokenizerME;
+import opennlp.tools.tokenize.TokenizerModel;
+import opennlp.tools.tokenize.WhitespaceTokenizer;
+import opennlp.tools.util.Span;
+
public class TokenizerJob extends Job {
private String algorithm;
@@ -73,31 +73,14 @@ public class TokenizerJob extends Job {
tokenizer = SimpleTokenizer.INSTANCE;
} else if (OpenNLPPreferenceConstants.TOKENIZER_ALGO_STATISTICAL.equals(algorithm)) {
if (tokenizer == null) {
- InputStream modelIn;
- try {
- modelIn = ModelUtil.openModelIn(modelPath);
- } catch (IOException e1) {
- return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, "Failed to load tokenizer model!");
- }
-
- try {
+ try (InputStream modelIn = ModelUtil.openModelIn(modelPath)) {
TokenizerModel model = new TokenizerModel(modelIn);
tokenizer = new TokenizerME(model);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (modelIn != null) {
- try {
- modelIn.close();
- } catch (IOException e) {
- }
- }
+ } catch (IOException e1) {
+ return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, "Failed to load tokenizer model!");
}
}
}
- else {
- // TODO: Report an error!
- }
tokens = tokenizer.tokenizePos(text);
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerPreferencePage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerPreferencePage.java
index 5dcd84f..b3cc980 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerPreferencePage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerPreferencePage.java
@@ -52,7 +52,7 @@ public class TokenizerPreferencePage extends FieldEditorPreferencePage
"Algorithm", namesAndValues, getFieldEditorParent());
addField(algorithmCombo);
- // Activate only if statistical is selected .. how to do that?
+ // Activate only if statistical is selected - how to do that?
StringFieldEditor modelPath = new StringFieldEditor(
OpenNLPPreferenceConstants.TOKENIZER_MODEL_PATH,
"Model Path", getFieldEditorParent());
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerView.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerView.java
index d920475..e7dc917 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerView.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerView.java
@@ -27,6 +27,7 @@ public class TokenizerView extends AnnotationEditorView {
super("The Tokenizer View is currently not available.");
}
+ @Override
protected PageRec doCreatePage(ICasEditor editor) {
PageRec result = null;
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerViewPage.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerViewPage.java
index e9391d6..7b25d28 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerViewPage.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/tokenize/TokenizerViewPage.java
@@ -20,8 +20,6 @@ package org.apache.opennlp.caseditor.tokenize;
import java.util.ArrayList;
import java.util.Collection;
-import opennlp.tools.util.Span;
-
import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Type;
@@ -37,9 +35,11 @@ import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.part.Page;
+import opennlp.tools.util.Span;
+
public class TokenizerViewPage extends Page {
- private ICasEditor editor;
+ private final ICasEditor editor;
private Label workInProgress;
@@ -83,13 +83,13 @@ public class TokenizerViewPage extends Page {
e.printStackTrace();
}
- Span tokens[] = tokenizerJob.getTokens();
+ Span[] tokens = tokenizerJob.getTokens();
CAS cas = editor.getDocument().getCAS();
Type tokenType = cas.getTypeSystem().getType(prefStore.getString(OpenNLPPreferenceConstants.TOKEN_TYPE));
- Collection<AnnotationFS> tokenAnnotations = new ArrayList<AnnotationFS>(tokens.length);
+ Collection<AnnotationFS> tokenAnnotations = new ArrayList<>(tokens.length);
for (Span token : tokens) {
tokenAnnotations.add(cas.createAnnotation(tokenType, token.getStart(), token.getEnd()));
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/ContainingConstraint.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/ContainingConstraint.java
index 51ce60d..75e267e 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/ContainingConstraint.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/ContainingConstraint.java
@@ -1,6 +1,6 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreemnets. See the NOTICE file distributed with
+ * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
@@ -18,7 +18,6 @@
package org.apache.opennlp.caseditor.util;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import org.apache.uima.cas.FSMatchConstraint;
@@ -31,8 +30,7 @@ import org.apache.uima.cas.text.AnnotationFS;
public final class ContainingConstraint implements FSMatchConstraint {
private static final long serialVersionUID = 1;
- private Collection<AnnotationFS> mContainingAnnotations =
- new LinkedList<AnnotationFS>();
+ private final Collection<AnnotationFS> mContainingAnnotations = new LinkedList<>();
/**
* Initializes a new instance.
@@ -43,8 +41,6 @@ public final class ContainingConstraint implements FSMatchConstraint {
/**
* Initializes a new instance.
- *
- * @param containingAnnotation
*/
public ContainingConstraint(AnnotationFS containingAnnotation) {
mContainingAnnotations.add(containingAnnotation);
@@ -60,8 +56,7 @@ public final class ContainingConstraint implements FSMatchConstraint {
AnnotationFS annotation = (AnnotationFS) featureStructure;
- for (Iterator<AnnotationFS> it = mContainingAnnotations.iterator(); it.hasNext(); ) {
- AnnotationFS containingAnnotation = it.next();
+ for (AnnotationFS containingAnnotation : mContainingAnnotations) {
if (isContaining(annotation, containingAnnotation)) {
return true;
}
@@ -71,12 +66,8 @@ public final class ContainingConstraint implements FSMatchConstraint {
}
private boolean isContaining(AnnotationFS annotation, AnnotationFS containing) {
- if ((containing.getBegin() <= annotation.getBegin())
- && (containing.getEnd() >= annotation.getEnd())) {
- return true;
- } else {
- return false;
- }
+ return (containing.getBegin() <= annotation.getBegin())
+ && (containing.getEnd() >= annotation.getEnd());
}
}
\ No newline at end of file
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/UIMAUtil.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/UIMAUtil.java
index 6c3d604..2202dfd 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/UIMAUtil.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/util/UIMAUtil.java
@@ -29,7 +29,7 @@ public class UIMAUtil {
public static String[] split(String parameter, char splitChar) {
- String parts[] = parameter.split(Character.toString(splitChar));
+ String[] parts = parameter.split(Character.toString(splitChar));
for (int i = 0; i < parts.length; i++) {
parts[i] = parts[i].trim();
@@ -40,9 +40,9 @@ public class UIMAUtil {
// TODO: Should throw an exception
public static Type[] splitTypes(String typeList, char splitChar, TypeSystem typeSystem) {
- String typeNames[] = split(typeList, splitChar);
+ String[] typeNames = split(typeList, splitChar);
- Type types[] = new Type[typeNames.length];
+ Type[] types = new Type[typeNames.length];
for (int i = 0; i < typeNames.length; i++) {
types[i] = typeSystem.getType(typeNames[i]);
@@ -70,8 +70,6 @@ public class UIMAUtil {
}
// Create and use the filtered iterator
- FSIterator<AnnotationFS> filteredIterator = cas.createFilteredIterator(iterator, typeConstraint);
-
- return filteredIterator;
+ return cas.createFilteredIterator(iterator, typeConstraint);
}
}