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/12/06 13:59:29 UTC
svn commit: r1210891 - in
/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor:
./ namefinder/
Author: joern
Date: Tue Dec 6 12:59:28 2011
New Revision: 1210891
URL: http://svn.apache.org/viewvc?rev=1210891&view=rev
Log:
OPENNLP-319 Added two new field editors to name finder preference page to make configuration easier.
Added:
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java (with props)
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java (with props)
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java (with props)
Modified:
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceConstants.java
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java
incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceConstants.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceConstants.java?rev=1210891&r1=1210890&r2=1210891&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceConstants.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/OpenNLPPreferenceConstants.java Tue Dec 6 12:59:28 2011
@@ -22,16 +22,19 @@ public class OpenNLPPreferenceConstants
// General settings
public static final String SENTENCE_TYPE = OpenNLPPlugin.ID + ".SENTENCE_TYPE";
public static final String TOKEN_TYPE = OpenNLPPlugin.ID + ".TOKEN_TYPE";
-
+
// Sentence detector
public static final String PARAGRAPH_TYPE = OpenNLPPlugin.ID + ".PARAGRAPH_TYPE";
public static final String SENTENCE_DETECTOR_MODEL_PATH = OpenNLPPlugin.ID + ".SENTENCE_DETECTOR_MODEL_PATH";
-
+
// Name Finder
public static final String ADDITIONAL_SENTENCE_TYPE = OpenNLPPlugin.ID + ".ADDITIONAL_SENTENCE_TYPE";
public static final String NAME_TYPE = OpenNLPPlugin.ID + ".NAME_TYPE";
public static final String NAME_FINDER_MODEL_PATH = OpenNLPPlugin.ID + ".NAME_FINDER_MODEL_PATH";
public static final String ENABLE_CONFIRMED_NAME_DETECTION = OpenNLPPlugin.ID + ".ENABLE_RECALL_BOOSTING";
+ public static final String IGNORE_SHORT_TOKENS = OpenNLPPlugin.ID + ".IGNORE_SHORT_TOKENS";
+ public static final String ONLY_CONSIDER_ALL_LETTER_TOKENS = OpenNLPPlugin.ID + ".ONLY_CONSIDER_ALL_LETTER_TOKENS";
+ public static final String ONLY_CONSIDER_INITIAL_CAPITAL_TOKENS = OpenNLPPlugin.ID + ".ONLY_CONSIDER_INITIAL_CAPITAL_TOKENS";
// Tokenizer
public static final String TOKENIZER_MODEL_PATH = OpenNLPPlugin.ID + ".TOKENIZER_MODEL_PATH";
Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java?rev=1210891&r1=1210890&r2=1210891&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/TypeListFieldEditor.java Tue Dec 6 12:59:28 2011
@@ -18,24 +18,27 @@
package org.apache.opennlp.caseditor;
import org.apache.uima.cas.TypeSystem;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
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.
*/
+// TODO: Enforce that no duplicate entries can be created
public class TypeListFieldEditor extends FieldEditor {
private List typeList;
private TypeSystem ts;
+ private Button removeButton;
public TypeListFieldEditor(String name, String labelText,
TypeSystem ts, Composite parent) {
@@ -47,6 +50,10 @@ public class TypeListFieldEditor extends
protected void adjustForNumColumns(int numColumns) {
}
+ private void checkState() {
+ removeButton.setEnabled(typeList.getSelectionCount() > 0);
+ }
+
@Override
protected void doFillIntoGrid(final Composite parent,
int numColumns) {
@@ -65,6 +72,12 @@ public class TypeListFieldEditor extends
gd.verticalAlignment = GridData.FILL;
typeList.setLayoutData(gd);
+ typeList.addListener(SWT.Selection, new Listener(){
+
+ @Override
+ public void handleEvent(Event event) {
+ checkState();
+ }});
Composite buttonGroup = new Composite(parent, SWT.NONE);
GridLayout buttonLayout = new GridLayout();
@@ -72,10 +85,10 @@ public class TypeListFieldEditor extends
Button addButton = new Button(buttonGroup, SWT.PUSH);
addButton.setText("Add");
- addButton.addSelectionListener(new SelectionListener() {
-
+ addButton.addListener(SWT.Selection, new Listener() {
+
@Override
- public void widgetSelected(SelectionEvent event) {
+ 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 ...
@@ -85,34 +98,32 @@ public class TypeListFieldEditor extends
if (typeName != null) {
typeList.add(typeName);
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent event) {
- // will never be called
+ }
}
});
+ addButton.setLayoutData(GridDataFactory.fillDefaults().create());
+
// TODO: only enabled when an item in the list is selected
- Button removeButton = new Button(buttonGroup, SWT.PUSH);
+ removeButton = new Button(buttonGroup, SWT.PUSH);
removeButton.setText("Remove");
- removeButton.addSelectionListener(new SelectionListener() {
-
+ removeButton.addListener(SWT.Selection, new Listener() {
+
@Override
- public void widgetSelected(SelectionEvent event) {
+ public void handleEvent(Event event) {
int selectedItem = typeList.getSelectionIndex();
if (selectedItem != -1) {
typeList.remove(selectedItem);
}
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent arg0) {
- // will never be called
+
+ checkState();
+
}
});
+ removeButton.setLayoutData(GridDataFactory.fillDefaults().create());
+
+ checkState();
}
@Override
@@ -135,10 +146,18 @@ public class TypeListFieldEditor extends
@Override
protected void doStore() {
-
+ getPreferenceStore().setValue(getPreferenceName(), listToString(typeList.getItems()));
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 3;
+ }
+
+ public static String listToString(String types[]) {
StringBuilder typeListString = new StringBuilder();
- for (String type : typeList.getItems()) {
+ for (String type : types) {
typeListString.append(type);
typeListString.append(",");
}
@@ -147,13 +166,7 @@ public class TypeListFieldEditor extends
typeListString.setLength(typeListString.length() - 1);
}
- // create string value ...
- getPreferenceStore().setValue(getPreferenceName(), typeListString.toString());
- }
-
- @Override
- public int getNumberOfControls() {
- return 3;
+ return typeListString.toString();
}
public static String[] getTypeList(String typeListString) {
Added: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java?rev=1210891&view=auto
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java (added)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java Tue Dec 6 12:59:28 2011
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+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.Group;
+import org.eclipse.swt.widgets.Listener;
+
+public class ConfirmedNameDetectionFieldEditor extends FieldEditor {
+
+ private Button forceDetectionButton;
+
+ private Composite optionButtons;
+
+ private Button ignoreShortTokensButton;
+ private Button onlyConsiderAllLetterTokensButton;
+ private Button onlyConsiderInitialCapitalTokensButton;
+
+ public ConfirmedNameDetectionFieldEditor(Composite parent) {
+ super("", "", parent);
+ }
+
+ @Override
+ protected void adjustForNumColumns(int numColumns) {
+ }
+
+ private void checkState() {
+ ignoreShortTokensButton.setEnabled(forceDetectionButton.getSelection());
+ onlyConsiderAllLetterTokensButton.setEnabled(forceDetectionButton.getSelection());
+ onlyConsiderInitialCapitalTokensButton.setEnabled(forceDetectionButton.getSelection());
+ }
+
+ @Override
+ protected void doFillIntoGrid(Composite parent, int numColumns) {
+
+ Group buttonGroup = new Group(parent, SWT.NONE);
+ buttonGroup.setText("Forced name detection");
+ buttonGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
+ buttonGroup.setLayout(new GridLayout());
+
+ forceDetectionButton = new Button(buttonGroup, SWT.CHECK);
+ forceDetectionButton.setText("Force the detection of existing names");
+ forceDetectionButton.addListener(SWT.Selection, new Listener(){
+
+ @Override
+ public void handleEvent(Event event) {
+ checkState();
+ }});
+
+ optionButtons = new Composite(buttonGroup, SWT.NONE);
+ optionButtons.setLayout(new GridLayout());
+
+ // Ignore short tokens
+ ignoreShortTokensButton = new Button(optionButtons, SWT.CHECK);
+ ignoreShortTokensButton.setText("Ignore short tokens");
+
+ // Only consider all letter tokens
+ onlyConsiderAllLetterTokensButton = new Button(optionButtons, SWT.CHECK);
+ onlyConsiderAllLetterTokensButton.setText("Only consider all letter tokens");
+
+ onlyConsiderInitialCapitalTokensButton = new Button(optionButtons, SWT.CHECK);
+ onlyConsiderInitialCapitalTokensButton.setText("Only consider initial capital tokens");
+
+ // TODO:
+ // Ignore ambiguous tokens
+ }
+
+ @Override
+ protected void doLoad() {
+ if (forceDetectionButton != null) {
+
+ forceDetectionButton.setSelection(
+ getPreferenceStore().getBoolean(ENABLE_CONFIRMED_NAME_DETECTION));
+
+ ignoreShortTokensButton.setSelection(
+ getPreferenceStore().getBoolean(IGNORE_SHORT_TOKENS));
+
+ onlyConsiderAllLetterTokensButton.setSelection(
+ getPreferenceStore().getBoolean(ONLY_CONSIDER_ALL_LETTER_TOKENS));
+
+ onlyConsiderInitialCapitalTokensButton.setSelection(
+ getPreferenceStore().getBoolean(ONLY_CONSIDER_INITIAL_CAPITAL_TOKENS));
+
+ checkState();
+ }
+ }
+
+ @Override
+ protected void doLoadDefault() {
+ }
+
+ @Override
+ protected void doStore() {
+ getPreferenceStore().setValue(
+ ENABLE_CONFIRMED_NAME_DETECTION, forceDetectionButton.getSelection());
+
+ getPreferenceStore().setValue(
+ IGNORE_SHORT_TOKENS, ignoreShortTokensButton.getSelection());
+
+ getPreferenceStore().setValue(ONLY_CONSIDER_ALL_LETTER_TOKENS,
+ onlyConsiderAllLetterTokensButton.getSelection());
+
+ getPreferenceStore().setValue( ONLY_CONSIDER_INITIAL_CAPITAL_TOKENS,
+ onlyConsiderInitialCapitalTokensButton.getSelection());
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 1;
+ }
+}
Propchange: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/ConfirmedNameDetectionFieldEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java?rev=1210891&view=auto
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java (added)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java Tue Dec 6 12:59:28 2011
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.caseditor.namefinder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
+import org.apache.opennlp.caseditor.TypeListFieldEditor;
+import org.apache.uima.cas.TypeSystem;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.swt.SWT;
+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;
+
+/**
+ * Field editor for configuring name finder models and corresponding types.
+ */
+
+// TODO:
+// Model type names are encoded into two string and saved to the pref store.
+// That should be enhanced and in a reliable way coded into one string.
+
+class NameFinderModelFieldEditor extends FieldEditor {
+
+ private static final String MODEL_PATH_KEY = "ModelPathKey";
+ private static final String TYPE_NAME_KEY = "TypeNameKey";
+
+ private TypeSystem ts;
+
+ private Table modelTypeTable;
+ private Button editButton;
+ private Button removeButton;
+
+ NameFinderModelFieldEditor(String name, String labelText, TypeSystem ts, Composite parent) {
+ super(name, labelText, parent);
+ this.ts = ts;
+ }
+
+ @Override
+ protected void adjustForNumColumns(int numColumns) {
+ }
+
+ private void createTableItem(String modelPath, String typeName) {
+ TableItem item = new TableItem(modelTypeTable, SWT.NONE);
+ item.setData(MODEL_PATH_KEY, modelPath);
+ item.setText(0, modelPath);
+
+ item.setData(TYPE_NAME_KEY, typeName);
+ item.setText(1, typeName);
+ }
+
+ private void checkState() {
+ editButton.setEnabled(modelTypeTable.getSelectionCount() == 1);
+ removeButton.setEnabled(modelTypeTable.getSelectionCount() == 1);
+ }
+
+ @Override
+ protected void doFillIntoGrid(final Composite parent, int numColumns) {
+ Label messageLabel = getLabelControl(parent);
+
+ GridData messageGridDate = new GridData();
+ messageGridDate.horizontalSpan = numColumns;
+ messageLabel.setLayoutData(messageGridDate);
+
+ modelTypeTable = new Table(parent, SWT.BORDER);
+
+ GridData gd = new GridData();
+ gd.horizontalSpan = numColumns - 1;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ gd.verticalAlignment = GridData.FILL;
+ modelTypeTable.setLayoutData(gd);
+
+ modelTypeTable.setLinesVisible(true);
+ modelTypeTable.setHeaderVisible(true);
+
+ modelTypeTable.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ checkState();
+ }});
+
+ TableColumn modelColumn = new TableColumn(modelTypeTable, SWT.NONE);
+ modelColumn.setText("Model Path");
+ modelColumn.setWidth(220);
+
+ TableColumn typeColumn = new TableColumn(modelTypeTable, SWT.NONE);
+ typeColumn.setText("Type");
+ typeColumn.setWidth(220);
+
+ Composite buttonGroup = new Composite(parent, SWT.NONE);
+ GridLayout buttonLayout = new GridLayout();
+ buttonGroup.setLayout(buttonLayout);
+
+ Button addButton = new Button(buttonGroup, SWT.PUSH);
+ 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);
+
+ 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);
+
+ TableItem item = modelTypeTable.getItem(modelTypeTable.getSelectionIndex());
+
+ 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());
+
+ 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();
+ }});
+
+ checkState();
+ }
+
+ @Override
+ protected void doLoad() {
+ if (modelTypeTable != null) {
+ String modelPathsString = getPreferenceStore().getString(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH);
+ String modelPaths[] = TypeListFieldEditor.getTypeList(modelPathsString);
+
+ String typeNamesString = getPreferenceStore().getString(OpenNLPPreferenceConstants.NAME_TYPE);
+ String typeNames[] = TypeListFieldEditor.getTypeList(typeNamesString);
+
+ // Don't load anything ...
+ if (modelPaths.length != typeNames.length) {
+ // TODO: Log error message
+ return;
+ }
+
+ for (int i = 0; i < modelPaths.length; i++) {
+ createTableItem(modelPaths[i], typeNames[i]);
+ }
+ }
+ }
+
+ @Override
+ protected void doLoadDefault() {
+ // there is no default
+ }
+
+ @Override
+ protected void doStore() {
+
+ List<String> modelPaths = new ArrayList<String>();
+ List<String> typeNames = new ArrayList<String>();
+
+ // iterate over table
+ for (int i = 0; i < modelTypeTable.getItemCount(); i++) {
+ TableItem item = modelTypeTable.getItem(i);
+
+ String modelPath = (String) item.getData(MODEL_PATH_KEY);
+ modelPaths.add(modelPath);
+
+ String typeName = (String) item.getData(TYPE_NAME_KEY);
+ typeNames.add(typeName);
+ }
+
+ String modelPathsString = TypeListFieldEditor.listToString(modelPaths.toArray(new String[modelPaths.size()]));
+ String typeNamesString = TypeListFieldEditor.listToString(typeNames.toArray(new String[typeNames.size()]));
+
+ getPreferenceStore().setValue(OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH, modelPathsString);
+ getPreferenceStore().setValue(OpenNLPPreferenceConstants.NAME_TYPE, typeNamesString);
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 3;
+ }
+}
Propchange: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelFieldEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java?rev=1210891&view=auto
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java (added)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java Tue Dec 6 12:59:28 2011
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * 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
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.caseditor.namefinder;
+
+import org.apache.uima.cas.TypeSystem;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog to add or edit a model and type mapping.
+ */
+// TODO: Add validation
+public class NameFinderModelInputDialog extends Dialog {
+
+ private TypeSystem ts;
+
+ private String dialogTitle;
+
+ private String modelTextValue = "";
+ private String typeNameTextValue = "";
+
+ private Text modelText;
+
+ private Text typeNameText;
+
+ public NameFinderModelInputDialog(Shell parentShell, String dialogTitle, TypeSystem ts) {
+ super(parentShell);
+ this.dialogTitle = dialogTitle;
+
+ this.ts = ts;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+
+ if (dialogTitle != null) {
+ newShell.setText(dialogTitle);
+ }
+
+ newShell.setSize(600, 150);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ Composite dialogArea = (Composite) super.createDialogArea(parent);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ dialogArea.setLayout(layout);
+
+ Label modelLabel = new Label(dialogArea, SWT.NONE);
+ modelLabel.setText("Model path");
+
+ modelText = new Text(dialogArea, SWT.BORDER);
+ modelText.setLayoutData(GridDataFactory.swtDefaults().
+ align(SWT.FILL, SWT.CENTER).grab(true, false).create());
+ modelText.setText(modelTextValue);
+ modelText.addListener(SWT.Selection, new Listener(){
+
+ @Override
+ public void handleEvent(Event event) {
+ modelTextValue = modelText.getText();
+ }});
+
+// TODO: Implement browse button
+// Button browseButton = new Button(dialogArea, SWT.PUSH);
+// browseButton.setText("Browse...");
+
+ Label typeNameLabel = new Label(dialogArea, SWT.NONE);
+ typeNameLabel.setText("Type name");
+
+ typeNameText = new Text(dialogArea, SWT.BORDER);
+ 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();
+ }
+ });
+
+ return dialogArea;
+ }
+
+ public void setModelPath(String value) {
+ modelTextValue = value;
+ }
+
+ String getModelPath() {
+ return modelTextValue;
+ }
+
+ String getTypeName() {
+ return typeNameTextValue;
+ }
+
+ public void setTypeName(String value) {
+ typeNameTextValue = value;
+ }
+}
Propchange: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderModelInputDialog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java?rev=1210891&r1=1210890&r2=1210891&view=diff
==============================================================================
--- incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java (original)
+++ incubator/opennlp/sandbox/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderPreferencePage.java Tue Dec 6 12:59:28 2011
@@ -20,9 +20,7 @@ package org.apache.opennlp.caseditor.nam
import org.apache.opennlp.caseditor.OpenNLPPreferenceConstants;
import org.apache.opennlp.caseditor.TypeListFieldEditor;
import org.apache.uima.cas.TypeSystem;
-import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -47,20 +45,25 @@ public class NameFinderPreferencePage ex
"Additional Sentence Types", ts, getFieldEditorParent());
addField(additionalSentenceTypes);
- StringFieldEditor modelPath = new StringFieldEditor(
- OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH,
- "Model Path(es)", getFieldEditorParent());
- addField(modelPath);
+ // TODO: We need a new input control for this one
+ // user needs to enter model path
+ // and type at the same time
- StringFieldEditor nameType = new StringFieldEditor(
- OpenNLPPreferenceConstants.NAME_TYPE,
- "Name Type(s)", getFieldEditorParent());
- addField(nameType);
+ NameFinderModelFieldEditor modelPath = new NameFinderModelFieldEditor(
+ OpenNLPPreferenceConstants.NAME_FINDER_MODEL_PATH,
+ "Model paths and types", ts, getFieldEditorParent());
+ addField(modelPath);
// TODO: We need a view settings which are enabled/disabled based on this one
- BooleanFieldEditor enableRecallBoosting = new BooleanFieldEditor(
- OpenNLPPreferenceConstants.ENABLE_CONFIRMED_NAME_DETECTION,
- "Enable the detection of confirmed names", getFieldEditorParent());
- addField(enableRecallBoosting);
+// BooleanFieldEditor enableRecallBoosting = new BooleanFieldEditor(
+// OpenNLPPreferenceConstants.ENABLE_CONFIRMED_NAME_DETECTION,
+// "Force the detection of confirmed names", getFieldEditorParent());
+// addField(enableRecallBoosting);
+
+ ConfirmedNameDetectionFieldEditor forceNameDetection =
+ new ConfirmedNameDetectionFieldEditor(getFieldEditorParent());
+ addField(forceNameDetection);
+ // Add a group
+ // Other options should be have an indent ...
}
}