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 17:36:03 UTC
svn commit: r1152831 [3/5] - in
/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing: ./
META-INF/ bin/ icons/ icons/oldIcons/ icons/otherIcons/ schema/ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main...
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,269 @@
+package org.apache.uima.tm.textmarker.testing.evaluator;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.CASRuntimeException;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.tm.textmarker.seed.DefaultSeeder;
+
+
+public class WordTemplateCasEvaluator implements ICasEvaluator {
+
+ @Override
+ public CAS evaluate(CAS test, CAS run, Collection<String> excludedTypes)
+ throws CASRuntimeException, CASException {
+ Type falsePositiveType = run.getTypeSystem().getType(ICasEvaluator.FALSE_POSITIVE);
+ Type falseNegativeType = run.getTypeSystem().getType(ICasEvaluator.FALSE_NEGATIVE);
+ Type truePositveType = run.getTypeSystem().getType(ICasEvaluator.TRUE_POSITIVE);
+ Feature feature = falsePositiveType.getFeatureByBaseName(ICasEvaluator.ORIGINAL);
+ List<Type> allTypes = test.getTypeSystem().getProperlySubsumedTypes(
+ test.getTypeSystem().getTopType());
+ List<Type> types = new ArrayList<Type>();
+
+ TypeSystem typeSystem = test.getTypeSystem();
+ Type annotationType = test.getAnnotationType();
+ for (Type eachType : allTypes) {
+ if (!excludedTypes.contains(eachType.getName())) {
+ List<Feature> features = eachType.getFeatures();
+ for (Feature f : features) {
+ Type range = f.getRange();
+ if (typeSystem.subsumes(annotationType, range)) {
+ if (!eachType.getName().startsWith("org.apache.uima.tm.textmarker.kernel.type")) {
+ types.add(eachType);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ List<Type> wordTypes = getWordTypes(run);
+ Collection<FeatureStructure> testFSs = getFeatureStructures(types, test, wordTypes);
+ Collection<FeatureStructure> runFSs = getFeatureStructures(types, run, wordTypes);
+
+ Collection<FeatureStructure> matched = new HashSet<FeatureStructure>();
+ List<FeatureStructure> fp = new ArrayList<FeatureStructure>();
+ List<FeatureStructure> fn = new ArrayList<FeatureStructure>();
+ List<FeatureStructure> tp = new ArrayList<FeatureStructure>();
+
+ if (test.getAnnotationIndex(
+ test.getTypeSystem().getType("org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic"))
+ .size() == 0) {
+ // need basics in this test cas too:
+ final DefaultSeeder scanner = new DefaultSeeder();
+ scanner.seed(test.getDocumentText(), test);
+ }
+ for (FeatureStructure eachTest : testFSs) {
+ boolean found = false;
+ for (FeatureStructure eachRun : runFSs) {
+ if (match(eachTest, eachRun, wordTypes)) {
+ matched.add(eachRun);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ FeatureStructure createFS = run.createFS(falseNegativeType);
+ fillFS(eachTest, createFS, false);
+ Type type = run.getTypeSystem().getType(eachTest.getType().getName());
+ FeatureStructure original = run.createFS(type);
+ fillFS(eachTest, original, true);
+ createFS.setFeatureValue(feature, original);
+ fn.add(createFS);
+ } else {
+ FeatureStructure createFS = run.createFS(truePositveType);
+ fillFS(eachTest, createFS, false);
+ Type type = run.getTypeSystem().getType(eachTest.getType().getName());
+ FeatureStructure original = run.createFS(type);
+ fillFS(eachTest, original, true);
+ createFS.setFeatureValue(feature, original);
+ tp.add(createFS);
+ }
+ }
+
+ for (FeatureStructure each : runFSs) {
+ if (!matched.contains(each)) {
+ FeatureStructure createFS = run.createFS(falsePositiveType);
+ fillFS(each, createFS, false);
+ Type type = run.getTypeSystem().getType(each.getType().getName());
+ FeatureStructure original = run.createFS(type);
+ fillFS(each, original, true);
+ createFS.setFeatureValue(feature, original);
+ fp.add(createFS);
+ }
+ }
+
+ for (FeatureStructure fs : fn) {
+ run.addFsToIndexes(fs);
+ }
+ for (FeatureStructure fs : fp) {
+ run.addFsToIndexes(fs);
+ }
+ for (FeatureStructure fs : tp) {
+ run.addFsToIndexes(fs);
+ }
+ return run;
+ }
+
+ private List<Type> getWordTypes(CAS test) {
+ List<Type> result = new ArrayList<Type>();
+ result.add(test.getTypeSystem().getType("org.apache.uima.tm.type.W"));
+ result.add(test.getTypeSystem().getType("org.apache.uima.tm.type.NUM"));
+ return result;
+ }
+
+ private void fillFS(FeatureStructure fs, FeatureStructure newFS, boolean withFeatures) {
+ if (fs instanceof AnnotationFS) {
+ Annotation a = (Annotation) newFS;
+ a.setBegin(((AnnotationFS) fs).getBegin());
+ a.setEnd(((AnnotationFS) fs).getEnd());
+ }
+ if (withFeatures) {
+ CAS testCas = fs.getCAS();
+ CAS runCas = newFS.getCAS();
+ TypeSystem testTS = testCas.getTypeSystem();
+ TypeSystem runTS = runCas.getTypeSystem();
+ Type annotationType = testCas.getAnnotationType();
+ List<Feature> features = fs.getType().getFeatures();
+ for (Feature feature : features) {
+ Type range = feature.getRange();
+ if (testTS.subsumes(annotationType, range)) {
+ FeatureStructure valueTest = fs.getFeatureValue(feature);
+ if (valueTest instanceof AnnotationFS) {
+ AnnotationFS a1 = (AnnotationFS) valueTest;
+ Feature feature2 = newFS.getType().getFeatureByBaseName(feature.getShortName());
+ if (feature != null) {
+ Type range2 = runTS.getType(range.getName());
+ AnnotationFS createAnnotation = runCas.createAnnotation(range2, a1.getBegin(), a1
+ .getEnd());
+ newFS.setFeatureValue(feature2, createAnnotation);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private Collection<FeatureStructure> getFeatureStructures(List<Type> types, CAS cas,
+ List<Type> basicTypes) {
+ TypeSystem typeSystem = cas.getTypeSystem();
+ Type annotationType = cas.getAnnotationType();
+ Collection<FeatureStructure> result = new HashSet<FeatureStructure>();
+ for (Type type : types) {
+ FSIterator<FeatureStructure> iterator = cas.getIndexRepository().getAllIndexedFS(type);
+ while (iterator.isValid()) {
+ FeatureStructure fs = iterator.get();
+ List<Feature> features = fs.getType().getFeatures();
+ for (Feature feature : features) {
+ Type range = feature.getRange();
+ if (typeSystem.subsumes(annotationType, range)) {
+ result.add(fs);
+ break;
+ }
+ }
+ iterator.moveToNext();
+ }
+ }
+ return result;
+ }
+
+ private List<AnnotationFS> expand(AnnotationFS a, CAS cas, List<Type> basicTypes) {
+ List<AnnotationFS> result = new LinkedList<AnnotationFS>();
+ for (Type basicType : basicTypes) {
+ AnnotationFS window = cas.createAnnotation(basicType, a.getBegin(), a.getEnd());
+ FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(basicType).subiterator(window);
+ while (iterator.isValid()) {
+ AnnotationFS basic = iterator.get();
+ if (cas.getTypeSystem().subsumes(basicType, basic.getType())
+ && basic.getBegin() >= a.getBegin() && basic.getEnd() <= a.getEnd()) {
+ result.add(cas.createAnnotation(a.getType(), basic.getBegin(), basic.getEnd()));
+ }
+ iterator.moveToNext();
+ }
+ }
+ return result;
+ }
+
+ private boolean match(FeatureStructure a1, FeatureStructure a2, List<Type> basicTypes) {
+ Type type1 = a1.getType();
+ Type type2 = a2.getType();
+ if (!type1.getName().equals(type2.getName())) {
+ return false;
+ }
+
+ if (a1 instanceof AnnotationFS && a2 instanceof AnnotationFS) {
+ AnnotationFS a11 = (AnnotationFS) a1;
+ AnnotationFS a22 = (AnnotationFS) a2;
+ if (!(a11.getBegin() == a22.getBegin() && a11.getEnd() == a22.getEnd())) {
+ return false;
+ }
+ }
+ CAS cas = a1.getCAS();
+ TypeSystem typeSystem = cas.getTypeSystem();
+ Type annotationType = cas.getAnnotationType();
+ List<Feature> features1 = type1.getFeatures();
+ boolean result = true;
+ boolean allEmpty1 = true;
+ boolean allEmpty2 = true;
+ for (Feature eachFeature1 : features1) {
+ Type range = eachFeature1.getRange();
+ if (typeSystem.subsumes(annotationType, range)) {
+ String name = eachFeature1.getShortName();
+ Feature eachFeature2 = type2.getFeatureByBaseName(name);
+ FeatureStructure featureValue1 = a1.getFeatureValue(eachFeature1);
+ FeatureStructure featureValue2 = a2.getFeatureValue(eachFeature2);
+ allEmpty1 &= featureValue1 == null;
+ allEmpty2 &= featureValue2 == null;
+ if (featureValue1 instanceof AnnotationFS && featureValue2 instanceof AnnotationFS) {
+ result &= matchAnnotations((AnnotationFS) featureValue1, (AnnotationFS) featureValue2,
+ basicTypes);
+ } else if (featureValue1 == null) {
+ // nothing to do
+ } else if (featureValue1 != null || featureValue2 != null) {
+ return false;
+ }
+ }
+ }
+ return result && (allEmpty1 == allEmpty2);
+ }
+
+ private boolean matchAnnotations(AnnotationFS a1, AnnotationFS a2, List<Type> basicTypes) {
+ List<AnnotationFS> w1 = expand(a1, a1.getCAS(), basicTypes);
+ List<AnnotationFS> w2 = expand(a2, a2.getCAS(), basicTypes);
+ boolean result = true;
+ int i = 0;
+ for (AnnotationFS each1 : w1) {
+ if (w2.size() > i) {
+ AnnotationFS each2 = w2.get(i);
+ result &= matchWord(each1, each2);
+ } else {
+ return false;
+ }
+ i++;
+ }
+ return result;
+ }
+
+ private boolean matchWord(AnnotationFS a1, AnnotationFS a2) {
+ if (a1 != null && a2 != null) {
+ if (a1.getBegin() == a2.getBegin() && a1.getEnd() == a2.getEnd()
+ && a1.getType().getName().equals(a2.getType().getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,13 @@
+package org.apache.uima.tm.textmarker.testing.evaluator;
+
+public class WordTemplateCasEvaluatorFactory implements ICasEvaluatorFactory {
+
+ public ICasEvaluator createEvaluator() {
+ return new WordTemplateCasEvaluator();
+ }
+
+ public String getDescription() {
+ return "Complex feature structures that provide at least one annotation as a feature value are compared. A template feature structure is a true positive if all all feature values are correct. Here, the word level evaluator is applied for the comparisionof the feature values.";
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/evaluator/WordTemplateCasEvaluatorFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,11 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+public class DescriptionChangedListener implements IDescriptionChangedListener {
+
+ @Override
+ public void descriptionChanged(String description) {
+
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionChangedListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,290 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+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.Group;
+
+public class DescriptionRadioGroupFieldEditor extends FieldEditor {
+
+ private IDescriptionChangedListener descriptionChangedListener;
+
+ /**
+ * List of radio button entries of the form [label,value].
+ */
+ private String[][] labelsAndValues;
+
+ /**
+ * Number of columns into which to arrange the radio buttons.
+ */
+ private int numColumns;
+
+ /**
+ * Indent used for the first column of the radion button matrix.
+ */
+ private int indent = HORIZONTAL_GAP;
+
+ /**
+ * The current value, or <code>null</code> if none.
+ */
+ private String value;
+
+ /**
+ * The box of radio buttons, or <code>null</code> if none (before creation and after disposal).
+ */
+ private Composite radioBox;
+
+ /**
+ * The radio buttons, or <code>null</code> if none (before creation and after disposal).
+ */
+ private Button[] radioButtons;
+
+ /**
+ * Whether to use a Group control.
+ */
+ private boolean useGroup;
+
+ public DescriptionRadioGroupFieldEditor(String name, String labelText, int numColumns,
+ String[][] labelAndValues, Composite parent, boolean useGroup) {
+ init(name, labelText);
+ Assert.isTrue(checkArray(labelAndValues));
+ this.labelsAndValues = labelAndValues;
+ this.numColumns = numColumns;
+ this.useGroup = useGroup;
+ createControl(parent);
+ }
+
+ public DescriptionRadioGroupFieldEditor(String name, String labelText, int numColumns,
+ String[][] labelAndValues, Composite parent) {
+ this(name,labelText,numColumns,labelAndValues,parent,false);
+
+
+ }
+
+ @Override
+ protected void adjustForNumColumns(int numColumns) {
+ Control control = getLabelControl();
+ if (control != null) {
+ ((GridData) control.getLayoutData()).horizontalSpan = numColumns;
+ }
+ ((GridData) radioBox.getLayoutData()).horizontalSpan = numColumns;
+}
+
+/**
+ * Checks whether given <code>String[][]</code> is of "type"
+ * <code>String[][2]</code>.
+ * @param table
+ *
+ * @return <code>true</code> if it is ok, and <code>false</code> otherwise
+ */
+private boolean checkArray(String[][] table) {
+ if (table == null)
+ return false;
+ for (int i = 0; i < table.length; i++) {
+ String[] array = table[i];
+ if (array == null || array.length != 2)
+ return false;
+ }
+ return true;
+}
+
+/* (non-Javadoc)
+ * Method declared on FieldEditor.
+ */
+@Override
+protected void doFillIntoGrid(Composite parent, int numColumns) {
+ if (useGroup) {
+ Control control = getRadioBoxControl(parent);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ control.setLayoutData(gd);
+ } else {
+ Control control = getLabelControl(parent);
+ GridData gd = new GridData();
+ gd.horizontalSpan = numColumns;
+ control.setLayoutData(gd);
+ control = getRadioBoxControl(parent);
+ gd = new GridData();
+ gd.horizontalSpan = numColumns;
+ gd.horizontalIndent = indent;
+ control.setLayoutData(gd);
+ }
+
+}
+
+/* (non-Javadoc)
+ * Method declared on FieldEditor.
+ */
+@Override
+protected void doLoad() {
+ updateValue(getPreferenceStore().getString(getPreferenceName()));
+}
+
+/* (non-Javadoc)
+ * Method declared on FieldEditor.
+ */
+@Override
+protected void doLoadDefault() {
+ updateValue(getPreferenceStore().getDefaultString(getPreferenceName()));
+}
+
+/* (non-Javadoc)
+ * Method declared on FieldEditor.
+ */
+@Override
+protected void doStore() {
+ if (value == null) {
+ getPreferenceStore().setToDefault(getPreferenceName());
+ return;
+ }
+
+ getPreferenceStore().setValue(getPreferenceName(), value);
+}
+
+/* (non-Javadoc)
+ * Method declared on FieldEditor.
+ */
+@Override
+public int getNumberOfControls() {
+ return 1;
+}
+
+/**
+ * Returns this field editor's radio group control.
+ * @param parent The parent to create the radioBox in
+ * @return the radio group control
+ */
+public Composite getRadioBoxControl(Composite parent) {
+ if (radioBox == null) {
+
+ Font font = parent.getFont();
+
+ if (useGroup) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setFont(font);
+ String text = getLabelText();
+ if (text != null)
+ group.setText(text);
+ radioBox = group;
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = HORIZONTAL_GAP;
+ layout.numColumns = numColumns;
+ radioBox.setLayout(layout);
+ } else {
+ radioBox = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ layout.horizontalSpacing = HORIZONTAL_GAP;
+ layout.numColumns = numColumns;
+ radioBox.setLayout(layout);
+ radioBox.setFont(font);
+ }
+
+ radioButtons = new Button[labelsAndValues.length];
+ for (int i = 0; i < labelsAndValues.length; i++) {
+ Button radio = new Button(radioBox, SWT.RADIO | SWT.LEFT);
+ radioButtons[i] = radio;
+ String[] labelAndValue = labelsAndValues[i];
+ radio.setText(labelAndValue[0]);
+ radio.setData(labelAndValue[1]);
+ radio.setFont(font);
+ radio.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ String oldValue = value;
+ value = (String) event.widget.getData();
+ setPresentsDefaultValue(false);
+ fireValueChanged(VALUE, oldValue, value);
+ if(descriptionChangedListener != null) {
+ descriptionChangedListener.descriptionChanged(value);
+ }
+ }
+ });
+ }
+ radioBox.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ radioBox = null;
+ radioButtons = null;
+ }
+ });
+ } else {
+ checkParent(radioBox, parent);
+ }
+ return radioBox;
+}
+
+/**
+ * Sets the indent used for the first column of the radion button matrix.
+ *
+ * @param indent the indent (in pixels)
+ */
+public void setIndent(int indent) {
+ if (indent < 0)
+ this.indent = 0;
+ else
+ this.indent = indent;
+}
+
+/**
+ * Select the radio button that conforms to the given value.
+ *
+ * @param selectedValue the selected value
+ */
+private void updateValue(String selectedValue) {
+ this.value = selectedValue;
+ if (radioButtons == null)
+ return;
+
+ if (this.value != null) {
+ boolean found = false;
+ for (int i = 0; i < radioButtons.length; i++) {
+ Button radio = radioButtons[i];
+ boolean selection = false;
+ if (((String) radio.getData()).equals(this.value)) {
+ selection = true;
+ found = true;
+ }
+ radio.setSelection(selection);
+ }
+ if (found)
+ return;
+ }
+
+ // We weren't able to find the value. So we select the first
+ // radio button as a default.
+ if (radioButtons.length > 0) {
+ radioButtons[0].setSelection(true);
+ this.value = (String) radioButtons[0].getData();
+ }
+ return;
+}
+
+/*
+ * @see FieldEditor.setEnabled(boolean,Composite).
+ */
+@Override
+public void setEnabled(boolean enabled, Composite parent) {
+ if (!useGroup)
+ super.setEnabled(enabled, parent);
+ for (int i = 0; i < radioButtons.length; i++) {
+ radioButtons[i].setEnabled(enabled);
+ }
+
+}
+
+public void setDescriptionChangedListener (IDescriptionChangedListener listener) {
+ descriptionChangedListener = listener;
+}
+
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/DescriptionRadioGroupFieldEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,6 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+public interface IDescriptionChangedListener {
+
+ public void descriptionChanged(String description);
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/IDescriptionChangedListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,51 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.testing.TestingPlugin;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+
+
+public class TestingPreferenceConstants {
+
+ public static final String EVALUATOR_FACTORY = "EVALUATOR_FACTORY";
+
+ public static final String DEFAULT_EVALUATOR_FACTORY = "org.apache.uima.tm.textmarker.testing.exactCasEvaluator";
+
+ public static final String AUTOMATED_FILE_SYNCRONIZATION = "AUTOMATED_FILE_SYNCRONIZATION";
+
+ public static final String LOAD_OLD_TEST_RESULTS = "LOAD_OLD_TEST_RESULTS";
+
+ public static String[][] EVALUATORS = getEvaluators();
+
+ public static String[][] getEvaluators() {
+
+ List<String[]> result = new ArrayList<String[]>();
+ int size = 0;
+
+ IExtension[] evalExtensions = Platform.getExtensionRegistry().getExtensionPoint(
+ TestingPlugin.PLUGIN_ID, "evaluators").getExtensions();
+ for (IExtension extension : evalExtensions) {
+ IConfigurationElement[] configurationElements = extension.getConfigurationElements();
+ for (IConfigurationElement configurationElement : configurationElements) {
+ size++;
+ }
+ }
+
+ String[][] evalFactories = new String[size][2];
+ int count = 0;
+ for (IExtension extension : evalExtensions) {
+ IConfigurationElement[] configurationElements = extension.getConfigurationElements();
+ for (IConfigurationElement configurationElement : configurationElements) {
+ evalFactories[count][0] = configurationElement.getAttribute("name");
+ evalFactories[count][1] = configurationElement.getAttribute("id");
+ count++;
+ }
+ }
+ return evalFactories;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,23 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+import org.apache.uima.tm.textmarker.testing.TestingPlugin;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+
+public class TestingPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ @Override
+ public void initializeDefaultPreferences () {
+ IPreferenceStore store = TestingPlugin.getDefault().getPreferenceStore();
+
+ store.setDefault(TestingPreferenceConstants.EVALUATOR_FACTORY,
+ TestingPreferenceConstants.DEFAULT_EVALUATOR_FACTORY);
+
+ store.setDefault(TestingPreferenceConstants.AUTOMATED_FILE_SYNCRONIZATION, "0");
+ store.setDefault(TestingPreferenceConstants.LOAD_OLD_TEST_RESULTS, "0");
+
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferenceInitializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,109 @@
+package org.apache.uima.tm.textmarker.testing.preferences;
+
+import org.apache.uima.tm.textmarker.testing.TestingPlugin;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+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.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class TestingPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ public static String ID = "org.apache.uima.tm.textmarker.testing.preferences";
+
+ private Text desc;
+
+ private Label evalHeadline;
+
+ private DescriptionRadioGroupFieldEditor evaluators;
+
+ private BooleanFieldEditor sync;
+
+ private BooleanFieldEditor oldResults;
+
+ public TestingPreferencePage() {
+ IPreferenceStore store = TestingPlugin.getDefault().getPreferenceStore();
+ setPreferenceStore(store);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite top = new Composite(parent, SWT.LEFT);
+ top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ top.setLayout(new GridLayout());
+
+ sync = new BooleanFieldEditor(TestingPreferenceConstants.AUTOMATED_FILE_SYNCRONIZATION,
+ "Synchronize Test-Files and Workspace automatically", top);
+ sync.setPage(this);
+ sync.setPreferenceStore(getPreferenceStore());
+ sync.load();
+
+ oldResults = new BooleanFieldEditor(TestingPreferenceConstants.LOAD_OLD_TEST_RESULTS,
+ "Load test results from previous sessions", top);
+ oldResults.setPage(this);
+ oldResults.setPreferenceStore(getPreferenceStore());
+ oldResults.load();
+
+ evaluators = new DescriptionRadioGroupFieldEditor(TestingPreferenceConstants.EVALUATOR_FACTORY,
+ "Evaluator :", 1, TestingPreferenceConstants.EVALUATORS, top);
+
+ evaluators.setPage(this);
+ evaluators.setPreferenceStore(getPreferenceStore());
+ evaluators.load();
+
+ IDescriptionChangedListener listener = new IDescriptionChangedListener() {
+ public void descriptionChanged(String s) {
+ String text = TestingPlugin.getCasEvaluatorFactoryById(s).getDescription();
+ desc.setText(text);
+ desc.update();
+ desc.redraw();
+ }
+ };
+
+ evaluators.setDescriptionChangedListener(listener);
+ evalHeadline = new Label(top, SWT.NULL);
+ evalHeadline.setText("Description:");
+
+ desc = new Text(top, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ desc.setText(getEvalDesc());
+ desc.setBackground(this.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE));
+ desc.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return top;
+ }
+
+ public String getEvalDesc() {
+ return TestingPlugin.getCasEvaluatorFactoryById(
+ getPreferenceStore().getString(TestingPreferenceConstants.EVALUATOR_FACTORY))
+ .getDescription();
+ }
+
+ protected void loadDefaults() {
+ sync.loadDefault();
+ oldResults.loadDefault();
+ evaluators.loadDefault();
+ super.performDefaults();
+ }
+
+ @Override
+ public boolean performOk() {
+ sync.store();
+ oldResults.store();
+ evaluators.store();
+ return super.performOk();
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/preferences/TestingPreferencePage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,52 @@
+package org.apache.uima.tm.textmarker.testing.searchStrategy;
+
+import org.apache.uima.tm.cev.extension.ICEVSearchStrategy;
+import org.apache.uima.tm.dltk.internal.core.builder.TextMarkerProjectUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+
+public class TestingSearchStrategy implements ICEVSearchStrategy {
+
+ private int priority;
+
+ public TestingSearchStrategy(int priority) {
+ super();
+ this.priority = priority;
+ }
+
+ @Override
+ public int getPriority() {
+ return priority;
+ }
+
+ @Override
+ public IFile searchDescriptor(IFile file) {
+ IPath location = file.getLocation();
+ IProject project = file.getProject();
+ IFolder testFolder = project.getFolder(TextMarkerProjectUtils.getDefaultTestLocation());
+ IFolder descFolder = project.getFolder(TextMarkerProjectUtils.getDefaultDescriptorLocation());
+ IPath relativeTo = location.makeRelativeTo(testFolder.getLocation());
+ IPath segments = relativeTo.removeLastSegments(2);
+ String scriptName = segments.lastSegment();
+ scriptName += "TypeSystem.xml";
+ segments = segments.removeLastSegments(1);
+ IFolder descPackageFolder = null;
+ try {
+ descPackageFolder = descFolder.getFolder(segments);
+ } catch (Exception e) {
+ return null;
+ }
+ if (descPackageFolder == null || !descPackageFolder.exists()) {
+ return null;
+ }
+ IFile result = descPackageFolder.getFile(scriptName);
+ if (result == null || !result.exists()) {
+ return null;
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.testing.searchStrategy;
+
+import org.apache.uima.tm.cev.extension.ICEVSearchStrategy;
+import org.apache.uima.tm.cev.extension.ICEVSearchStrategyFactory;
+
+public class TestingSearchStrategyFactory implements ICEVSearchStrategyFactory {
+
+ public TestingSearchStrategyFactory() {
+ }
+
+ @Override
+ public ICEVSearchStrategy createSearchStrategy(int priority) {
+ return new TestingSearchStrategy(priority);
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/searchStrategy/TestingSearchStrategyFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,67 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.EvalDataDialog;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestCasData;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+import org.apache.uima.tm.textmarker.testing.ui.views.evalDataTable.TypeEvalData;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class ExportTabelHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
+
+ TableViewer viewer = debugPage.getViewer();
+
+ Shell shell = HandlerUtil.getActiveShell(event);
+
+ String evalData = "Test File,Type,TP,FP,FN,Recall,Prec,F-1\n";
+
+
+ ArrayList<TestCasData> dataList = (ArrayList)viewer.getInput();
+
+ for (TestCasData entry : dataList) {
+ Collection<TypeEvalData> col = entry.getTypeEvalData().values();
+ for (TypeEvalData data : col) {
+ if (!data.getTypeName().equals("Total")) {
+
+
+
+ String column = entry.getPath().lastSegment() + ","
+ + data.getTypeName() + ","
+ + String.valueOf(data.getTruePositives()) + ","
+ + String.valueOf(data.getFalsePositives()) + ","
+ + String.valueOf(data.getFalseNegatives()) + ","
+ + String.valueOf(data.getRecall()) + ","
+ + String.valueOf(data.getPrecision()) + ","
+ + String.valueOf(data.getFOne())
+ + "\n";
+ evalData = evalData+ column;
+ }
+ }
+
+ }
+
+ EvalDataDialog dialog = new EvalDataDialog(shell, evalData);
+ dialog.open();
+
+// MessageDialog.openConfirm(shell, "Evaluation Data", text);
+
+ return null;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/ExportTabelHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,129 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.TestCasData;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+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.core.internal.resources.Folder;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class LoadFilesFromFolderHandler implements IHandler {
+
+ TestPageBookView debugView;
+
+ TestViewPage debugPage;
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ debugPage = (TestViewPage) debugView.getCurrentPage();
+ IProject project = debugPage.getResource().getProject();
+
+ IViewPart scriptExpl = HandlerUtil.getActiveSite(event).getWorkbenchWindow().getActivePage()
+ .findView("org.eclipse.dltk.ui.ScriptExplorer");
+ ISelection select = scriptExpl.getViewSite().getSelectionProvider().getSelection();
+
+ if (select != null && select instanceof StructuredSelection) {
+ StructuredSelection structSelect = (StructuredSelection) select;
+ Iterator iter = structSelect.iterator();
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof Folder) {
+ Folder folder = (Folder) o;
+ IPath path2Folder = folder.getFullPath().removeFirstSegments(1);
+ IFolder testFolder = project.getFolder(path2Folder);
+
+ loadFolder(testFolder);
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void loadFolder(IFolder folder) {
+ try {
+ IResource[] children = folder.members();
+ for (IResource r : children) {
+ // if (r instanceof IFolder) {
+ // loadFolder((IFolder)r);
+ // }
+ if (r instanceof IFile) {
+ if (r != null && r instanceof IFile && r.getLocation().getFileExtension().equals("xmi")) {
+ add2Viewer(r.getLocation());
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void add2Viewer(IPath p) {
+
+ TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
+
+ TableViewer viewer = debugPage.getViewer();
+
+ if (viewer.getInput() instanceof ArrayList) {
+ ArrayList input = (ArrayList) debugPage.getViewer().getInput();
+ input.add(new TestCasData(p));
+ viewer.refresh();
+
+ if (input.get(0) != null) {
+ TestCasData data = (TestCasData) input.get(0);
+ if (data.wasEvaluated()) {
+ debugPage.updateSingleTestInformation(data);
+ }
+ }
+ }
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/LoadFilesFromFolderHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,52 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+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 NextTestCaseHandler implements IHandler {
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ TestViewPage page = (TestViewPage) debugView.getCurrentPage();
+ page.nextState();
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/NextTestCaseHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,53 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+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 PreviousTestCaseHandler implements IHandler {
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ TestViewPage page = (TestViewPage) debugView.getCurrentPage();
+ page.previousState();
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/PreviousTestCaseHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,71 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.TestCasData;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+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.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class RemoveTestsHandler implements IHandler {
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ TestViewPage activePage = (TestViewPage) debugView.getCurrentPage();
+ activePage.saveState();
+ TableViewer viewer = activePage.getViewer();
+ List list = (List) viewer.getInput();
+ if (viewer.getSelection() == null) {
+ // TODO Refactor this
+ } else if (viewer.getSelection() instanceof StructuredSelection) {
+ StructuredSelection selection = (StructuredSelection) viewer.getSelection();
+ Iterator<TestCasData> iter = selection.iterator();
+ while (iter.hasNext()) {
+ list.remove(iter.next());
+ }
+ }
+ viewer.refresh(false);
+ // debugView.saveState();
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RemoveTestsHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,368 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.tm.dltk.core.TextMarkerPlugin;
+import org.apache.uima.tm.dltk.internal.core.builder.TextMarkerProjectUtils;
+import org.apache.uima.tm.textmarker.kernel.type.EvalAnnotation;
+import org.apache.uima.tm.textmarker.testing.TestingPlugin;
+import org.apache.uima.tm.textmarker.testing.evaluator.ICasEvaluator;
+import org.apache.uima.tm.textmarker.testing.preferences.TestingPreferenceConstants;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestCasData;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestPageBookView;
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+import org.apache.uima.tm.textmarker.testing.ui.views.evalDataTable.TypeEvalData;
+import org.apache.uima.tm.textmarker.testing.ui.views.util.EvalDataProcessor;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLSerializer;
+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.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.xml.sax.SAXException;
+
+
+public class RerunActionHandler implements IHandler {
+
+ private class DebugJobChangeAdapter extends JobChangeAdapter {
+
+ private TestViewPage page;
+
+ DebugJobChangeAdapter(TestViewPage page) {
+ super();
+ this.page = page;
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ if (event.getResult().isOK()) {
+ page.getControl().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ page.updateInfoPanel();
+ }
+ });
+ }
+ }
+ }
+
+ private class RerunHandlerJob extends Job {
+ ExecutionEvent event;
+
+ String viewCasName;
+
+ RerunHandlerJob(ExecutionEvent event, String scriptName, String viewCasName) {
+ super("Testing " + scriptName + "...");
+ this.event = event;
+ this.viewCasName = viewCasName;
+ setUser(true);
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ final TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ final TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
+ debugPage.saveState();
+ debugView.showBusy(true);
+ IResource r = debugPage.getResource();
+ ArrayList<TestCasData> testCasData = (ArrayList) debugPage.getViewer().getInput();
+ monitor.beginTask("Running evaluation, please wait", testCasData.size());
+ IProject project = r.getProject();
+ IPath engineDescriptorPath = TextMarkerProjectUtils.getEngineDescriptorPath(r.getLocation(),
+ project);
+ try {
+ XMLInputSource in = new XMLInputSource(engineDescriptorPath.toPortableString());
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+
+ String desc = null;
+ desc = engineDescriptorPath.toPortableString();
+ XMLInputSource in2 = new XMLInputSource(desc);
+ Object descriptor = UIMAFramework.getXMLParser().parse(in2);
+ CAS runCas = ae.newCAS();
+
+ for (TestCasData td : testCasData) {
+ runCas.reset();
+ String elementName = r.getLocation().lastSegment();
+ monitor.setTaskName("Evaluating " + td.getPath().lastSegment());
+ int lastIndexOf = elementName.lastIndexOf(".tm");
+ if (lastIndexOf != -1) {
+ elementName = elementName.substring(0, lastIndexOf);
+ }
+
+ CAS testCas = getTestCas(descriptor);
+ FileInputStream inputStream = null;
+ try {
+ inputStream = new FileInputStream(new File(td.getPath().toPortableString()));
+ XmiCasDeserializer.deserialize(inputStream, testCas, true);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+
+ for (Iterator<CAS> iterator = testCas.getViewIterator(); iterator.hasNext();) {
+ CAS each = (CAS) iterator.next();
+ String viewName = each.getViewName();
+ try {
+ CAS view = runCas.getView(viewName);
+ view.setDocumentText(each.getDocumentText());
+
+ } catch (Exception e) {
+ }
+ }
+
+ testCas = testCas.getView(viewCasName);
+ runCas = runCas.getView(viewCasName);
+
+ IPreferenceStore store = TestingPlugin.getDefault().getPreferenceStore();
+ String factoryName = store.getString(TestingPreferenceConstants.EVALUATOR_FACTORY);
+ ICasEvaluator evaluator = TestingPlugin.getCasEvaluatorFactoryById(factoryName)
+ .createEvaluator();
+
+ ae.process(runCas);
+ CAS resultCas = evaluator.evaluate(testCas, runCas, debugPage.getExcludedTypes());
+
+ IPath path2Test = td.getPath().removeLastSegments(1);
+
+ IPath estimatedTestPath = project.getFullPath().append(
+ TextMarkerProjectUtils.getDefaultTestLocation());
+ IPath path2recource = r.getFullPath();
+ IPath projectRelativePath2Script = path2recource.removeFirstSegments(2);
+ IPath estimatedTestFolderPath = estimatedTestPath.append(projectRelativePath2Script
+ .removeFileExtension());
+
+ IPath path2Result = path2Test.append(TestCasData.RESULT_FOLDER);
+ IPath path2ResultFile = path2Result.append(td.getPath().removeFileExtension()
+ .lastSegment()
+ + ".result.xmi");
+
+ if (!path2Test.toOSString().contains(estimatedTestFolderPath.toOSString())) {
+ path2Result = project.getLocation().append(
+ TextMarkerProjectUtils.getDefaultTestLocation()).append(
+ TextMarkerProjectUtils.getDefaultTempTestLocation());
+ path2ResultFile = path2Result.append(td.getPath().removeFileExtension().lastSegment()
+ + ".result.xmi");
+ }
+
+ File resultFile = new File(path2ResultFile.toPortableString());
+ writeXmi(resultCas, resultFile);
+
+ td.setResultPath(path2ResultFile);
+
+ // calculateEvaluatData(td, resultCas);
+
+ EvalDataProcessor.calculateEvaluatData(td, resultCas);
+
+ debugView.getDefaultPage().getControl().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ debugPage.getViewer().refresh();
+ }
+ });
+ monitor.worked(1);
+ r.getProject().getFolder(path2Result).refreshLocal(IResource.DEPTH_INFINITE,
+ new NullProgressMonitor());
+ runCas.release();
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+ }
+ } catch (Exception e) {
+ TextMarkerPlugin.error(e);
+ }
+
+ monitor.done();
+ debugView.showBusy(false);
+ return Status.OK_STATUS;
+
+ }
+
+ private CAS getTestCas(Object descriptor) throws ResourceInitializationException,
+ InvalidXMLException {
+ CAS testCas = null;
+ if (descriptor instanceof AnalysisEngineDescription) {
+ testCas = CasCreationUtils.createCas((AnalysisEngineDescription) descriptor);
+ } else if (descriptor instanceof TypeSystemDescription) {
+ TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
+ tsDesc.resolveImports();
+ testCas = CasCreationUtils.createCas(tsDesc, null, new FsIndexDescription[0]);
+ // TODO: where are the type priorities?
+ }
+ return testCas;
+ }
+ }
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
+
+ String viewCasName = debugPage.getSelectedViewCasName();
+ String scriptName = debugPage.getResource().getLocation().lastSegment();
+ RerunHandlerJob job = new RerunHandlerJob(event, scriptName, viewCasName);
+
+ job.addJobChangeListener(new DebugJobChangeAdapter(debugPage) {
+ });
+
+ job.schedule();
+
+ return null;
+ }
+
+ private static void writeXmi(CAS aCas, File name) throws IOException, SAXException {
+ FileOutputStream out = null;
+ try {
+ name.getParentFile().mkdirs();
+ if (!name.exists()) {
+ name.createNewFile();
+ }
+ out = new FileOutputStream(name);
+ XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
+ XMLSerializer xmlSer = new XMLSerializer(out, false);
+ ser.serialize(aCas, xmlSer.getContentHandler());
+ } catch (Exception e) {
+ TextMarkerPlugin.error(e);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+ public void calculateEvaluatData(TestCasData data, CAS resultCas) {
+ data.setEvaluationStatus(true);
+ TypeSystem ts = resultCas.getTypeSystem();
+ Type falsePositiveType = ts.getType(ICasEvaluator.FALSE_POSITIVE);
+ Type falseNegativeType = ts.getType(ICasEvaluator.FALSE_NEGATIVE);
+ Type truePositiveType = ts.getType(ICasEvaluator.TRUE_POSITIVE);
+
+ int falsePositiveCount = resultCas.getAnnotationIndex(falsePositiveType).size();
+ int falseNegativeCount = resultCas.getAnnotationIndex(falseNegativeType).size();
+ int truePositiveCount = resultCas.getAnnotationIndex(truePositiveType).size();
+
+ data.setTruePositiveCount(truePositiveCount);
+ data.setFalsePositiveCount(falsePositiveCount);
+ data.setFalseNegativeCount(falseNegativeCount);
+
+ HashMap map = new HashMap();
+
+ AnnotationIndex<AnnotationFS> index = resultCas.getAnnotationIndex(truePositiveType);
+
+ FSIterator iter = index.iterator();
+
+ while (iter.isValid()) {
+ EvalAnnotation a = (EvalAnnotation) iter.next();
+ Annotation original = a.getOriginal();
+ Type originalType = original.getType();
+
+ if (map.containsKey(originalType.getName())) {
+ TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
+ int oldCount = element.getTruePositives();
+ element.setTruePositives(oldCount + 1);
+ } else {
+ TypeEvalData newData = new TypeEvalData(originalType.getName(), 1, 0, 0);
+ map.put(originalType.getName(), newData);
+ }
+ }
+
+ index = resultCas.getAnnotationIndex(falsePositiveType);
+ iter = index.iterator();
+
+ while (iter.isValid()) {
+ EvalAnnotation a = (EvalAnnotation) iter.next();
+ Annotation original = a.getOriginal();
+ Type originalType = original.getType();
+
+ if (map.containsKey(originalType.getName())) {
+ TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
+ int oldCount = element.getFalsePositives();
+ element.setFalsePositives(oldCount + 1);
+ } else {
+ TypeEvalData newData = new TypeEvalData(originalType.getName(), 0, 1, 0);
+ map.put(originalType.getName(), newData);
+ }
+ }
+
+ index = resultCas.getAnnotationIndex(falseNegativeType);
+ iter = index.iterator();
+
+ while (iter.isValid()) {
+ EvalAnnotation a = (EvalAnnotation) iter.next();
+ Annotation original = a.getOriginal();
+ Type originalType = original.getType();
+
+ if (map.containsKey(originalType.getName())) {
+ TypeEvalData element = (TypeEvalData) map.get(originalType.getName());
+ int oldCount = element.getFalseNegatives();
+ element.setFalseNegatives(oldCount + 1);
+ } else {
+ TypeEvalData newData = new TypeEvalData(originalType.getName(), 0, 0, 1);
+ map.put(originalType.getName(), newData);
+ }
+ }
+
+ data.setTypeEvalData(map);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RerunActionHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,94 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import org.apache.uima.tm.textmarker.testing.ui.views.TestViewPage;
+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.core.resources.IResource;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.part.FileEditorInput;
+
+
+public class RunTestHandler implements IHandler {
+
+ private IResource resource;
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ // TODO create a new view for every resource file
+ TestViewPage view = null;
+ try {
+ FileEditorInput input = (FileEditorInput) HandlerUtil.getActiveEditor(event).getEditorInput();
+ IResource r = input.getFile();
+ view = (TestViewPage) HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().showView(
+ "org.apache.uima.tm.textmarker.testing.annotationTest");
+ view.setResource(r);
+ } catch (PartInitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ /*
+ * TODO Create a separate view for every tm project that is selected if
+ * (HandlerUtil.getActiveMenuSelection(event) instanceof IStructuredSelection) { // if
+ * (HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection) {
+ * StructuredSelection selection =
+ * (StructuredSelection)HandlerUtil.getActiveMenuSelection(event);; // StructuredSelection
+ * selection = (StructuredSelection)HandlerUtil.getCurrentSelection(event); Iterator iter =
+ * selection.iterator(); ArrayList<IResource> selectionList = new ArrayList<IResource>(); while
+ * (iter.hasNext()) {
+ *
+ * Object obj = iter.next(); if (obj instanceof IResource) { selectionList.add((IResource)obj);
+ * } view.setResource(selectionList.get(0)); if (selectionList.get(0) == null) {
+ * System.out.println("keks"); } //view.setTitle(selectionList.get(0).getName()); }
+ *
+ * ArrayList<String> testList = new ArrayList<String>();
+ *
+ * if (view.getViewer() != null) { List list = view.getViewer().getList(); for (int i = 0; i <
+ * list.getItemCount(); i++) { String s = view.getViewer().getList().getItem(i).toString();
+ * testList.add(s); } }
+ *
+ * IResource resource = selectionList.get(0); for (String s : testList) {
+ *
+ * }
+ *
+ * }
+ */
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/RunTestHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java?rev=1152831&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java Mon Aug 1 15:35:40 2011
@@ -0,0 +1,48 @@
+package org.apache.uima.tm.textmarker.testing.ui.handlers;
+
+import org.apache.uima.tm.textmarker.testing.preferences.TestingPreferencePage;
+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.dialogs.Dialog;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+public class SelectEvaluatorHandler implements IHandler {
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ 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.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.testing/src/main/java/org/apache/uima/tm/textmarker/testing/ui/handlers/SelectEvaluatorHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain