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/01 16:21:35 UTC
svn commit: r1152792 [9/10] - in /uima/sandbox/trunk/TextMarker:
org.apache.uima.tm.textruler.lp2/ org.apache.uima.tm.textruler.lp2/META-INF/
org.apache.uima.tm.textruler.lp2/bin/ org.apache.uima.tm.textruler.lp2/src/
org.apache.uima.tm.textruler.lp2/s...
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,47 @@
+package org.apache.uima.tm.textruler.tools;
+
+import org.apache.uima.tm.textruler.core.TextRulerToolkit;
+
+public class MemoryWatch {
+
+ private static long lastFreeMemory = 0;
+
+ private static long lastTotalMemory = 0;
+
+ private static long count = 0;
+
+ private static long lastFreeMemAfterGuessedGC = 0;
+
+ public static synchronized void watch() {
+ long free = Runtime.getRuntime().freeMemory();
+ long total = Runtime.getRuntime().totalMemory();
+ long max = Runtime.getRuntime().maxMemory();
+ long used = total - free;
+
+ boolean show = total != lastTotalMemory || (count % 5000 == 0);
+
+ if (total == max) {
+ if (free > lastFreeMemory && free != lastFreeMemAfterGuessedGC) // gc
+ // seemd
+ // to
+ // clean
+ // up
+ // the
+ // memory
+ {
+
+ lastFreeMemAfterGuessedGC = free;
+ show = true;
+ }
+ }
+
+ if (show) {
+ TextRulerToolkit.log(count + "\tfree: " + free + "\ttotal: " + total + "\tused: " + used
+ + "\tmax: " + max + "\tfreeAfterGC: " + lastFreeMemAfterGuessedGC);
+ }
+ lastFreeMemory = free;
+ lastTotalMemory = total;
+ count++;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/MemoryWatch.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,89 @@
+package org.apache.uima.tm.textruler.tools;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textruler.core.TextRulerToolkit;
+import org.apache.uima.util.FileUtils;
+import org.eclipse.core.runtime.Path;
+
+public class SGMLToXMIConverter {
+
+ public static boolean DEBUG = true;
+
+ static void convertSGMLAnnotationsToCASAnotations(String documentText, CAS cas) {
+ StringBuffer textBuf = new StringBuffer(documentText);
+ TypeSystem ts = cas.getTypeSystem();
+ int annotations = 0;
+ while (true) {
+ int indexTagBegin = textBuf.indexOf("<");
+ int indexTagEnd = textBuf.indexOf(">", indexTagBegin);
+ if (indexTagBegin < 0 || indexTagEnd < 0)
+ break;
+ try {
+ String name = textBuf.substring(indexTagBegin + 1, indexTagEnd);
+
+ int lengthTag = indexTagEnd - indexTagBegin + 1;
+ Type theType = ts.getType("de.uniwue.ml.types." + name);
+ if (theType != null) {
+ TextRulerToolkit.log("\tType known, creating Annotation: " + name);
+ int indexTagCloseBegin = textBuf.indexOf("<", indexTagEnd);
+ AnnotationFS fs = cas.createAnnotation(theType, indexTagBegin, indexTagCloseBegin
+ - lengthTag);
+ cas.addFsToIndexes(fs);
+ annotations++;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ textBuf.delete(indexTagBegin, indexTagEnd + 1);
+ }
+ cas.setDocumentText(textBuf.toString());
+ if (annotations == 0) {
+ TextRulerToolkit.log("NO ANNOTATIONS CREATED! IS THAT INTENDED ?");
+ }
+ }
+
+ public static void convertFilesInFolder(String inFolder, String outFolder, String tmFileForEngine) {
+ File in = new File(inFolder);
+ File[] files = in.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return !name.startsWith(".");
+ }
+ });
+
+ outFolder = TextRulerToolkit.addTrailingSlashToPath(outFolder);
+
+ AnalysisEngine ae = TextRulerToolkit.loadAnalysisEngine(TextRulerToolkit
+ .getEngineDescriptorFromTMSourceFile(new Path(tmFileForEngine)));
+ if (ae == null) {
+ TextRulerToolkit.log("ERROR LOADING ANALYSIS ENGINE!");
+ return;
+ }
+ for (File f : files) {
+ try {
+ String fileContents = FileUtils.file2String(f);
+ CAS theCas = ae.newCAS();
+ convertSGMLAnnotationsToCASAnotations(fileContents, theCas);
+ TextRulerToolkit.writeCAStoXMIFile(theCas, outFolder + f.getName() + ".xmi");
+ TextRulerToolkit.log("Saved to " + outFolder + f.getName() + ".xmi");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ public static void main(String[] args) {
+ String inputFolder = "/testinput/SA/all/txt";
+ String outputFolder = "/testinput/SA/all/xmi/";
+ String tmScriptFileForEngine = "/Users/tobi/Documents/runtime-EclipseApplication/MLSandBox/script/de.uniwue.ml/types.tm";
+
+ convertFilesInFolder(inputFolder, outputFolder, tmScriptFileForEngine);
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/SGMLToXMIConverter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,187 @@
+package org.apache.uima.tm.textruler.tools;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.uima.tm.textruler.core.TextRulerToolkit;
+import org.apache.uima.util.FileUtils;
+
+public class TestSetGenerator {
+
+ public static String trainingDir = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/ALL/training/";
+
+ public static String testDir = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/ALL/withoutslots/";
+
+ public static String trainingFilesPrefix = "postagged_";
+
+ public static String testFilesPrefix = "postagged_withoutslots_";
+
+ public static class PairEntry {
+ public String trainingsFileName;
+
+ public String testFileName;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+
+ File trainingFolder = new File(trainingDir);
+ File[] files = trainingFolder.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return (name.endsWith(".xmi"));
+ }
+ });
+
+ List<PairEntry> pairs = new ArrayList<PairEntry>();
+
+ for (File file : files) {
+ String fName = file.getName();
+ String docName = fName.substring(trainingFilesPrefix.length());
+ PairEntry p = new PairEntry();
+ p.trainingsFileName = fName;
+ p.testFileName = testFilesPrefix + docName;
+ pairs.add(p);
+ }
+
+ try {
+ // makeXFoldCrossValidationSets(10, pairs,
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/test2_out/");
+ // makeXFoldCrossValidationSets(5,
+ // pairs,
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100/5fold");
+
+ // List<PairEntry> list1 = new ArrayList<PairEntry>();
+ // List<PairEntry> list2 = new ArrayList<PairEntry>();
+ // for (int i = 0; i<pairs.size(); i++)
+ // {
+ // if (i % 2 == 0)
+ // list1.add(pairs.get(i));
+ // else
+ // list2.add(pairs.get(i));
+ // }
+ // copyPairs(list1,
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/halfhalf/0/training");
+ // copyPairs(list2,
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/halfhalf/0/testing");
+
+ Random rand = new Random();
+ List<PairEntry> list1 = new ArrayList<PairEntry>(pairs);
+ List<PairEntry> list2 = new ArrayList<PairEntry>();
+ for (int i = 0; i < 28; i++) {
+ int index = rand.nextInt(list1.size());
+ list2.add(list1.get(index));
+ list1.remove(index);
+ }
+ while (list1.size() > 252) {
+ int index = rand.nextInt(list1.size());
+ list1.remove(index);
+ }
+ copyPairs(list1,
+ "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/9010_middle/0/training");
+ copyPairs(list2,
+ "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/9010_middle/0/testing");
+
+ // double step = 485.0 / 97.0;
+ // List<PairEntry> list = new ArrayList<PairEntry>();
+ // double i = 0;
+ // while (list.size() != 97)
+ // {
+ // int intI = (int)Math.round(i);
+ // if (intI >= 485) intI -= 484;
+ // TextRulerToolkit.log(""+intI);
+ // list.add(pairs.get(intI));
+ // i += step;
+ // }
+ // copyPairs(list,
+ // "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void copyPairs(List<PairEntry> pairs, String dest) throws IOException {
+ dest = TextRulerToolkit.addTrailingSlashToPath(dest);
+ String withTags = dest + "withtags";
+ String withoutTags = dest + "withouttags";
+ new File(withTags).mkdir();
+ new File(withoutTags).mkdir();
+
+ for (PairEntry pe : pairs) {
+ File srcFile = new File(trainingDir + pe.trainingsFileName);
+ File dstFile = new File(withTags);
+ FileUtils.copyFile(srcFile, dstFile);
+ srcFile = new File(testDir + pe.testFileName);
+ dstFile = new File(withoutTags);
+ FileUtils.copyFile(srcFile, dstFile);
+ }
+
+ }
+
+ public static void makeXFoldCrossValidationSets(int partitionCount, List<PairEntry> pairs,
+ String destinationPath) throws IOException {
+ List<PairEntry> pairsCopy = new ArrayList<PairEntry>(pairs);
+ int partSize = (int) Math.ceil((double) pairsCopy.size() / ((double) partitionCount));
+
+ Random rand = new Random();
+
+ ArrayList<ArrayList<PairEntry>> partition = new ArrayList<ArrayList<PairEntry>>();
+
+ for (int partNo = 0; partNo < partitionCount; partNo++) {
+ ArrayList<PairEntry> part = new ArrayList<PairEntry>();
+ partition.add(part);
+ if (partNo == partitionCount - 1) {
+ part.addAll(pairsCopy); // the last part gets the remaining
+ // items...
+ } else {
+ for (int i = 0; i < partSize; i++) {
+ int index = rand.nextInt(pairsCopy.size());
+ part.add(pairsCopy.get(index));
+ pairsCopy.remove(index);
+ }
+ }
+ }
+ destinationPath = TextRulerToolkit.addTrailingSlashToPath(destinationPath);
+ for (int i = 0; i < partitionCount; i++) {
+ String foldDest = destinationPath + i + "/";
+ TextRulerToolkit.log("MK: " + new File(foldDest).mkdir());
+ new File(foldDest + "training").mkdir();
+ new File(foldDest + "testing").mkdir();
+ new File(foldDest + "training/withtags").mkdir();
+ new File(foldDest + "training/withouttags").mkdir();
+ new File(foldDest + "testing/withtags").mkdir();
+ new File(foldDest + "testing/withouttags").mkdir();
+ String trainingWithTagsDir = foldDest + "training/withtags/";
+ String trainingWithoutTagsDir = foldDest + "training/withouttags/";
+ String testingWithTagsDir = foldDest + "testing/withtags/";
+ String testingWithoutTagsDir = foldDest + "testing/withouttags/";
+
+ for (PairEntry pe : partition.get(i)) {
+ // part no i is the testing fold
+ File srcFile = new File(trainingDir + pe.trainingsFileName);
+ File dstFile = new File(testingWithTagsDir);
+ FileUtils.copyFile(srcFile, dstFile);
+ srcFile = new File(testDir + pe.testFileName);
+ dstFile = new File(testingWithoutTagsDir);
+ FileUtils.copyFile(srcFile, dstFile);
+ }
+ for (int restI = 0; restI < partitionCount; restI++)
+ if (restI != i) {
+ for (PairEntry pe : partition.get(restI)) {
+ File srcFile = new File(trainingDir + pe.trainingsFileName);
+ File dstFile = new File(trainingWithTagsDir);
+ FileUtils.copyFile(srcFile, dstFile);
+ srcFile = new File(testDir + pe.testFileName);
+ dstFile = new File(trainingWithoutTagsDir);
+ FileUtils.copyFile(srcFile, dstFile);
+ }
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/tools/TestSetGenerator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,395 @@
+package org.apache.uima.tm.textruler.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.tm.textruler.core.TextRulerToolkit;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLizable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+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.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableItem;
+
+
+public class AddRemoveList extends Composite {
+
+ private boolean error = false;
+
+ private String name;
+
+ private CheckboxTableViewer listViewer;
+
+ private Button add;
+
+ private Button remove;
+
+ private Button up;
+
+ private Button down;
+
+ private Button ts;
+
+ private TextRulerViewComposite parent;
+
+ protected final HashMap<String, Image> images;
+
+ private ArrayList<String> types;
+
+ private boolean ordered;
+
+ public AddRemoveList(String name, HashMap<String, Image> images, TextRulerViewComposite parent,
+ boolean ordered) {
+ super(parent, SWT.NULL);
+ this.name = name;
+ this.images = images;
+ this.parent = parent;
+ this.ordered = ordered;
+ init();
+ }
+
+ private void setTypes() {
+ error = false;
+ types.clear();
+ String preFilePath = TextRulerViewComposite.getScriptPath();
+ File preFile = new File(preFilePath);
+ if (preFile.exists() == false || preFilePath.equals("")) {
+ printErrorDialog("The preprocessing file was not found!");
+ error = true;
+ return;
+ }
+ Path scriptPath = new Path(preFilePath);
+ String defaultTypeSystemDescriptorLocation = TextRulerToolkit
+ .getTypeSystemDescriptorFromTMSourceFile(scriptPath);
+ TypeSystemDescription defaultTypeSystemDescription = null;
+ try {
+ defaultTypeSystemDescription = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+ new XMLInputSource(new File(defaultTypeSystemDescriptorLocation)));
+ defaultTypeSystemDescription.resolveImports();
+ TypeDescription[] systemTypes = defaultTypeSystemDescription.getTypes();
+ for (TypeDescription typeDescription : systemTypes) {
+ types.add(typeDescription.getName());
+ }
+ Collections.sort(types);
+ } catch (InvalidXMLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void printErrorDialog(String error) {
+ ErrorDialog.openError(Display.getCurrent().getActiveShell(), "File not Found!", error,
+ new Status(IStatus.ERROR, "-1", "File not found!"));
+ }
+
+ private void init() {
+
+ this.setLayout(new FormLayout());
+ this.setSize(200, 300);
+
+ types = new ArrayList<String>();
+ listViewer = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.MULTI);
+ FormData listViewerLData = new FormData();
+ listViewerLData.width = 160;
+ listViewerLData.height = 150;
+ listViewerLData.left = new FormAttachment(0, 1000, 0);
+ listViewerLData.right = new FormAttachment(1000, 1000, -40);
+ listViewerLData.top = new FormAttachment(0, 1000, 0);
+ listViewerLData.bottom = new FormAttachment(1000, 1000, -10);
+ listViewer.getControl().setLayoutData(listViewerLData);
+ listViewer.setContentProvider(parent.new ListContentProvider());
+ listViewer.setLabelProvider(parent.new DefaultLabelProvider(name));
+ // listViewer.setLabelProvider(parent.new ViewLabelProvider());
+ // listViewer.setSorter(parent.new NameSorter());
+ listViewer.getTable().setVisible(true);
+
+ if (name.equals("FilterTypes")) {
+ String input = TextRulerToolkit.getStandardFilterSetString();
+ addAll(input);
+ } else {
+ listViewer.setAllChecked(true);
+ }
+
+ listViewer.getControl().addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ int keyCode = e.keyCode;
+ // backspace or delete
+ if (keyCode == SWT.BS || keyCode == SWT.DEL) {
+ String selected = listViewer.getSelection().toString();
+ selected = selected.substring(1, selected.length() - 1);
+ String[] types = selected.split(", ");
+ for (String string : types) {
+ listViewer.remove(string);
+ }
+ }
+ }
+
+ });
+
+ ts = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData tsLData = new FormData();
+ tsLData.width = 25;
+ tsLData.height = 25;
+ tsLData.top = new FormAttachment(0, 1000, 0);
+ tsLData.right = new FormAttachment(1000, 1000, -10);
+ ts.setLayoutData(tsLData);
+ Image tsIcon = images.get("prepFolder");
+ ts.setImage(tsIcon);
+ ts.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
+ fd.setText("Choose Type System Descriptor");
+ String[] filterExt = { "*.xml", "*.*" };
+ fd.setFilterExtensions(filterExt);
+ fd.setFileName(parent.getPreprocessorTMFile());
+ String file = fd.open();
+ if (file != null) {
+ XMLizable descriptor = null;
+ try {
+ descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(file));
+ } 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);
+ }
+ addAll(tsTypes);
+ }
+ }
+ }
+ });
+
+ add = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData addLData = new FormData();
+ addLData.width = 25;
+ addLData.height = 25;
+ addLData.top = new FormAttachment(0, 1000, 27);
+ addLData.right = new FormAttachment(1000, 1000, -10);
+ add.setLayoutData(addLData);
+ Image addIcon = images.get("add");
+ add.setImage(addIcon);
+ add.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ setTypes();
+ if (error)
+ return;
+ Display display = Display.getDefault();
+ Shell shell = new Shell(display, SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
+ if (name.equals("FilterTypes"))
+ shell.setText("Filter Types");
+ else
+ shell.setText("Slot Types");
+ new SelectTypesDialog(shell, types, AddRemoveList.this);
+ }
+ });
+
+ remove = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData removeLData = new FormData();
+ removeLData.width = 25;
+ removeLData.height = 25;
+ removeLData.top = new FormAttachment(0, 1000, 54);
+ removeLData.right = new FormAttachment(1000, 1000, -10);
+ remove.setLayoutData(removeLData);
+ Image deleteIcon = images.get("delete");
+ remove.setImage(deleteIcon);
+ remove.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String selected = listViewer.getSelection().toString();
+ selected = selected.substring(1, selected.length() - 1);
+ String[] types = selected.split(", ");
+ for (String string : types) {
+ listViewer.remove(string);
+ }
+ }
+ });
+
+ if (ordered) {
+ up = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData upLData = new FormData();
+ upLData.width = 25;
+ upLData.height = 25;
+ upLData.top = new FormAttachment(0, 1000, 81);
+ upLData.right = new FormAttachment(1000, 1000, -10);
+ up.setLayoutData(upLData);
+ Image upIcon = images.get("up");
+ up.setImage(upIcon);
+ up.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ ISelection selection = listViewer.getSelection();
+ List<String> dataList = new ArrayList<String>();
+ if (selection instanceof StructuredSelection) {
+ StructuredSelection ss = (StructuredSelection) selection;
+ Iterator<?> iterator = ss.iterator();
+ while (iterator.hasNext()) {
+ Object object = (Object) iterator.next();
+ if (object instanceof String) {
+ String obj = (String) object;
+ dataList = new ArrayList<String>();
+ TableItem[] items = listViewer.getTable().getItems();
+ for (TableItem tableItem : items) {
+ dataList.add((String) tableItem.getData());
+ }
+ int indexOf = dataList.indexOf(obj);
+ Collections.swap(dataList, indexOf, indexOf - 1);
+ }
+ }
+ }
+ listViewer.remove(dataList.toArray());
+ addAll(dataList);
+ }
+ });
+
+ down = new Button(this, SWT.PUSH | SWT.CENTER);
+ FormData downLData = new FormData();
+ downLData.width = 25;
+ downLData.height = 25;
+ downLData.top = new FormAttachment(0, 1000, 108);
+ downLData.right = new FormAttachment(1000, 1000, -10);
+ down.setLayoutData(downLData);
+ Image downIcon = images.get("down");
+ down.setImage(downIcon);
+ down.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ ISelection selection = listViewer.getSelection();
+ List<String> dataList = new ArrayList<String>();
+ if (selection instanceof StructuredSelection) {
+ StructuredSelection ss = (StructuredSelection) selection;
+ Iterator<?> iterator = ss.iterator();
+ while (iterator.hasNext()) {
+ Object object = (Object) iterator.next();
+ if (object instanceof String) {
+ String obj = (String) object;
+ dataList = new ArrayList<String>();
+ TableItem[] items = listViewer.getTable().getItems();
+ for (TableItem tableItem : items) {
+ dataList.add((String) tableItem.getData());
+ }
+ int indexOf = dataList.indexOf(obj);
+ Collections.swap(dataList, indexOf, indexOf + 1);
+ }
+ }
+ }
+ listViewer.remove(dataList.toArray());
+ addAll(dataList);
+ }
+ });
+ }
+ }
+
+ public String[] getAll() {
+ ArrayList<String> elements = new ArrayList<String>();
+
+ Object[] objectElements = listViewer.getCheckedElements();
+ for (Object object : objectElements) {
+ elements.add(object.toString());
+ }
+ return elements.toArray(new String[objectElements.length]);
+ }
+
+ public String getAllElementsAsString() {
+ String result = "";
+ listViewer.setAllChecked(true);
+ for (int i = 0; i < listViewer.getCheckedElements().length; i++) {
+ if (i == listViewer.getCheckedElements().length - 1) {
+ result += listViewer.getCheckedElements()[i];
+ } else {
+ result += listViewer.getCheckedElements()[i] + ", ";
+ }
+ }
+ return result;
+ }
+
+ public void addAll(String input) {
+ if (input == null)
+ return;
+ int index = 0;
+ while (index != -1) {
+ index = input.indexOf(",");
+ String filter;
+ if (index == -1)
+ filter = input;
+ else {
+ filter = input.substring(0, index);
+ input = input.substring(index + 2);
+ }
+ boolean isAlreadyAdded = false;
+ int i = 0;
+ while (listViewer.getElementAt(i) != null) {
+ if (filter.equals(listViewer.getElementAt(i))) {
+ isAlreadyAdded = true;
+ break;
+ }
+ i++;
+ }
+ if (!isAlreadyAdded && !filter.trim().equals(""))
+ listViewer.add(filter);
+ }
+ listViewer.setAllChecked(true);
+ }
+
+ public void addAll(List<String> input) {
+ addAll(input, true);
+ }
+
+ public void addAll(List<String> input, boolean checkAll) {
+ for (String string : input) {
+ boolean isAlreadyAdded = false;
+ int i = 0;
+ while (listViewer.getElementAt(i) != null) {
+ if (string.equals(listViewer.getElementAt(i))) {
+ isAlreadyAdded = true;
+ break;
+ }
+ i++;
+ }
+ if (!isAlreadyAdded)
+ listViewer.add(string);
+ }
+ if (checkAll)
+ listViewer.setAllChecked(true);
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/AddRemoveList.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,87 @@
+package org.apache.uima.tm.textruler.ui;
+
+import java.util.List;
+
+import org.apache.uima.tm.textruler.TextRulerPlugin;
+import org.apache.uima.tm.textruler.extension.TextRulerController;
+import org.apache.uima.tm.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.tm.textruler.extension.TextRulerLearnerParameter;
+import org.apache.uima.tm.textruler.preferences.AlgorithmPreferencePage;
+import org.apache.uima.tm.textruler.preferences.ConfigPreferencePage;
+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.jface.preference.PreferenceDialog;
+import org.eclipse.jface.preference.PreferenceManager;
+import org.eclipse.jface.preference.PreferenceNode;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+
+public class ConfigureLearnersHandler implements IHandler {
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ PreferenceManager pm = new PreferenceManager();
+
+ PreferencePage page = new ConfigPreferencePage();
+ page.setTitle("TextRuler");
+ PreferenceNode node = new PreferenceNode("org.apache.uima.tm.textruler.config", page);
+ pm.addToRoot(node);
+
+ List<PreferenceNode> nodes = pm.getElements(0);
+ PreferenceNode top = null;
+ for (PreferenceNode n : nodes)
+ if (n.getId().equals("org.apache.uima.tm.textruler.config"))
+ top = n;
+ if (top != null) {
+ for (TextRulerLearnerController ctrl : TextRulerController.getAvailableControllers()) {
+ TextRulerLearnerParameter[] params = ctrl.getFactory().getAlgorithmParameters();
+ if (params == null || params.length == 0)
+ continue;
+ page = new AlgorithmPreferencePage(ctrl);
+ page.setTitle(ctrl.getName());
+ node = new PreferenceNode(ctrl.getID(), page);
+ top.add(node);
+ }
+ }
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ PreferenceDialog pd = new PreferenceDialog(shell, pm);
+ pd.setPreferenceStore(TextRulerPlugin.getDefault().getPreferenceStore());
+ pd.create();
+ pd.open();
+
+ // Dialog dialog = PreferencesUtil.createPreferenceDialogOn(HandlerUtil.getActiveShell(event),
+ // TestingPreferencePage.ID, new String[] { TestingPreferencePage.ID }, null);
+ // dialog.open();
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/ConfigureLearnersHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,203 @@
+package org.apache.uima.tm.textruler.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.tm.textruler.TextRulerPlugin;
+import org.apache.uima.tm.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.tm.textruler.extension.TextRulerLearnerFactory;
+import org.apache.uima.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/LearnerConfigurator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,226 @@
+package org.apache.uima.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/SelectTypesDialog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,34 @@
+package org.apache.uima.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,34 @@
+package org.apache.uima.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StartStopHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,33 @@
+package org.apache.uima.tm.textruler.ui;
+
+import org.apache.uima.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/StopHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,70 @@
+package org.apache.uima.tm.textruler.ui;
+
+import org.apache.uima.tm.dltk.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.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerResultsView.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java?rev=1152792&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java Mon Aug 1 14:21:12 2011
@@ -0,0 +1,310 @@
+package org.apache.uima.tm.textruler.ui;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.tm.textruler.extension.TextRulerController;
+import org.apache.uima.tm.textruler.extension.TextRulerControllerDelegate;
+import org.apache.uima.tm.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.tm.textruler.extension.TextRulerPreprocessor;
+import org.apache.uima.tm.textruler.extension.TextRulerLearner.TextRulerLearnerState;
+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.tm.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/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textruler/src/main/java/org/apache/uima/tm/textruler/ui/TextRulerView.java
------------------------------------------------------------------------------
svn:mime-type = text/plain