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 [9/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/jav...

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.learner.wien;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearner;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerDelegate;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerFactory;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerParameter;
+
+public class WienFactory implements TextRulerLearnerFactory {
+
+  public TextRulerLearner createAlgorithm(String inputFolderPath, String additionalFolderPath,
+          String preprocessorTMfile, String tempFolderPath, String[] fullSlotTypeNames,
+          Set<String> filterSet, TextRulerLearnerDelegate delegate) {
+    return new Wien(inputFolderPath, preprocessorTMfile, tempFolderPath, fullSlotTypeNames,
+            filterSet, delegate);
+  }
+
+  public Map<String, Object> getAlgorithmParameterStandardValues() {
+    return new HashMap<String, Object>();
+  }
+
+  public TextRulerLearnerParameter[] getAlgorithmParameters() {
+    TextRulerLearnerParameter[] result = new TextRulerLearnerParameter[0];
+    return result;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,41 @@
+/*
+ * 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.learner.wien;
+
+import org.apache.uima.textmarker.textruler.core.TextRulerBasicLearner;
+import org.apache.uima.textmarker.textruler.core.TextRulerMultiSlotRule;
+import org.apache.uima.textmarker.textruler.core.TextRulerTarget;
+
+public class WienRule extends TextRulerMultiSlotRule {
+
+  public WienRule(TextRulerBasicLearner parentAlgorithm, TextRulerTarget target) {
+    super(parentAlgorithm, target);
+  }
+
+  public WienRule(WienRule copyFrom) {
+    super(copyFrom);
+  }
+
+  @Override
+  public WienRule copy() {
+    return new WienRule(this);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,146 @@
+/*
+ * 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.learner.wien;
+
+import java.util.ArrayList;
+
+import org.apache.uima.textmarker.textruler.core.TextRulerAnnotation;
+import org.apache.uima.textmarker.textruler.core.TextRulerMultiSlotRule;
+import org.apache.uima.textmarker.textruler.core.TextRulerRule;
+import org.apache.uima.textmarker.textruler.core.TextRulerRuleItem;
+
+public class WienRuleItem implements TextRulerRuleItem {
+
+  WienWordConstraint wordConstraint;
+
+  ArrayList<String> conditions = new ArrayList<String>();
+
+  ArrayList<String> actions = new ArrayList<String>();
+
+  public WienRuleItem(WienRuleItem copyFrom) {
+    super();
+    if (copyFrom.wordConstraint != null)
+      wordConstraint = copyFrom.wordConstraint.copy();
+  }
+
+  public WienRuleItem(TextRulerAnnotation tokenAnnotation, boolean generalizeLinkMarkUp) {
+    super();
+    if (tokenAnnotation != null)
+      setWordConstraint(tokenAnnotation, generalizeLinkMarkUp);
+  }
+
+  public WienRuleItem(TextRulerAnnotation tokenAnnotation) {
+    super();
+    if (tokenAnnotation != null)
+      setWordConstraint(tokenAnnotation);
+  }
+
+  public WienRuleItem copy() {
+    return new WienRuleItem(this);
+  }
+
+  @Override
+  public int hashCode() {
+    return toString().hashCode();
+  }
+
+  public boolean equals(TextRulerRuleItem o) {
+    return toString().equals(((WienRuleItem) o).toString());
+  }
+
+  @Override
+  public String toString() {
+    return getStringForRuleString(null, null, 0, 0, 0, 0, 0);
+  }
+
+  public void addAction(String s) {
+    actions.add(s);
+  }
+
+  public void addCondition(String s) {
+    conditions.add(s);
+  }
+
+  public String getStringForRuleString(TextRulerRule rule, MLRuleItemType type,
+          int numberInPattern, int patternSize, int numberInRule, int ruleSize, int slotIndex) {
+
+    ArrayList<String> theConditions = new ArrayList<String>();
+    String anchor = null;
+    if (wordConstraint != null) {
+      if (wordConstraint.isRegExpConstraint()) {
+        anchor = wordConstraint.typeShortName();
+        theConditions.add("REGEXP(\"" + wordConstraint + "\")");
+      } else
+        anchor = wordConstraint.toString();
+    } else
+      anchor = "ALL*?";
+
+    theConditions.addAll(conditions);
+    String cStr = "";
+    if (theConditions.size() > 0) {
+      for (String c : theConditions) {
+        if (cStr.length() > 0)
+          cStr += ", ";
+        cStr += c;
+      }
+      cStr = "{" + cStr;
+    }
+
+    ArrayList<String> theActions = new ArrayList<String>();
+    if (type == MLRuleItemType.FILLER)
+      theActions.add("MARKONCE(" + ((TextRulerMultiSlotRule) rule).getMarkName(slotIndex) + ")");
+    // theActions.add("MARK, "+((TextRulerMultiSlotRule)rule).getMarkName(slotIndex)+", "+(numberInRule+1));
+    theActions.addAll(actions);
+    String aStr = "";
+    if (theActions.size() > 0) {
+      for (String a : theActions) {
+        if (aStr.length() > 0)
+          aStr += ", ";
+        aStr += a;
+      }
+      if (theConditions.size() == 0)
+        aStr = "{->" + aStr + "}";
+      else
+        aStr = "->" + aStr + "}";
+    } else if (theConditions.size() != 0)
+      aStr = "}";
+
+    return anchor + cStr + aStr;
+  }
+
+  public void setWordConstraint(TextRulerAnnotation tokenAnnotation, boolean generalizeLinkMarkUp) {
+    WienWordConstraint c = new WienWordConstraint(tokenAnnotation);
+    c.setGeneralizeLinkMarkUp(generalizeLinkMarkUp);
+    setWordConstraint(c);
+  }
+
+  public void setWordConstraint(TextRulerAnnotation tokenAnnotation) {
+    setWordConstraint(new WienWordConstraint(tokenAnnotation));
+  }
+
+  public void setWordConstraint(WienWordConstraint c) {
+    wordConstraint = c;
+  }
+
+  public WienWordConstraint getWordConstraint() {
+    return wordConstraint;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienRuleItem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.learner.wien;
+
+import org.apache.uima.textmarker.textruler.core.TextRulerAnnotation;
+import org.apache.uima.textmarker.textruler.core.TextRulerWordConstraint;
+
+public class WienWordConstraint extends TextRulerWordConstraint {
+
+  protected boolean generalizeLinkMarkUp;
+
+  public WienWordConstraint(TextRulerAnnotation tokenAnnotation) {
+    super(tokenAnnotation);
+    generalizeLinkMarkUp = false;
+  }
+
+  public WienWordConstraint(WienWordConstraint copyFrom) {
+    super(copyFrom);
+    generalizeLinkMarkUp = copyFrom.generalizeLinkMarkUp;
+  }
+
+  @Override
+  public WienWordConstraint copy() {
+    return new WienWordConstraint(this);
+  }
+
+  public void setGeneralizeLinkMarkUp(boolean b) {
+    generalizeLinkMarkUp = b;
+  }
+
+  @Override
+  public String toString() {
+    if (isRegExpConstraint()) {
+      String theText = tokenAnnotation.getCoveredText();
+      if (generalizeLinkMarkUp && typeShortName().equals("MARKUP")
+              && (theText.startsWith("<a") || theText.startsWith("<A"))) {
+        // special case for A HREF stuff, since hrefs are often
+        // different but the struct is the same!
+        // this is quick hack that should be configurable, but for now
+        // it works!
+        return theText.substring(0, 2) + ".*>";
+      } else
+        return super.toString();
+    } else
+      return super.toString();
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/learner/wien/WienWordConstraint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,149 @@
+/*
+ * 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.preferences;
+
+import java.util.ArrayList;
+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.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+
+public class AlgorithmPreferencePage extends FieldEditorPreferencePage implements IPreferencePage {
+
+  public static String ID = "org.apache.uima.textmarker.textruler.algorithmPages";
+
+  private TextRulerLearnerController algorithmController;
+
+  private IPreferenceStore store;
+
+  private ArrayList<FieldEditor> fields = new ArrayList<FieldEditor>();
+
+  public AlgorithmPreferencePage(TextRulerLearnerController algorithmController) {
+    super(FieldEditorPreferencePage.GRID);
+    this.algorithmController = algorithmController;
+    store = TextRulerPlugin.getDefault().getPreferenceStore();
+    setPreferenceStore(store);
+  }
+
+  protected void createFieldEditors() {
+    TextRulerLearnerFactory f = algorithmController.getFactory();
+    TextRulerLearnerParameter[] params = f.getAlgorithmParameters();
+    Map<String, Object> values = f.getAlgorithmParameterStandardValues();
+    if (params != null) {
+      for (int i = 0; i < params.length; i++) {
+        TextRulerLearnerParameter p = params[i];
+        String id = algorithmController.getID() + "." + p.id;
+        FieldEditor l = null;
+        switch (p.type) {
+          case ML_BOOL_PARAM: {
+            l = new BooleanFieldEditor(id, p.name, getFieldEditorParent());
+            fields.add(l);
+            addField(l);
+            store.setDefault(id, (Boolean) values.get(p.id));
+            l.setPreferenceStore(store);
+            break;
+          }
+
+          case ML_FLOAT_PARAM:
+          case ML_INT_PARAM:
+          case ML_STRING_PARAM: {
+            l = new StringFieldEditor(id, p.name, getFieldEditorParent());
+            fields.add(l);
+            addField(l);
+            store.setDefault(id, values.get(p.id).toString());
+            l.setPreferenceStore(store);
+            break;
+          }
+          // case ML_SELECT_PARAM: {
+          // Combo combo = new Combo(top, SWT.READ_ONLY);
+          // if (p.selectValues != null)
+          // for (MLParameterSelectValue v : p.selectValues) {
+          // combo.add(v.name);
+          // }
+          // c = combo;
+          // break;
+          // }
+          case ML_SELECT_PARAM:
+            break;
+        }
+      }
+    }
+  }
+
+  // public Map<String, Object> getCurrentAlgorithmParameters() {
+  // // Map<String, Map<String, Object>> results = new HashMap<String, Map<String, Object>>();
+  // Map<String, Object> result = new HashMap<String, Object>();
+  //
+  // 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: {
+  // // Map<String, Object> result = new HashMap<String, Object>();
+  // result.put(p.id, store.getBoolean(id));
+  // // results.put(p.id, result);
+  // break;
+  // }
+  //
+  // case ML_FLOAT_PARAM:
+  // case ML_INT_PARAM:
+  // case ML_STRING_PARAM: {
+  // // Map<String, Object> result = new HashMap<String, Object>();
+  // result.put(p.id, store.getString(id));
+  // // results.put(p.id, result);
+  // break;
+  // }
+  // // case ML_SELECT_PARAM: {
+  // // break;
+  // // }
+  // case ML_SELECT_PARAM:
+  // break;
+  // }
+  // }
+  // }
+  // return result;
+  // }
+
+  @Override
+  protected void performDefaults() {
+    for (FieldEditor f : fields)
+      f.loadDefault();
+    // super.performDefaults();
+  }
+
+  @Override
+  public boolean performOk() {
+    for (FieldEditor f : fields)
+      f.store();
+    // return super.performOk();
+    return true;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/AlgorithmPreferencePage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class ConfigPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+  public static String ID = "org.apache.uima.textmarker.textruler.config";
+
+  private Label evalHeadline;
+
+  public ConfigPreferencePage() {
+
+  }
+
+  @Override
+  protected Control createContents(Composite parent) {
+    Composite top = new Composite(parent, SWT.LEFT);
+    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+    top.setLayout(new GridLayout());
+
+    evalHeadline = new Label(top, SWT.NULL);
+    evalHeadline.setText("General settings for the different TextRuler methods.");
+
+    return top;
+  }
+
+  @Override
+  public void init(IWorkbench workbench) {
+
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/preferences/ConfigPreferencePage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,175 @@
+/*
+ * 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.tools;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.textmarker.engine.TextMarkerEngine;
+import org.apache.uima.textmarker.textruler.core.TextRulerToolkit;
+import org.apache.uima.util.FileUtils;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+public class BatchRuleEvaluator {
+
+  private static AnalysisEngine ae;
+
+  private static String engineFile;
+
+  // private static String preprocessorTMFile;
+  private static String tempDir;
+
+  private static String foldRootDirectory;
+
+  private static int foldCount = 0;
+
+  private static CAS sharedCAS;
+
+  public static AnalysisEngine getAnalysisEngine() {
+    if (ae == null) {
+      // String descriptorFile =
+      // TextRulerToolkit.getEngineDescriptorFromTMSourceFile(new
+      // Path(preprocessorTMFile));
+      String descriptorFile = engineFile;
+      TextRulerToolkit.log("loading AE...");
+      ae = TextRulerToolkit.loadAnalysisEngine(descriptorFile);
+
+      // set filters to NO filtering so that we can add it manually with
+      // the FILTERTYPE expression!
+      ae.setConfigParameterValue(TextMarkerEngine.DEFAULT_FILTERED_MARKUPS, new String[0]);
+      IPath path = new Path(tempDir + "/results.tm");
+      ae.setConfigParameterValue(TextMarkerEngine.MAIN_SCRIPT, path.removeFileExtension()
+              .lastSegment());
+      ae.setConfigParameterValue(TextMarkerEngine.SCRIPT_PATHS, new String[] { path
+              .removeLastSegments(1).toPortableString() });
+      // ae.setConfigParameterValue(TextMarkerEngine.SEEDERS, new String[] {});
+      try {
+        ae.reconfigure();
+      } catch (ResourceConfigurationException e) {
+        e.printStackTrace();
+        return null;
+      }
+    }
+    return ae;
+  }
+
+  private static File[] getXMIFileFromFolder(String folderName) {
+    File folder = new File(folderName);
+    File[] files = folder.listFiles(new FilenameFilter() {
+      public boolean accept(File dir, String name) {
+        return (name.endsWith(".xmi"));
+      }
+    });
+    return files;
+  }
+
+  /**
+   * @param args
+   */
+  public static void main(String[] args) {
+
+    tempDir = "/testinput/temp/";
+    engineFile = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100/10fold/desc/lp2ergebnisrandomgiantEngine.xml";
+    foldRootDirectory = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/9010_middle/";// mit
+    foldCount = 1;
+    String slotNames[] = { "org.apache.uima.ml.types.etime", "org.apache.uima.ml.types.stime",
+        "org.apache.uima.ml.types.location", "org.apache.uima.ml.types.speaker" };
+    String algIDs[] = { "optimizedLP2"// ,
+    };
+
+    // TODO back to 0 !
+    for (int foldNumber = 0; foldNumber < foldCount; foldNumber++) {
+      for (String slotName : slotNames) {
+        for (String algID : algIDs) {
+          runRules(foldNumber, slotName, algID);
+        }
+      }
+    }
+
+  }
+
+  public static void runRules(int foldNumber, String slotName, String algorithmID) {
+    getAnalysisEngine();
+
+    TextRulerToolkit.log("Testing Fold Number " + foldNumber + "\t  Slot: " + slotName
+            + "\t  Algorithm: " + algorithmID);
+
+    // Input: 0/testing/withouttags/*.xmi
+    String inputFolder = foldRootDirectory + foldNumber + "/testing/withouttags/";
+    String rulesFile = foldRootDirectory + foldNumber + "/learnResults/" + slotName + "/"
+            + algorithmID + "/results.tm";
+    String scriptFile = tempDir + "results.tm";
+    File oldScriptFile = new File(scriptFile);
+    if (oldScriptFile.exists()) {
+      if (!oldScriptFile.delete()) {
+        TextRulerToolkit.log("ERROR DELETING OLD SCRIPT FILE: " + scriptFile);
+        return;
+      }
+    }
+
+    if (!new File(rulesFile).exists()) {
+      TextRulerToolkit.log("\tSKIPPED, no rules file not found!");
+      return;
+    }
+
+    try {
+      FileUtils.copyFile(new File(rulesFile), new File(tempDir));
+    } catch (IOException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+      return;
+    }
+
+    String outputFolder1 = foldRootDirectory + foldNumber + "/testing/markedFromRules";
+    String outputFolder2 = foldRootDirectory + foldNumber + "/testing/markedFromRules/" + slotName;
+    String outputFolder = foldRootDirectory + foldNumber + "/testing/markedFromRules/" + slotName
+            + "/" + algorithmID;
+    new File(outputFolder1).mkdir();
+    new File(outputFolder2).mkdir();
+    new File(outputFolder).mkdir();
+
+    File[] inputFiles = getXMIFileFromFolder(inputFolder);
+
+    for (File inputFile : inputFiles) {
+      // TextRulerToolkit.log("FILE TO TEST: "+inputFile.getAbsolutePath());
+      // TextRulerToolkit.log(" RESULT FILE: "+TextRulerToolkit.addTrailingSlashToPath(outputFolder)+"fromRules_"+inputFile.getName());
+
+      sharedCAS = TextRulerToolkit.readCASfromXMIFile(inputFile, ae, sharedCAS);
+
+      try {
+        ae.process(sharedCAS);
+      } catch (AnalysisEngineProcessException e) {
+        e.printStackTrace();
+        return;
+      }
+      TextRulerToolkit.writeCAStoXMIFile(
+              sharedCAS,
+              TextRulerToolkit.addTrailingSlashToPath(outputFolder) + "fromRules_"
+                      + inputFile.getName());
+    }
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleEvaluator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,90 @@
+/*
+ * 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.tools;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.textmarker.textruler.core.TextRulerToolkit;
+import org.apache.uima.textmarker.textruler.tools.F1Scorer.Score;
+import org.apache.uima.util.FileUtils;
+
+public class BatchRuleScorer {
+
+  private static String engineFile;
+
+  // private static String preprocessorTMFile;
+  private static String foldRootDirectory;
+
+  private static int foldCount = 0;
+
+  private static AnalysisEngine ae = null;
+
+  public static void main(String[] args) {
+    engineFile = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100/10fold/desc/lp2ergebnisrandomgiantEngine.xml";
+    foldRootDirectory = "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/9010_middle/";// mit
+    foldCount = 1;
+    String slotNames[] = { "org.apache.uima.ml.types.etime", "org.apache.uima.ml.types.stime",
+        "org.apache.uima.ml.types.location", "org.apache.uima.ml.types.speaker" };
+    String algIDs[] = { "optimizedLP2"// ,
+    // "rapier",
+    // "whisk"
+    };
+
+    ae = TextRulerToolkit.loadAnalysisEngine(engineFile);
+
+    // TODO back to 0 !
+    for (int foldNumber = 0; foldNumber < foldCount; foldNumber++) {
+      for (String slotName : slotNames) {
+        for (String algID : algIDs) {
+          scoreRules(foldNumber, slotName, algID);
+        }
+      }
+    }
+
+  }
+
+  public static void scoreRules(int foldNumber, String slotName, String algorithmID) {
+    TextRulerToolkit.log("Scoring Fold Number " + foldNumber + "\t  Slot: " + slotName
+            + "\t  Algorithm: " + algorithmID);
+
+    String fromRulesFolder = foldRootDirectory + foldNumber + "/testing/markedFromRules/"
+            + slotName + "/" + algorithmID + "/";
+    String originalsFolder = foldRootDirectory + foldNumber + "/testing/withtags/";
+    String resultsFile = foldRootDirectory + foldNumber + "/testing/score_" + foldNumber + "_"
+            + algorithmID + "." + slotName + ".txt";
+    if (!new File(fromRulesFolder).exists()) {
+      TextRulerToolkit.log("\tSKIPPED, fromRulesFolder not found!");
+      return;
+    }
+    F1Scorer scorer = new F1Scorer(ae, originalsFolder, fromRulesFolder);
+    Score slotScore = scorer.scoreSlot(slotName);
+    String str = "Score Results for Fold " + foldNumber + "\t  Slot: " + slotName
+            + "\t  Algorithm: " + algorithmID + "\n\n";
+    str += slotScore.toString();
+    try {
+      FileUtils.saveString2File(str, new File(resultsFile));
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/BatchRuleScorer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,225 @@
+/*
+ * 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.tools;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.textmarker.textruler.core.CasCache;
+import org.apache.uima.textmarker.textruler.core.CasCacheLoader;
+import org.apache.uima.textmarker.textruler.core.GlobalCASSource;
+import org.apache.uima.textmarker.textruler.core.TextRulerExample;
+import org.apache.uima.textmarker.textruler.core.TextRulerExampleDocument;
+import org.apache.uima.textmarker.textruler.core.TextRulerTarget;
+import org.apache.uima.textmarker.textruler.core.TextRulerToolkit;
+
+public class F1Scorer implements CasCacheLoader {
+
+  private AnalysisEngine ae;
+
+  ArrayList<TextRulerExampleDocument> trainingDocuments;
+
+  String[] testFileNames;
+
+  public static class Score {
+    public String slotName;
+
+    public int tp; // true positives: correct extracted slots
+
+    public int fp; // false positives: spurious fillers that do not occur in
+
+    // the original document
+    public int fn; // false negatives: missing slots that occur in the
+
+    // document but not in the result
+
+    public void logInfo() {
+      TextRulerToolkit.log(toString());
+    }
+
+    @Override
+    public String toString() {
+      String str = "Slot: '" + slotName + "';  tp=" + tp + "\tfp=" + fp + "\tfn=" + fn + "\n";
+      str += "\tPrecision: \t" + precision() + "\n";
+      str += "\tRecall:    \t" + recall() + "\n";
+      str += "\tF1 Score:  \t" + f1Score() + "\n";
+      return str;
+    }
+
+    public double f1Score() {
+      return f1Score(precision(), recall());
+    }
+
+    public static double f1Score(double P, double R) {
+      if (P + R == 0)
+        return 0;
+      else
+        return (2 * P * R) / (P + R);
+    }
+
+    public double precision() {
+      double v = tp + fp;
+      if (v == 0)
+        return 0;
+      else
+        return (tp) / v;
+    }
+
+    public double recall() {
+      double v = tp + fn;
+      if (v == 0)
+        return 0;
+      else
+        return (tp) / v;
+    }
+  }
+
+  public static String[] getXMIfileNames(String folderName) {
+    File folder = new File(folderName);
+    File[] files = folder.listFiles(new FilenameFilter() {
+      public boolean accept(File dir, String name) {
+        return (name.endsWith(".xmi"));
+      }
+    });
+    ArrayList<String> resultList = new ArrayList<String>();
+    for (File f : files)
+      resultList.add(f.getAbsolutePath());
+
+    Comparator<String> cmp = new Comparator<String>() {
+
+      public int compare(String o1, String o2) {
+        return o1.compareTo(o2);
+      }
+
+    };
+    Collections.sort(resultList, cmp);
+    return resultList.toArray(new String[0]);
+  }
+
+  public F1Scorer(String descriptorFile, String trainingFolder, String testFolder) {
+    this(TextRulerToolkit.loadAnalysisEngine(descriptorFile), trainingFolder, testFolder);
+  }
+
+  public F1Scorer(AnalysisEngine ae, String trainingFolder, String testFolder) {
+    this.ae = ae;
+
+    trainingDocuments = new ArrayList<TextRulerExampleDocument>();
+    CasCache casCache = new CasCache(5, this);
+
+    for (String fileName : getXMIfileNames(trainingFolder))
+      trainingDocuments.add(new TextRulerExampleDocument(fileName, casCache));
+    testFileNames = getXMIfileNames(testFolder);
+  }
+
+  public Score scoreSlot(String slotName) {
+    Score result = new Score();
+    // TODO set a learner here... or something else...
+    TextRulerTarget target = new TextRulerTarget(slotName, null);
+    result.slotName = slotName;
+    int index = 0;
+    CAS testCAS = null;
+    for (TextRulerExampleDocument doc : trainingDocuments) {
+      CAS exampleCAS = doc.getCAS();
+      if (index >= testFileNames.length) {
+        TextRulerToolkit.log("ABORTING DUE TO NON TEST-EXISTENT FILE! ");
+        break;
+      }
+      testCAS = loadCAS(testFileNames[index], testCAS);
+      if (!testCAS.getDocumentText().equals((exampleCAS.getDocumentText()))) {
+        TextRulerToolkit.log("ERROR, EXAMPLE AND TEST DOCUMENT MISMATCH! WRONG FILE ORDER?");
+        return null;
+      }
+
+      doc.clearCurrentExamples();
+      doc.createExamplesForTarget(target);
+      compareOriginalDocumentWithTestCAS(doc, testCAS, target, result);
+      testCAS.reset();
+      index++;
+    }
+    testCAS.reset();
+    GlobalCASSource.releaseCAS(testCAS); // testCAS.release();
+    return result;
+  }
+
+  // based on TextRulerBasicLearner's method:
+  protected void compareOriginalDocumentWithTestCAS(TextRulerExampleDocument originalDoc,
+          CAS testCas, TextRulerTarget target, Score theScore) {
+    List<TextRulerExample> originalPositives = originalDoc.getPositiveExamples();
+    List<TextRulerExample> testPositives = originalDoc.createSlotInstancesForCAS(testCas, target,
+            true);
+
+    for (TextRulerExample e : testPositives) {
+      TextRulerExample coveredExample = TextRulerToolkit.exampleListContainsAnnotation(
+              originalPositives, e.getAnnotation());
+      if (coveredExample != null) {
+        originalPositives.remove(coveredExample);
+        theScore.tp++;
+      } else
+        theScore.fp++;
+    }
+
+    // all remaining positives are missing positives (false negatives)
+    theScore.fn += originalPositives.size();
+  }
+
+  public static void main(String[] args) {
+    // RAPIER
+    // TextRulerToolkit.log("stime = "+Score.f1Score(93.9, 92.9));
+    // TextRulerToolkit.log("etime = "+Score.f1Score(95.8, 94.6));
+    // TextRulerToolkit.log("loc   = "+Score.f1Score(91.0, 60.5));
+    // TextRulerToolkit.log("speak = "+Score.f1Score(80.9, 39.4));
+
+    // WHISK
+    // TextRulerToolkit.log("stime = "+Score.f1Score(86.2, 100.0));
+    // TextRulerToolkit.log("etime = "+Score.f1Score(85.0, 87.2));
+    // TextRulerToolkit.log("loc   = "+Score.f1Score(83.6, 55.4));
+    // TextRulerToolkit.log("speak = "+Score.f1Score(52.6, 11.1));
+
+    // // SRV
+    // TextRulerToolkit.log("stime = "+Score.f1Score(98.4, 98.3));
+    // TextRulerToolkit.log("etime = "+Score.f1Score(66.7, 92.6));
+    // TextRulerToolkit.log("loc   = "+Score.f1Score(73.8, 69.5));
+    // TextRulerToolkit.log("speak = "+Score.f1Score(54.9, 58.3));
+
+    F1Scorer scorer = new F1Scorer(
+            // "/testinput/f1test2/desc/lp2ergebnisrandomgiantEngine.xml",
+            // "/testinput/f1test2/original",
+            // // "/testinput/f1test/fromSystem"
+            // "/Users/tobi/Documents/runtime-EclipseApplication/MLSandBox/output"
+            "/Users/tobi/Documents/runtime-EclipseApplication/MLSandBox/descriptor/org.apache.uima.ml/lp2validateEngine.xml",
+            "/Users/tobi/Documents/UniLaptop/Diplomarbeit/TestDataSets/withPosTags/Subset100/5fold/2/testing/withtags",
+            "/Users/tobi/Documents/runtime-EclipseApplication/MLSandBox/output");
+    Score score = scorer.scoreSlot("org.apache.uima.ml.types.stime");
+    // Score score = scorer.scoreSlot("org.apache.uima.ml.types.location");
+    if (score != null)
+      score.logInfo();
+  }
+
+  public CAS loadCAS(String fileName, CAS reuseCAS) {
+    return TextRulerToolkit.readCASfromXMIFile(fileName, ae, reuseCAS);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/F1Scorer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.tools;
+
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/MemoryWatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,108 @@
+/*
+ * 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.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.textmarker.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("org.apache.uima.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/org.apache.uima.ml/types.tm";
+
+    convertFilesInFolder(inputFolder, outputFolder, tmScriptFileForEngine);
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/SGMLToXMIConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,206 @@
+/*
+ * 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.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.textmarker.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/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/tools/TestSetGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,414 @@
+/*
+ * 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.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.textmarker.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/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/AddRemoveList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java?rev=1157037&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java Fri Aug 12 10:32:50 2011
@@ -0,0 +1,105 @@
+/*
+ * 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.List;
+
+import org.apache.uima.textmarker.textruler.TextRulerPlugin;
+import org.apache.uima.textmarker.textruler.extension.TextRulerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerController;
+import org.apache.uima.textmarker.textruler.extension.TextRulerLearnerParameter;
+import org.apache.uima.textmarker.textruler.preferences.AlgorithmPreferencePage;
+import org.apache.uima.textmarker.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.textmarker.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.textmarker.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/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/src/main/java/org/apache/uima/textmarker/textruler/ui/ConfigureLearnersHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain