You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/08/12 12:32:54 UTC
svn commit: r1157037 [10/10] - in
/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler: ./ .settings/
META-INF/ icons/ schema/ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/ja...
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,222 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.textmarker.textruler.TextRulerPlugin;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerFactory;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerParameter;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Control;
+
+public class LearnerConfigurator {
+
+ Map<String, Control> paramControls = new HashMap<String, Control>();
+
+ private TextRulerLearnerController algorithmController;
+
+ public LearnerConfigurator(TextRulerLearnerController algController) {
+ algorithmController = algController;
+ // createWidgetsForAlgorithm();
+ }
+
+ public TextRulerLearnerController getController() {
+ return algorithmController;
+ }
+
+ // protected void createWidgetsForAlgorithm() {
+ // TextRulerLearnerFactory f = algorithmController.getFactory();
+ // TextRulerLearnerParameter[] params = f.getAlgorithmParameters();
+ // if (params == null)
+ // return;
+ //
+ // for (TextRulerLearnerParameter p : params) {
+ // Label l = new Label(this, SWT.NONE);
+ // l.setText(p.name);
+ // Control theControl = null;
+ // switch (p.type) {
+ // case ML_BOOL_PARAM: {
+ // theControl = new Button(this, SWT.CHECK | SWT.LEFT);
+ // break;
+ // }
+ //
+ // case ML_FLOAT_PARAM:
+ // case ML_INT_PARAM:
+ // case ML_STRING_PARAM: {
+ // theControl = new Text(this, SWT.SINGLE | SWT.BORDER);
+ // ((Text) theControl).addModifyListener(new ModifyListener() {
+ // public void modifyText(ModifyEvent e) {
+ // // without that listener, the text fields forget the
+ // // last change when leaving with tab! don't know why!
+ // // we also MUST call getText() otherwise the changes in
+ // // the field are lost (what is this???!!)
+ // Text t = (Text) e.widget;
+ // t.getText();
+ // }
+ // });
+ // GridData d = new GridData();
+ // d.widthHint = 150;
+ // d.minimumWidth = 40;
+ // theControl.setLayoutData(d);
+ // break;
+ // }
+ //
+ // case ML_SELECT_PARAM: {
+ // Combo combo = new Combo(this, SWT.READ_ONLY);
+ // if (p.selectValues != null)
+ // for (MLParameterSelectValue v : p.selectValues) {
+ // combo.add(v.name);
+ // }
+ // theControl = combo;
+ // break;
+ // }
+ // }
+ // if (theControl != null) {
+ // theControl.setData(p);
+ // }
+ // paramControls.put(p.id, theControl);
+ // }
+ // }
+
+ public String getID() {
+ return algorithmController.getID();
+ }
+
+ // public Map<String, Object> getCurrentParameterSettings() {
+ // Map<String, Object> result = new HashMap<String, Object>();
+ // for (String key : paramControls.keySet()) {
+ // Control c = paramControls.get(key);
+ // TextRulerLearnerParameter p = (TextRulerLearnerParameter) c.getData();
+ // try {
+ // switch (p.type) {
+ // case ML_BOOL_PARAM: {
+ // result.put(key, new Boolean(((Button) c).getSelection()));
+ // break;
+ // }
+ // case ML_INT_PARAM: {
+ // result.put(key, new Integer(((Text) c).getText()));
+ // break;
+ // }
+ // case ML_FLOAT_PARAM: {
+ // result.put(key, new Float(((Text) c).getText()));
+ // break;
+ // }
+ // case ML_STRING_PARAM: {
+ // result.put(key, new String(((Text) c).getText()));
+ // break;
+ // }
+ // case ML_SELECT_PARAM: {
+ // int index = ((Combo) c).getSelectionIndex();
+ // if (index >= 0 && p.selectValues != null && index < p.selectValues.length) {
+ // result.put(key, new String(p.selectValues[index].id));
+ // }
+ // break;
+ // }
+ // }
+ // } catch (NumberFormatException e) {
+ // // todo !
+ // }
+ // }
+ // return result;
+ // }
+
+ public Map<String, Object> getCurrentParameterSettings() {
+ Map<String, Object> result = new HashMap<String, Object>();
+ IPreferenceStore store = TextRulerPlugin.getDefault().getPreferenceStore();
+ TextRulerLearnerFactory f = algorithmController.getFactory();
+ TextRulerLearnerParameter[] params = f.getAlgorithmParameters();
+ if (params != null) {
+ for (int i = 0; i < params.length; i++) {
+ TextRulerLearnerParameter p = params[i];
+ String id = algorithmController.getID() + "." + p.id;
+ switch (p.type) {
+ case ML_BOOL_PARAM: {
+ result.put(p.id, store.getBoolean(id));
+ break;
+ }
+ case ML_FLOAT_PARAM: {
+ result.put(p.id, store.getFloat(id));
+ break;
+ }
+ case ML_INT_PARAM: {
+ result.put(p.id, store.getInt(id));
+ break;
+ }
+ case ML_STRING_PARAM: {
+ result.put(p.id, store.getString(id));
+ break;
+ }
+ // case ML_SELECT_PARAM: {
+ // break;
+ // }
+ case ML_SELECT_PARAM:
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ // public void setCurrentParameterSettings(Map<String, Object> params) {
+ // if (params == null)
+ // return;
+ // for (String key : paramControls.keySet())
+ // if (params.containsKey(key)) {
+ // Control c = paramControls.get(key);
+ // TextRulerLearnerParameter p = (TextRulerLearnerParameter) c.getData();
+ // switch (p.type) {
+ // case ML_BOOL_PARAM: {
+ // ((Button) c).setSelection(((Boolean) params.get(key)).booleanValue());
+ // break;
+ // }
+ //
+ // case ML_INT_PARAM:
+ // case ML_FLOAT_PARAM:
+ // case ML_STRING_PARAM: {
+ // ((Text) c).setText(params.get(key).toString());
+ // break;
+ // }
+ //
+ // case ML_SELECT_PARAM: {
+ // if (p.selectValues != null) {
+ // String value = (String) params.get(key);
+ // for (int i = 0; i < p.selectValues.length; i++) {
+ // if (p.selectValues[i].id.equals(value)) {
+ // ((Combo) c).select(i);
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ // @Override
+ // public void setEnabled(boolean flag) {
+ // super.setEnabled(flag);
+ // for (Control c : paramControls.values())
+ // c.setEnabled(flag);
+ // }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/LearnerConfigurator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,245 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import java.awt.Toolkit;
+import java.util.ArrayList;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+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.Control;
+import org.eclipse.swt.widgets.Display;
+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.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+public class SelectTypesDialog extends Dialog implements Listener {
+
+ private Shell shell;
+
+ private Text typeNameUI;
+
+ private Table matchingTypesUI;
+
+ // private Table nameSpacesUI;
+
+ public String typeName = "error-TypeName-never-set";
+
+ private ArrayList<String> types;
+
+ private Button okButton;
+
+ private Button cancelButton;
+
+ private AddRemoveList list;
+
+ public SelectTypesDialog(Shell shell, ArrayList<String> types, AddRemoveList list) {
+ super(shell);
+ this.shell = shell;
+ this.types = types;
+ this.list = list;
+ createDialogArea();
+ init();
+ }
+
+ protected Control createDialogArea() {
+ Composite mainArea = (Composite) createDialogArea(shell);
+ createWideLabel(mainArea, " Type Name:");
+
+ typeNameUI = newText(mainArea, SWT.SINGLE, "Specify the type name");
+ typeNameUI.addListener(SWT.Modify, this);
+
+ createWideLabel(mainArea, " Matching Types:");
+
+ matchingTypesUI = newTable(mainArea, SWT.MULTI);
+ ((GridData) matchingTypesUI.getLayoutData()).heightHint = 250;
+ ((GridData) matchingTypesUI.getLayoutData()).minimumHeight = 100;
+ typeNameUI.addListener(SWT.Selection, this);
+
+ displayFilteredTypes("");
+ createButtonBar(mainArea);
+ return mainArea;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = 3;
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ @Override
+ protected Control createButtonBar(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 0;
+ layout.makeColumnsEqualWidth = true;
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ composite.setLayout(layout);
+ GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ composite.setLayoutData(data);
+
+ createButtonsForButtonBar(composite);
+ return composite;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ okButton = createButton(parent, IDialogConstants.OK_ID, "OK", true);
+ cancelButton = createButton(parent, IDialogConstants.CANCEL_ID, " Cancel ", false);
+ okButton.setEnabled(false);
+ }
+
+ private void init() {
+
+ okButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ TableItem[] types = matchingTypesUI.getSelection();
+ ArrayList<String> selection = new ArrayList<String>();
+ for (TableItem item : types) {
+ selection.add(item.getText());
+ }
+ list.addAll(selection);
+ shell.dispose();
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ shell.dispose();
+ }
+ });
+
+ Display display = Display.getDefault();
+ int width = 300;
+ int height = 400;
+ shell.setSize(width, height);
+ shell.setMinimumSize(200, 250);
+ shell.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - width) / 2, (Toolkit
+ .getDefaultToolkit().getScreenSize().height - height) / 2);
+ shell.setLayout(new FillLayout());
+ shell.layout();
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+
+ protected Label createWideLabel(Composite parent, String message) {
+ Label label = null;
+ label = new Label(parent, SWT.WRAP);
+ label.setText(null != message ? message : "");
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ data.verticalAlignment = SWT.CENTER;
+ label.setLayoutData(data);
+ return label;
+ }
+
+ protected Text newText(Composite parent, int style, String tip) {
+ Text t = new Text(parent, style | SWT.BORDER);
+ t.setToolTipText(tip);
+ t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ t.addListener(SWT.KeyUp, this);
+ t.addListener(SWT.MouseUp, this);
+ return t;
+ }
+
+ protected Table newTable(Composite parent, int style) {
+ Table table = new Table(parent, style | SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ table.setLayoutData(gd);
+ table.addListener(SWT.Selection, this);
+ table.addListener(SWT.KeyUp, this);
+ return table;
+ }
+
+ private void displayFilteredTypes(String aTypeName) {
+ matchingTypesUI.setRedraw(false);
+ matchingTypesUI.removeAll();
+ String topEntry = "";
+ aTypeName = aTypeName.toLowerCase();
+ for (String type : types) {
+ String candidateTypeName = type.toLowerCase();
+ if (aTypeName.trim().equals("") || candidateTypeName.indexOf(aTypeName) != -1) {
+
+ if (topEntry.equals("")) {
+ topEntry = type;
+ }
+ TableItem item = new TableItem(matchingTypesUI, SWT.NULL);
+ item.setText(type);
+ }
+ }
+ // if (matchingTypesUI.getItemCount() > 0) {
+ // matchingTypesUI.select(0);
+ // displayNameSpacesForSelectedItem(topEntry);
+ // }
+ matchingTypesUI.setRedraw(true);
+ }
+
+ // private void displayNameSpacesForSelectedItem(String topEntry) {
+ // nameSpacesUI.removeAll();
+ // TableItem item = new TableItem(nameSpacesUI, SWT.NULL);
+ // item.setText(topEntry);
+ // if (nameSpacesUI.getItemCount() > 0) {
+ // nameSpacesUI.select(0);
+ // }
+ // nameSpacesUI.setRedraw(true);
+ // }
+
+ public void handleEvent(Event event) {
+ if (event.widget == typeNameUI && event.type == SWT.Modify) {
+ displayFilteredTypes(typeNameUI.getText());
+ }
+
+ else if (event.widget == matchingTypesUI && event.type == SWT.Selection) {
+ okButton.setEnabled(0 < matchingTypesUI.getSelectionCount());
+ }
+ }
+
+ public boolean isValid() {
+ return true;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/SelectTypesDialog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class StartHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TextRulerView theView = (TextRulerView) HandlerUtil.getActivePart(event);
+ theView.startPressed();
+ return null;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class StartStopHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TextRulerView theView = (TextRulerView) HandlerUtil.getActivePart(event);
+ theView.onStartStopPressed();
+ return null;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StartStopHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import org.apache.uima.textmarker.textruler.extension.TextRulerController;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+
+public class StopHandler implements IHandler {
+
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TextRulerController.abort();
+ return null;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/StopHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,89 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import org.apache.uima.textmarker.ide.core.TextMarkerLanguageToolkit;
+import org.eclipse.dltk.internal.ui.editor.ScriptSourceViewer;
+import org.eclipse.dltk.ui.DLTKUILanguageManager;
+import org.eclipse.dltk.ui.IDLTKUILanguageToolkit;
+import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
+import org.eclipse.dltk.ui.text.ScriptTextTools;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class TextRulerResultsView extends ViewPart {
+
+ public static final String ID = "org.apache.uima.textmarker.textruler.TextRulerResultsView";
+
+ protected SourceViewer viewer;
+
+ public TextRulerResultsView() {
+ super();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ IDLTKUILanguageToolkit toolkit = DLTKUILanguageManager
+ .getLanguageToolkit(TextMarkerLanguageToolkit.getDefault().getNatureId());
+ final ScriptTextTools textTools = toolkit.getTextTools();
+ IPreferenceStore store = toolkit.getCombinedPreferenceStore();
+ viewer = new ScriptSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL
+ | SWT.H_SCROLL, store);
+ ScriptSourceViewerConfiguration configuration = textTools.createSourceViewerConfiguraton(store,
+ (ITextEditor) null);
+ viewer.configure(configuration);
+ viewer.setDocument(new Document("No results available yet!"));
+ }
+
+ public void setViewTitle(String title) {
+ setPartName(title);
+ }
+
+ public void setInformation(String content) {
+ if (content == null) {
+ viewer.setInput(null);
+ return;
+ }
+ IDocument doc = new Document(content);
+ IDLTKUILanguageToolkit uiToolkit = DLTKUILanguageManager
+ .getLanguageToolkit(TextMarkerLanguageToolkit.getDefault().getNatureId());
+ ScriptTextTools textTools = uiToolkit.getTextTools();
+ if (textTools != null) {
+ textTools.setupDocumentPartitioner(doc, uiToolkit.getPartitioningId());
+ }
+ viewer.setInput(doc);
+ }
+
+ public void setResultContents(String str) {
+ setInformation(str);
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerResultsView.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,332 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.textmarker.textruler.extension.TextRulerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerControllerDelegate;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearner.TextRulerLearnerState;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerPreprocessor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+public class TextRulerView extends ViewPart implements TextRulerControllerDelegate {
+
+ public static final String ID = "org.apache.uima.textmarker.ml.MainView";
+
+ private TextRulerViewComposite viewContent;
+
+ private IMemento memento;
+
+ public TextRulerView() {
+ super();
+ }
+
+ public void errorAlert(String message) {
+ MessageBox alert = new MessageBox(getSite().getShell(), SWT.OK | SWT.ICON_ERROR);
+ alert.setMessage(message);
+ alert.open();
+ }
+
+ public boolean yesNoAlert(String message) {
+ MessageBox alert = new MessageBox(getSite().getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
+ alert.setMessage(message);
+ int result = alert.open();
+ return result == SWT.OK; // THIS DOES NOT WORK IN OS X !!??
+ }
+
+ public void onStartStopPressed() {
+ if (TextRulerController.isRunning()) {
+ // if
+ // (yesNoAlert("Do you really want to abort the current learning processes?"))
+ // TODO does not work in OS X since alert.open always returns 256
+ // (=cancel) no matter which button was pressed...
+ TextRulerController.abort();
+ } else {
+ startPressed();
+ }
+ updateEnabledStatus();
+ }
+
+ public void startPressed() {
+ if (!TextRulerController.isRunning()) {
+ String inputDir = viewContent.getInputDirectoryPath().trim();
+ String additionalDir = viewContent.getAdditionalDirectoryPath().trim();
+ String preProcTMFile = viewContent.getPreprocessorTMFile().trim();
+
+ File inputFile = new File(inputDir);
+ if (!inputFile.exists()) {
+ AddRemoveList.printErrorDialog("The training data directory was not found!");
+ return;
+ }
+
+ File additionalFile = new File(additionalDir);
+ // if (!additionalFile .exists()) {
+ // AddRemoveList.printErrorDialog("The additional data directory was not found!");
+ // return;
+ // }
+
+ File preFile = new File(preProcTMFile);
+ if (!preFile.exists()) {
+ AddRemoveList.printErrorDialog("The preprocessing script was not found!");
+ return;
+ }
+
+ String[] slotNames = viewContent.getSlotNames();
+ for (String string : slotNames) {
+ System.out.println(string);
+ }
+ String[] filterArray = viewContent.getFilters();
+ Set<String> filters = new HashSet<String>();
+ for (String s : filterArray)
+ filters.add(s);
+
+ if (slotNames.length == 0 || inputDir.length() == 0 || preProcTMFile.length() == 0) {
+ errorAlert("Please specify at least one slot type, the input directory and the preprocessing file (this is needed even if preprocessing is skipped)!");
+ return;
+ }
+ File dir = new File(inputDir);
+ if (!dir.exists() || !dir.isDirectory()) {
+ errorAlert("The specified input directory could not be found!");
+ return;
+ }
+
+ Object[] algs = viewContent.getAlgListViewer().getCheckedElements();
+
+ // reset all:
+ for (TextRulerLearnerController controller : TextRulerController.getAvailableControllers())
+ controller.setEnabled(false);
+
+ // enable the checked ones...
+ for (Object i : algs) {
+ TextRulerLearnerController c = ((TextRulerLearnerController) i);
+
+ c.setEnabled(true);
+
+ IViewPart resultView;
+
+ if ((resultView = getView(TextRulerResultsView.ID, c.getID())) == null) {
+ try {
+ IViewPart view = PlatformUI
+ .getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage()
+ .showView(TextRulerResultsView.ID, ((TextRulerLearnerController) i).getID(),
+ IWorkbenchPage.VIEW_CREATE);
+ ((TextRulerResultsView) view).setViewTitle(c.getName() + " - Results");
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ } else {
+ ((TextRulerResultsView) resultView).setViewTitle(c.getName() + " - Results");
+ }
+ }
+
+ if (TextRulerController.enabledAlgorithmsCount() > 0) {
+ TextRulerController.start(inputDir, additionalDir, preProcTMFile, slotNames, filters, this,
+ viewContent.getCurrentAlgorithmParameters(), viewContent.getSkipPreprocessing());
+
+ // BATCH_STUFF
+ // preprocessorTMFile = preProcTMFile;
+ // TextRulerView.slotNames = slotNames;
+ // TextRulerView.filters = filters;
+ // algParams = viewContent.getCurrentAlgorithmParameters();
+ // skipPreprocessing = viewContent.getSkipPreprocessing();
+ // batchNext();
+ } else
+ errorAlert("No algorithm has been activated for learning!");
+ }
+ }
+
+ public void updateEnabledStatus() {
+ boolean isRunning = TextRulerController.isRunning();
+ viewContent.setEnabled(!isRunning);
+ }
+
+ public void asyncUpdateGlobalStatus(final String str) {
+ viewContent.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ viewContent.setGlobalStatusString(str);
+ updateEnabledStatus();
+ }
+ });
+ }
+
+ public void asyncUpdateList(final TextRulerLearnerController algController,
+ final boolean ruleBaseChanged) {
+ viewContent.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ updateList(algController, ruleBaseChanged);
+ }
+ });
+ }
+
+ public void updateList(TextRulerLearnerController algController, boolean ruleBaseChanged) {
+ viewContent.getAlgListViewer().refresh(true, true);
+ if (algController != null && ruleBaseChanged) {
+ TextRulerResultsView textRulerResultsView = (TextRulerResultsView) getView(
+ TextRulerResultsView.ID, algController.getID());
+ if (textRulerResultsView != null) {
+ textRulerResultsView.setResultContents(algController.getCurrentResultString());
+ }
+ }
+ }
+
+ public synchronized void algorithmDidEnd(TextRulerLearnerController algController) {
+ asyncUpdateList(algController, true);
+
+ // // BATCH_STUFF
+ // if (!TextRulerController.isRunning() &&
+ // !TextRulerController.shouldAbort())
+ // {
+ // viewContent.getDisplay().asyncExec(new Runnable(){
+ // public void run() {
+ // batchNext();
+ // }
+ // });
+ // }
+ }
+
+ public static IViewPart getView(String id, String id2) {
+ IViewReference viewReferences[] = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().getViewReferences();
+ for (int i = 0; i < viewReferences.length; i++) {
+ if (id.equals(viewReferences[i].getId()) && id2.equals(viewReferences[i].getSecondaryId())) {
+ return viewReferences[i].getView(false);
+ }
+ }
+ return null;
+ }
+
+ public synchronized void algorithmStatusUpdate(TextRulerLearnerController algController,
+ String statusString, TextRulerLearnerState state, boolean ruleBaseChanged) {
+ asyncUpdateList(algController, ruleBaseChanged);
+ }
+
+ public void preprocessorStatusUpdate(TextRulerPreprocessor p, String statusString) {
+ asyncUpdateGlobalStatus("Preprocessing... " + statusString);
+ }
+
+ public void globalStatusUpdate(String str) {
+ asyncUpdateGlobalStatus(str);
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ viewContent = new TextRulerViewComposite(parent, SWT.NULL, this);
+ if (memento != null) {
+ viewContent.restoreState(memento);
+ memento = null;
+ }
+ }
+
+ @Override
+ public void setFocus() {
+ viewContent.setFocus();
+ }
+
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ this.memento = memento;
+ super.init(site, memento);
+ }
+
+ @Override
+ public void saveState(IMemento memento) {
+ viewContent.saveState(memento);
+ }
+
+ // BATCH_STUFF
+ // private static String preprocessorTMFile;
+ // private static String[] slotNames;
+ // private static Set<String> filters;
+ // private static Map<String, Map<String, Object>> algParams;
+ // private static boolean skipPreprocessing;
+ //
+ // int foldNumber = 0;
+ // int slotNumber = -1;
+ //
+ // private static final int kFoldSize = 1;
+ //
+ // public void batchNext()
+ // {
+ // slotNumber++;
+ // if (slotNumber > slotNames.length-1)
+ // {
+ // slotNumber = 0;
+ // foldNumber ++;
+ // if (foldNumber > (kFoldSize-1))
+ // {
+ // TextRulerToolkit.log("DONE WITH ALL STUFF, YAAAA!");
+ // return; // stop
+ // }
+ // }
+ //
+ // // if (foldNumber == 2 && (slotNumber == 0 || slotNumber==1)) // SKIP for
+ // now!
+ // // {
+ // // algorithmDidEnd(null);
+ // // return;
+ // // }
+ //
+ // TextRulerToolkit.log("******* ******* ******* ******* NEW BATCH TASK:");
+ // TextRulerToolkit.log("Fold: "+foldNumber);
+ // TextRulerToolkit.log("Slot: "+slotNumber);
+ // TextRulerToolkit.log("******* ******* ******* *******");
+ //
+ // // String inFolder =
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100/10fold/"+foldNumber+"/training/withtags";
+ // // String inFolder =
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/halfhalf/"+foldNumber+"/training/withtags";
+ // String inFolder =
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/9010_middle/"+foldNumber+"/training/withtags";
+ // String[] slots = new String[slotNames.length];
+ // int otherI = 1;
+ // for (int i=0; i<slotNames.length; i++)
+ // {
+ // if (i==slotNumber)
+ // slots[0] = slotNames[i];
+ // else
+ // {
+ // slots[otherI] = slotNames[i];
+ // otherI++;
+ // }
+ //
+ // }
+ // for (String s : slots)
+ // TextRulerToolkit.log("slot: "+s);
+ // TextRulerToolkit.log(inFolder);
+ // TextRulerController.start(inFolder, preprocessorTMFile, slots, filters,
+ // this, algParams, skipPreprocessing);
+ // }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerView.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,875 @@
+/*
+ * 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.uima.textmarker.textruler.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.textmarker.textruler.TextRulerPlugin;
+import org.apache.uima.textmarker.textruler.core.TextRulerToolkit;
+import org.apache.uima.textmarker.textruler.extension.TextRulerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLizable;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+
+public class TextRulerViewComposite extends org.eclipse.swt.widgets.Composite {
+
+ public class DefaultLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ private final String type;
+
+ public DefaultLabelProvider(String type) {
+ super();
+ this.type = type;
+ }
+
+ public String getColumnText(Object obj, int index) {
+ return getText(obj);
+ }
+
+ public Image getColumnImage(Object obj, int index) {
+ return getImage(obj);
+ }
+
+ @Override
+ public Image getImage(Object obj) {
+ if (type.equals("SlotTypes")) {
+ return images.get("information");
+ } else if (type.equals("FilterTypes")) {
+ return images.get("feature");
+ } else if (type.equals("learner")) {
+ return images.get("learner");
+ }
+ return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+ }
+ }
+
+ private CheckboxTableViewer algListViewer;
+
+ private AddRemoveList slotTypes;
+
+ private AddRemoveList filterTypes;
+
+ private Button skipPreButton;
+
+ private Button dirButton;
+
+ // private Composite configArea;
+
+ private ArrayList<LearnerConfigurator> configurators;
+
+ private Label globalStatusLabel;
+
+ private Label label2;
+
+ private Label label1;
+
+ private Text inputDirectoryText;
+
+ private Label methodsLabel;
+
+ private Label filtersLabel;
+
+ private TextRulerView textRulerView;
+
+ private Button fileChooseButton;
+
+ private static Text preFileText;
+
+ private Label label3;
+
+ private HashMap<String, Image> images;
+
+ private Text additionalDirectoryText;
+
+ private Button additionalButton;
+
+ private Label label4;
+
+ private Label label5;
+
+ private Text testDirectoryText;
+
+ private Button testButton;
+
+ private Button showTestsButton;
+
+ public class ListContentProvider implements IStructuredContentProvider {
+ public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object[] getElements(Object parent) {
+ return TextRulerController.getAvailableControllers().toArray();
+ }
+ }
+
+ public class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+ public String getColumnText(Object obj, int index) {
+ return getText(obj);
+ }
+
+ public Image getColumnImage(Object obj, int index) {
+ return getImage(obj);
+ }
+
+ @Override
+ public Image getImage(Object obj) {
+ return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+ }
+ }
+
+ public class NameSorter extends ViewerSorter {
+ }
+
+ public TextRulerViewComposite(org.eclipse.swt.widgets.Composite parent, int style,
+ TextRulerView textRulerView) {
+ super(parent, style);
+ this.textRulerView = textRulerView;
+
+ initImages();
+ initGUI();
+
+ ScrolledComposite sComp = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL
+ | SWT.H_SCROLL);
+ this.setParent(sComp);
+ sComp.setMinSize(this.getSize());
+ sComp.setContent(this);
+ sComp.setExpandHorizontal(true);
+ sComp.setExpandVertical(true);
+ }
+
+ private void initGUI() {
+ try {
+ this.setLayout(new FormLayout());
+ this.setSize(600, 380);
+
+ configurators = new ArrayList<LearnerConfigurator>();
+
+ label1 = new Label(this, SWT.NONE);
+ FormData label1LData = new FormData();
+ label1LData.left = new FormAttachment(0, 1000, 12);
+ label1LData.top = new FormAttachment(0, 1000, 20);
+ label1LData.width = 109;
+ label1.setLayoutData(label1LData);
+ label1.setText("Training Data:");
+
+ inputDirectoryText = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData inputDirectoryTexLData = new FormData();
+ inputDirectoryTexLData.width = 300;
+ inputDirectoryTexLData.left = new FormAttachment(0, 1000, 126);
+ inputDirectoryTexLData.top = new FormAttachment(0, 1000, 20);
+ inputDirectoryTexLData.right = new FormAttachment(1000, 1000, -110);
+ inputDirectoryText.setLayoutData(inputDirectoryTexLData);
+ inputDirectoryText.setText("");
+ inputDirectoryText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ // without that listener, the text fields forget the
+ // last change when leaving with tab! don't know why!
+ // we also MUST call getText() otherwise the changes in
+ // the field are lost (what is this???!!)
+ Text t = (Text) e.widget;
+ t.getText();
+ }
+ });
+
+ dirButton = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData dirButtoLData = new FormData();
+ dirButtoLData.width = 25;
+ dirButtoLData.height = 25;
+ dirButtoLData.top = new FormAttachment(0, 1000, 18);
+ dirButtoLData.right = new FormAttachment(1000, 1000, -80);
+ dirButton.setLayoutData(dirButtoLData);
+ Image folderIcon = getImage("folder");
+ dirButton.setImage(folderIcon);
+ dirButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ DirectoryDialog dlg = new DirectoryDialog(getShell());
+ dlg.setFilterPath(inputDirectoryText.getText());
+ dlg.setText("Input Directory");
+ dlg.setMessage("Select a directory with input XMI files for the learning algorithms.");
+ String dir = dlg.open();
+ if (dir != null) {
+ inputDirectoryText.setText(dir);
+ }
+ }
+ });
+
+ label4 = new Label(this, SWT.NONE);
+ FormData label4LData = new FormData();
+ label4LData.left = new FormAttachment(0, 1000, 12);
+ label4LData.top = new FormAttachment(0, 1000, 44);
+ label4LData.width = 109;
+ label4.setLayoutData(label4LData);
+ label4.setText("Additional Data:");
+
+ additionalDirectoryText = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData additionalDirectoryTexLData = new FormData();
+ additionalDirectoryTexLData.width = 300;
+ additionalDirectoryTexLData.left = new FormAttachment(0, 1000, 126);
+ additionalDirectoryTexLData.top = new FormAttachment(0, 1000, 44);
+ additionalDirectoryTexLData.right = new FormAttachment(1000, 1000, -110);
+ additionalDirectoryText.setLayoutData(additionalDirectoryTexLData);
+ additionalDirectoryText.setText("");
+ additionalDirectoryText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ // without that listener, the text fields forget the
+ // last change when leaving with tab! don't know why!
+ // we also MUST call getText() otherwise the changes in
+ // the field are lost (what is this???!!)
+ Text t = (Text) e.widget;
+ t.getText();
+ }
+ });
+
+ additionalButton = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData additionalButtoLData = new FormData();
+ additionalButtoLData.width = 25;
+ additionalButtoLData.height = 25;
+ additionalButtoLData.top = new FormAttachment(0, 1000, 42);
+ additionalButtoLData.right = new FormAttachment(1000, 1000, -80);
+ additionalButton.setLayoutData(additionalButtoLData);
+ folderIcon = getImage("folder");
+ additionalButton.setImage(folderIcon);
+ additionalButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ DirectoryDialog dlg = new DirectoryDialog(getShell());
+ dlg.setFilterPath(inputDirectoryText.getText());
+ dlg.setText("Additional Directory");
+ dlg
+ .setMessage("Select a directory with input additional XMI files for the learning algorithms.");
+ String dir = dlg.open();
+ if (dir != null) {
+ additionalDirectoryText.setText(dir);
+ }
+ }
+ });
+
+ label5 = new Label(this, SWT.NONE);
+ FormData label5LData = new FormData();
+ label5LData.left = new FormAttachment(0, 1000, 12);
+ label5LData.top = new FormAttachment(0, 1000, 44 + 24);
+ label5LData.width = 109;
+ label5.setLayoutData(label5LData);
+ label5.setText("Test Data:");
+
+ testDirectoryText = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData testDirectoryTexLData = new FormData();
+ testDirectoryTexLData.width = 300;
+ testDirectoryTexLData.left = new FormAttachment(0, 1000, 126);
+ testDirectoryTexLData.top = new FormAttachment(0, 1000, 44 + 24);
+ testDirectoryTexLData.right = new FormAttachment(1000, 1000, -110);
+ testDirectoryText.setLayoutData(testDirectoryTexLData);
+ testDirectoryText.setText("");
+ testDirectoryText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ // without that listener, the text fields forget the
+ // last change when leaving with tab! don't know why!
+ // we also MUST call getText() otherwise the changes in
+ // the field are lost (what is this???!!)
+ Text t = (Text) e.widget;
+ t.getText();
+ }
+ });
+
+ testButton = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData testButtoLData = new FormData();
+ testButtoLData.width = 25;
+ testButtoLData.height = 25;
+ testButtoLData.top = new FormAttachment(0, 1000, 42 + 24);
+ testButtoLData.right = new FormAttachment(1000, 1000, -80);
+ testButton.setLayoutData(testButtoLData);
+ folderIcon = getImage("folder");
+ testButton.setImage(folderIcon);
+ testButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ DirectoryDialog dlg = new DirectoryDialog(getShell());
+ dlg.setFilterPath(inputDirectoryText.getText());
+ dlg.setText("Test Directory");
+ dlg.setMessage("Select a directory with input test XMI files.");
+ String dir = dlg.open();
+ if (dir != null) {
+ testDirectoryText.setText(dir);
+ }
+ }
+ });
+
+ showTestsButton = new Button(this, SWT.CHECK | SWT.LEFT);
+ FormData showTestsButtoLData = new FormData();
+ showTestsButtoLData.width = 50;
+ showTestsButtoLData.height = 18;
+ showTestsButtoLData.top = new FormAttachment(0, 1000, 42 + 24);
+ showTestsButtoLData.right = new FormAttachment(1000, 1000, -25);
+ showTestsButton.setLayoutData(showTestsButtoLData);
+ showTestsButton.setText("eval");
+
+ label3 = new Label(this, SWT.NONE);
+ FormData label3LData = new FormData();
+ label3LData.width = 103;
+ label3LData.left = new FormAttachment(0, 1000, 12);
+ label3LData.top = new FormAttachment(0, 1000, 68 + 24);
+ label3.setLayoutData(label3LData);
+ label3.setText("Preprocess Script:");
+
+ preFileText = new Text(this, SWT.SINGLE | SWT.BORDER);
+ FormData preFileTexLData = new FormData();
+ preFileTexLData.width = 495;
+ preFileTexLData.left = new FormAttachment(0, 1000, 126);
+ preFileTexLData.top = new FormAttachment(0, 1000, 68 + 24);
+ preFileTexLData.right = new FormAttachment(1000, 1000, -110);
+ preFileText.setLayoutData(preFileTexLData);
+ preFileText.setText("");
+ preFileText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ // without that listener, the text fields forget the
+ // last change when leaving with tab! don't know why!
+ // we also MUST call getText() otherwise the changes in
+ // the field are lost (what is this???!!)
+ Text t = (Text) e.widget;
+ t.getText();
+ }
+ });
+
+ fileChooseButton = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData fileChooseButtoLData = new FormData();
+ fileChooseButtoLData.width = 25;
+ fileChooseButtoLData.height = 25;
+ fileChooseButtoLData.top = new FormAttachment(0, 1000, 66 + 24);
+ fileChooseButtoLData.right = new FormAttachment(1000, 1000, -80);
+ fileChooseButton.setLayoutData(fileChooseButtoLData);
+ Image icon = getImage("prepFolder");
+ fileChooseButton.setImage(icon);
+ fileChooseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
+ fd.setText("Choose TextMarker Source File");
+ String[] filterExt = { "*.tm", "*.*" };
+ fd.setFilterExtensions(filterExt);
+ String file = fd.open();
+ if (file != null) {
+ preFileText.setText(file);
+ }
+ }
+ });
+
+ skipPreButton = new Button(this, SWT.CHECK | SWT.LEFT);
+ FormData skipPreButtonLData = new FormData();
+ skipPreButtonLData.width = 50;
+ skipPreButtonLData.height = 18;
+ skipPreButtonLData.top = new FormAttachment(0, 1000, 68 + 24);
+ skipPreButtonLData.right = new FormAttachment(1000, 1000, -25);
+ skipPreButton.setLayoutData(skipPreButtonLData);
+ skipPreButton.setText("skip");
+
+ label2 = new Label(this, SWT.NONE);
+ FormData label2LData = new FormData();
+ label2LData.left = new FormAttachment(0, 1000, 12);
+ label2LData.top = new FormAttachment(0, 1000, 44 + 24 + 24 + 24);
+ label2LData.width = 109;
+ label2.setLayoutData(label2LData);
+ label2.setText("Information Types:");
+
+ slotTypes = new AddRemoveList("SlotTypes", images, this, true);
+ FormData slotTypesLData = new FormData();
+ slotTypesLData.width = 300;
+ slotTypesLData.height = 144;
+ slotTypesLData.top = new FormAttachment(0, 1000, 85 + 24 + 24);
+ slotTypesLData.left = new FormAttachment(0, 1000, 12);
+ slotTypes.setLayoutData(slotTypesLData);
+
+ addDropTarget(slotTypes);
+
+ filtersLabel = new Label(this, SWT.NONE);
+ FormData filtersLabeLData = new FormData();
+ filtersLabeLData.width = 120;
+ filtersLabeLData.left = new FormAttachment(0, 1000, 320);
+ filtersLabeLData.top = new FormAttachment(0, 1000, 44 + 24 + 24 + 24);
+ filtersLabel.setLayoutData(filtersLabeLData);
+ filtersLabel.setText("Filtered Feature Types:");
+
+ filterTypes = new AddRemoveList("FilterTypes", images, this, false);
+ FormData filterTypesLData = new FormData();
+ filterTypesLData.width = 300;
+ filterTypesLData.height = 144;
+ filterTypesLData.top = new FormAttachment(0, 1000, 85 + 24 + 24);
+ filterTypesLData.left = new FormAttachment(0, 1000, 320);
+ filterTypes.setLayoutData(filterTypesLData);
+
+ addDropTarget(filterTypes);
+
+ FormData globalStatusLabeLData = new FormData();
+ globalStatusLabeLData.width = 400;
+ globalStatusLabeLData.left = new FormAttachment(0, 1000, 70);
+ globalStatusLabeLData.top = new FormAttachment(0, 1000, 228 + 24 + 24);
+ globalStatusLabeLData.right = new FormAttachment(1000, 1000, -19);
+ globalStatusLabel = new Label(this, SWT.NONE);
+ globalStatusLabel.setLayoutData(globalStatusLabeLData);
+
+ methodsLabel = new Label(this, SWT.NONE);
+ FormData algsLabeLData = new FormData();
+ algsLabeLData.width = 120;
+ algsLabeLData.left = new FormAttachment(0, 1000, 12);
+ algsLabeLData.top = new FormAttachment(0, 1000, 228 + 24 + 24);
+ methodsLabel.setLayoutData(algsLabeLData);
+ methodsLabel.setText("Methods:");
+
+ FormData algListViewerLData = new FormData();
+ // algListViewerLData.width = 400;
+ // algListViewerLData.height = 115;
+
+ algListViewerLData.left = new FormAttachment(0, 1000, 10);
+ algListViewerLData.top = new FormAttachment(0, 1000, 248 + 24 + 24);
+ algListViewerLData.right = new FormAttachment(1000, 1000, -10);
+ algListViewerLData.bottom = new FormAttachment(1000, 1000, -10);
+
+ algListViewer = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ algListViewer.getControl().setLayoutData(algListViewerLData);
+ algListViewer.setContentProvider(new ListContentProvider());
+ algListViewer.setLabelProvider(new DefaultLabelProvider("learner"));
+ algListViewer.setSorter(new NameSorter());
+ if (textRulerView != null)
+ algListViewer.setInput(textRulerView.getViewSite());
+
+ this.layout();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ DropTarget dt = new DropTarget(inputDirectoryText, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0)
+ inputDirectoryText.setText(fileList[0]);
+ }
+ });
+
+ DropTarget dt3 = new DropTarget(additionalDirectoryText, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt3.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt3.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0)
+ additionalDirectoryText.setText(fileList[0]);
+ }
+ });
+
+ DropTarget dt4 = new DropTarget(testDirectoryText, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt4.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt4.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0)
+ testDirectoryText.setText(fileList[0]);
+ }
+ });
+
+ DropTarget dt2 = new DropTarget(preFileText, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ dt2.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ dt2.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0)
+ preFileText.setText(fileList[0]);
+ }
+ });
+
+ createAlgorithmConfigurators();
+ // algListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ // public void selectionChanged(SelectionChangedEvent event) {
+ // StructuredSelection s = (StructuredSelection) event.getSelection();
+ // String id = null;
+ // if (!s.isEmpty())
+ // id = ((TextRulerLearnerController) s.getFirstElement()).getID();
+ // showConfiguratorForAlgorithm(id);
+ // }
+ // });
+ }
+
+ private void addDropTarget(final AddRemoveList list) {
+ DropTarget fdt = new DropTarget(list, DND.DROP_DEFAULT | DND.DROP_MOVE);
+ fdt.setTransfer(new Transfer[] { FileTransfer.getInstance() });
+ fdt.addDropListener(new DropTargetAdapter() {
+ @Override
+ public void drop(DropTargetEvent event) {
+ String fileList[] = null;
+ FileTransfer ft = FileTransfer.getInstance();
+ if (ft.isSupportedType(event.currentDataType)) {
+ fileList = (String[]) event.data;
+ }
+ if (fileList.length > 0) {
+ for (String string : fileList) {
+ if (string.endsWith(".xml")) {
+ XMLizable descriptor = null;
+ try {
+ descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(string));
+ } catch (InvalidXMLException e) {
+ } catch (IOException e) {
+ }
+ if (descriptor instanceof TypeSystemDescription) {
+ TypeSystemDescription tsd = (TypeSystemDescription) descriptor;
+ try {
+ tsd.resolveImports();
+ } catch (InvalidXMLException e) {
+ }
+ List<String> tsTypes = new ArrayList<String>();
+ TypeDescription[] typeDescs = tsd.getTypes();
+ for (TypeDescription typeDescription : typeDescs) {
+ String n = typeDescription.getName();
+ tsTypes.add(n);
+ }
+ list.addAll(tsTypes);
+ }
+ } else if (string.endsWith(".txt")) {
+ String file2String = null;
+ try {
+ file2String = FileUtils.file2String(new File(string), "UTF-8");
+ } catch (IOException e) {
+ }
+ if (file2String != null) {
+ String replaceAll = file2String.replaceAll("[\\n\\r]+", ", ");
+ list.addAll(replaceAll);
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ private void initImages() {
+ images = new HashMap<String, Image>();
+ ImageDescriptor desc;
+ Image image;
+ String name;
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/add.png");
+ image = desc.createImage();
+ name = "add";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/delete.png");
+ image = desc.createImage();
+ name = "delete";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/folder_edit.png");
+ image = desc.createImage();
+ name = "prepFolder";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/folder.png");
+ image = desc.createImage();
+ name = "folder";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/up.gif");
+ image = desc.createImage();
+ name = "up";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/down.gif");
+ image = desc.createImage();
+ name = "down";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/information.gif");
+ image = desc.createImage();
+ name = "information";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/feature.gif");
+ image = desc.createImage();
+ name = "feature";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/learner.png");
+ image = desc.createImage();
+ name = "learner";
+ images.put(name, image);
+
+ desc = TextRulerPlugin.getImageDescriptor("/icons/testing.gif");
+ image = desc.createImage();
+ name = "testing";
+ images.put(name, image);
+
+ }
+
+ public Image getImage(String name) {
+ if (images == null) {
+ initImages();
+ }
+ return images.get(name);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ if (images != null) {
+ for (Image each : images.values()) {
+ each.dispose();
+ }
+ }
+ }
+
+ public String[] getFilters() {
+ return filterTypes.getAll();
+ }
+
+ public String[] getSlotNames() {
+ return slotTypes.getAll();
+ }
+
+ public String getPreprocessorTMFile() {
+ return preFileText.getText().trim();
+ }
+
+ public String getInputDirectoryPath() {
+ return inputDirectoryText.getText().trim();
+ }
+
+ public String getAdditionalDirectoryPath() {
+ return additionalDirectoryText.getText().trim();
+ }
+
+ public String getTestDirectoryPath() {
+ return testDirectoryText.getText().trim();
+ }
+
+ public CheckboxTableViewer getAlgListViewer() {
+ return algListViewer;
+ }
+
+ public boolean getSkipPreprocessing() {
+ return skipPreButton.getSelection();
+ }
+
+ public void setGlobalStatusString(String s) {
+ globalStatusLabel.setText(s);
+ }
+
+ public void createAlgorithmConfigurators() {
+ if (null == TextRulerController.getAvailableControllers())
+ return;
+ for (TextRulerLearnerController ctrl : TextRulerController.getAvailableControllers()) {
+ LearnerConfigurator ac = new LearnerConfigurator(ctrl);
+ configurators.add(ac);
+ // GridData d = new GridData();
+ // d.horizontalAlignment = GridData.FILL;
+ // d.grabExcessHorizontalSpace = true;
+ // d.verticalAlignment = GridData.FILL;
+ // d.grabExcessVerticalSpace = true;
+ // d.exclude = true;
+ // ac.setLayoutData(d);
+ // ac.setVisible(false);
+ // ac.setCurrentParameterSettings(ctrl.getFactory().getAlgorithmParameterStandardValues());
+ }
+ }
+
+ // public void showConfiguratorForAlgorithm(String id) {
+ // for (Control aControl : configArea.getChildren()) {
+ // boolean show = id != null && ((LearnerConfigurator) aControl).getID().equals(id);
+ // GridData d = (GridData) aControl.getLayoutData();
+ // d.exclude = !show;
+ // aControl.setVisible(show);
+ // }
+ // configArea.layout();
+ // }
+
+ public Map<String, Map<String, Object>> getCurrentAlgorithmParameters() {
+ Map<String, Map<String, Object>> result = new HashMap<String, Map<String, Object>>();
+ for (LearnerConfigurator c : configurators) {
+ result.put(c.getID(), c.getCurrentParameterSettings());
+ }
+ return result;
+ }
+
+ public void saveState(IMemento memento) {
+ IMemento activeAlgChild = memento.createChild("activeAlgorithms");
+ for (Object c : algListViewer.getCheckedElements()) {
+ activeAlgChild.createChild("algorithm", ((TextRulerLearnerController) c).getID());
+ }
+
+ memento.createChild("inputDirectory", inputDirectoryText.getText());
+ memento.createChild("additionalDirectory", additionalDirectoryText.getText());
+ memento.createChild("testDirectory", testDirectoryText.getText());
+ memento.createChild("slotName", slotTypes.getAllElementsAsString());
+ memento.createChild("filters", filterTypes.getAllElementsAsString());
+ memento.createChild("preprocessFile", preFileText.getText());
+ memento.createChild("skipPreprocessing", skipPreButton.getSelection() ? "yes" : "no");
+ memento.createChild("showTest", showTestsButton.getSelection() ? "yes" : "no");
+ }
+
+ public LearnerConfigurator getAlgConfiguratorForID(String id) {
+ for (LearnerConfigurator c : configurators) {
+ if (c.getID().equals(id))
+ return c;
+ }
+ return null;
+ }
+
+ public void restoreState(IMemento memento) {
+ if (memento == null)
+ return;
+
+ IMemento filters = memento.getChild("filters");
+ if (filters != null)
+ filterTypes.addAll(filters.getID());
+ else
+ filterTypes.addAll(TextRulerToolkit.getStandardFilterSetString());
+
+ IMemento slotName = memento.getChild("slotName");
+ if (slotName != null)
+ slotTypes.addAll(slotName.getID());
+
+ IMemento preName = memento.getChild("preprocessFile");
+ if (preName != null)
+ preFileText.setText(preName.getID());
+
+ IMemento dir = memento.getChild("inputDirectory");
+ if (dir != null)
+ inputDirectoryText.setText(dir.getID());
+
+ IMemento additional = memento.getChild("additionalDirectory");
+ if (additional != null)
+ additionalDirectoryText.setText(additional.getID());
+
+ IMemento test = memento.getChild("testDirectory");
+ if (test != null)
+ testDirectoryText.setText(test.getID());
+
+ IMemento activeAlgs = memento.getChild("activeAlgorithms");
+ if (activeAlgs != null) {
+ ArrayList<TextRulerLearnerController> activeControllers = new ArrayList<TextRulerLearnerController>();
+ for (IMemento c : activeAlgs.getChildren("algorithm")) {
+ TextRulerLearnerController ctrl = TextRulerController.getControllerForID(c.getID());
+ if (ctrl != null)
+ activeControllers.add(ctrl);
+ }
+ algListViewer.setCheckedElements(activeControllers.toArray());
+ }
+
+ IMemento skip = memento.getChild("skipPreprocessing");
+ if (skip != null) {
+ boolean skipPreprocessing = skip.getID().equals("yes");
+ skipPreButton.setSelection(skipPreprocessing);
+ }
+
+ IMemento showTest = memento.getChild("showTest");
+ if (skip != null) {
+ boolean showTestValue = showTest.getID().equals("yes");
+ showTestsButton.setSelection(showTestValue);
+ }
+ }
+
+ @Override
+ public void setEnabled(boolean flag) {
+ super.setEnabled(flag);
+ // algListViewer.getTable().setEnabled(flag); // it is not possible to just
+ // prevent from pressing on
+ // the checkboxes unfortunately. so we have to disable the whole control
+ // which also disables scrolling
+ // (that is really lame!)
+ dirButton.setEnabled(flag);
+ fileChooseButton.setEnabled(flag);
+ slotTypes.setEnabled(flag);
+ filterTypes.setEnabled(flag);
+ preFileText.setEnabled(flag);
+ inputDirectoryText.setEnabled(flag);
+ additionalDirectoryText.setEnabled(flag);
+ additionalButton.setEnabled(flag);
+ testDirectoryText.setEnabled(flag);
+ testButton.setEnabled(flag);
+ }
+
+ public static String getScriptPath() {
+ return preFileText.getText();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/TextRulerViewComposite.java
------------------------------------------------------------------------------
svn:mime-type = text/plain