You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/06/03 18:06:48 UTC
svn commit: r1489049 [3/3] - in /uima/sandbox/ruta/trunk: ruta-core/
ruta-ep-addons/ ruta-ep-addons/icons/
ruta-ep-addons/src/main/java/org/apache/uima/ruta/addons/
ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/
ruta-ep-addons/src/main/java/org...
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewComposite.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewComposite.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewComposite.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewComposite.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,165 @@
+/*
+ * 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.ruta.cde.ui;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import org.apache.uima.ruta.cde.utils.CDEComparatorFactory;
+import org.apache.uima.ruta.cde.utils.DocumentData;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+
+
+
+public class ResultViewComposite extends Composite implements ISelectionListener {
+
+ private Clipboard clipboard;
+
+ private TableViewer tableViewer;
+
+ private Table table;
+
+ private TableColumn tc1;
+
+ private TableColumn tc2;
+
+ private CDEComparatorFactory comparatorFactory;
+
+ public ResultViewComposite(Composite parent, int style) {
+ super(parent, style);
+ initGui();
+ comparatorFactory = new CDEComparatorFactory();
+ clipboard = new Clipboard(parent.getDisplay());
+ }
+
+ public void initGui() {
+ this.setLayout(new FormLayout());
+ tableViewer = new TableViewer (this, SWT.MULTI | SWT.BORDER
+ | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ tableViewer.setContentProvider(new ResultViewContentProvder());
+ tableViewer.setLabelProvider(new ResultViewLabelProvider());
+ table = tableViewer.getTable();
+
+ FormData tableFormData = new FormData();
+ tableFormData.top = new FormAttachment(0, 5);
+ tableFormData.left = new FormAttachment(0, 5);
+ tableFormData.bottom = new FormAttachment(100, -5);
+ tableFormData.right = new FormAttachment(100, -5);
+ table.setLayoutData(tableFormData);
+
+ table.addKeyListener(new KeyListener() {
+ public void keyPressed(KeyEvent e) {
+ if(((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'c')) {
+ String output = "";
+ TableItem[] items = table.getSelection();
+ for(TableItem item : items) {
+ String[] data = (String[])item.getData();
+ output = output + data[0] + ", " + data[1] + ", \n";
+ }
+ clipboard.setContents(new Object[] { output },
+ new Transfer[] { TextTransfer.getInstance() });
+ }
+ }
+ public void keyReleased(KeyEvent arg0) {
+ // TODO Auto-generated method stub
+ }
+ });
+
+
+
+ tc1 = new TableColumn(table, SWT.LEFT);
+ tc1.setText("Constraint ");
+ tc1.setWidth(160);
+ tc1.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected (SelectionEvent event) {
+ ArrayList<String[]> data = (ArrayList<String[]>) tableViewer.getInput();
+ Comparator comparator = comparatorFactory.getComparator(tc1);
+ Collections.sort(data, comparator);
+ tableViewer.refresh();
+ }
+ });
+
+ tc2 = new TableColumn(table, SWT.LEFT);
+ tc2.setText("Result");
+ tc2.setWidth(120);
+ tc2.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected (SelectionEvent event) {
+ ArrayList<String[]> data = (ArrayList<String[]>) tableViewer.getInput();
+ Comparator comparator = comparatorFactory.getComparator(tc2);
+ Collections.sort(data, comparator);
+ tableViewer.refresh();
+ }
+ });
+
+ tableViewer.refresh();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+
+
+ }
+
+ public void updateInput(Object input) {
+ tableViewer.setInput(input);
+ tableViewer.refresh();
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection strucSel = (IStructuredSelection) selection;
+ Iterator<?> iter = strucSel.iterator();
+ if (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof DocumentData) {
+ DocumentData data = (DocumentData) o;
+ ArrayList<String[]> results = data.getResults();
+ tableViewer.setInput(results);
+ tableViewer.refresh();
+ }
+ }
+ }
+ }
+
+ public TableViewer getViewer() {
+ return tableViewer;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewContentProvder.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewContentProvder.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewContentProvder.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewContentProvder.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.ruta.cde.ui;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class ResultViewContentProvder implements IStructuredContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ }
+
+ public Object[] getElements(Object input) {
+ if (input instanceof ArrayList) {
+ return ((ArrayList<?>) input).toArray();
+ }
+ return null;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewLabelProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewLabelProvider.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewLabelProvider.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/ui/ResultViewLabelProvider.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.ruta.cde.ui;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class ResultViewLabelProvider implements ITableLabelProvider {
+
+ public void addListener(ILabelProviderListener arg0) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object arg0, String arg1) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener arg0) {
+
+ }
+
+ public Image getColumnImage(Object arg0, int arg1) {
+ return null;
+ }
+
+ public String getColumnText(Object input, int column) {
+ if(input instanceof String[]) {
+ String[] results = (String[])input;
+ switch(column) {
+ case 0 :
+ return results[0];
+ case 1 :
+ return results[1];
+ }
+ }
+ return null;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/CDEComparatorFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/CDEComparatorFactory.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/CDEComparatorFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/CDEComparatorFactory.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,164 @@
+/*
+ * 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.ruta.cde.utils;
+
+import java.text.Collator;
+import java.util.Comparator;
+import java.util.Locale;
+
+import org.eclipse.swt.widgets.TableColumn;
+
+public class CDEComparatorFactory {
+
+ private int updown;
+
+ public CDEComparatorFactory () {
+ updown = 1;
+ }
+
+ private Comparator<DocumentData> stringDocumentComparator = new Comparator <DocumentData>() {
+
+ public int compare(DocumentData object1, DocumentData object2) {
+ Collator collator = Collator.getInstance();
+
+ String docName1 = object1.getDocument().getName();
+ String docName2 = object2.getDocument().getName();
+
+ int result = collator.compare(docName1, docName2) * updown;
+ return result;
+ }
+ };
+
+ private Comparator<DocumentData> resultComparator = new Comparator <DocumentData> () {
+
+ public int compare(DocumentData object1, DocumentData object2) {
+
+ double augment1 = object1.getAugmentedResult();
+ double augment2 = object2.getAugmentedResult();
+
+ if (augment1 <= augment2) {
+ return 1 * updown;
+ }
+ else {
+ return -1 *updown;
+ }
+
+ }
+ };
+
+
+private Comparator<DocumentData> f1ScoreComparator = new Comparator <DocumentData> () {
+
+ public int compare(DocumentData object1, DocumentData object2) {
+
+ double augment1 = object1.getFMeasure();
+ double augment2 = object2.getFMeasure();
+
+ if (augment1 <= augment2) {
+ return 1 * updown;
+ }
+ else {
+ return -1 *updown;
+ }
+
+ }
+ };
+
+
+
+
+ private Comparator<ConstraintData> stringConstraintComparator = new Comparator <ConstraintData>() {
+
+ public int compare(ConstraintData object1, ConstraintData object2) {
+ Collator collator = Collator.getInstance();
+
+ String constraintName1 = object1.getDescription();
+ String constraintName2 = object2.getDescription();
+
+ int result = collator.compare(constraintName1, constraintName2) * updown;
+ return result;
+ }
+
+ };
+
+ private Comparator<ConstraintData> intConstraintComparator = new Comparator <ConstraintData> () {
+
+ public int compare(ConstraintData object1, ConstraintData object2) {;
+
+ int weight1 = object1.getWeight();
+ int weight2 = object2.getWeight();
+
+ return (weight1-weight2) * updown;
+ }
+
+ };
+
+ private Comparator <String[]> resultNameComparator = new Comparator<String[]> () {
+ public int compare(String[] object1, String[] object2) {
+
+ Collator collator = Collator.getInstance(Locale.getDefault());
+ int result = collator.compare(object1[0], object2[0]) * updown;
+ return result;
+ }
+ };
+
+ private Comparator <String[]> resultValueComparator = new Comparator<String[]> () {
+ public int compare(String[] object1, String[] object2) {
+ double result1 = Double.valueOf(object1[1]);
+ double result2 = Double.valueOf(object2[1]);
+ if (result1 >= result2)
+ return 1 * updown;
+ else {
+ return -1 *updown;
+ }
+ }
+ };
+
+ public Comparator getComparator (TableColumn tc) {
+ this.updown = updown * (-1);
+ String columnName = tc.getText();
+
+ if(columnName.equals("CDE")) {
+ return resultComparator;
+ }
+ if(columnName.equals( "F1")) {
+ return f1ScoreComparator;
+ }
+ else if (columnName.equals("Document")) {
+ return stringDocumentComparator;
+ }
+ else if (columnName.equals("Constraint")) {
+ return stringConstraintComparator;
+ }
+ else if (columnName.equals("Weight")) {
+ return intConstraintComparator;
+ }
+ else if (columnName.equals("Constraint ")) {
+ return resultNameComparator;
+ }
+ else if (columnName.equals("Result")) {
+ return resultValueComparator;
+ }
+ return Collator.getInstance();
+ }
+
+
+}
+
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintData.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintData.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintData.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintData.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.ruta.cde.utils;
+
+import org.apache.uima.ruta.cde.IRutaConstraint;
+
+public class ConstraintData {
+
+ private IRutaConstraint constraint;
+
+ private int weight;
+
+ public ConstraintData (IRutaConstraint constraint) {
+ this.constraint = constraint;
+ weight = 1;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public IRutaConstraint getConstraint () {
+ return constraint;
+ }
+
+ public void setConstraint (IRutaConstraint constraint) {
+ this.constraint= constraint;
+ }
+
+ public String getDescription () {
+ return constraint.getDescription();
+ }
+
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLExporter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLExporter.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLExporter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLExporter.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,131 @@
+/*
+ * 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.ruta.cde.utils;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+
+@SuppressWarnings("restriction")
+public class ConstraintXMLExporter {
+
+ IPath outputPath;
+
+ ArrayList<ConstraintData> constraints;
+
+ public ConstraintXMLExporter(ArrayList<ConstraintData> constraints) {
+ this.outputPath = outputPath;
+ this.constraints = constraints;
+ }
+
+ public void saveConstraints(IPath outputPath) throws Exception {
+
+// IWorkspace workspace = ResourcesPlugin.getWorkspace();
+// IWorkspaceRoot root = workspace.getRoot();
+// String rootPath = root.getRawLocation().toPortableString();
+
+// if(outputPath.getFileExtension() == null) {
+// outputPath = outputPath.addFileExtension("xml");
+//
+// System.out.println("adsf :" + outputPath.toOSString());
+// } else if
+//
+// (!outputPath.getFileExtension().equals("xml")) {
+// outputPath.removeFileExtension();
+// outputPath = outputPath.addFileExtension("xml");
+// }
+
+// String absolutPath = rootPath + System.getProperty("file.separator") + outputPath.toOSString();
+// String absolutPath = outputPath.toOSString();
+// File file = new File(absolutPath);
+//
+//
+// file.createNewFile();
+//
+//
+//
+// // outputPath = Path.fromOSString("C:/test/test1.xml");
+// // Create a XMLOutputFactory
+// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+// // Create XMLEventWriter
+// XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(absolutPath));
+// // Create a EventFactory
+// XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+// XMLEvent end = eventFactory.createDTD("\n");
+// // Create and write Start Tag
+// StartDocument startDocument = eventFactory.createStartDocument();
+// eventWriter.add(startDocument);
+// StartElement constraintListStartElement = eventFactory.createStartElement("", "",
+// "constraintList");
+// eventWriter.add(constraintListStartElement);
+// eventWriter.add(end);
+//
+// for (ConstraintData data : constraints) {
+// String constraintType = "";
+// if (data.getConstraint() instanceof IAugurTMConstraint) {
+// IAugurTMConstraint constraint = (IAugurTMConstraint) data.getConstraint();
+//
+// if (constraint instanceof SimpleRutaConstraint) {
+// constraintType = "SimpleRutaConstraint";
+//
+// }
+// if (constraint instanceof ListRutaConstraint) {
+// constraintType = "ListRutaConstraint";
+// }
+//
+// StartElement constraintStartElement = eventFactory.createStartElement("", "",
+// constraintType);
+// eventWriter.add(constraintStartElement);
+// eventWriter.add(end);
+//
+// createNode(eventWriter, "rule", constraint.getRule());
+// }
+// createNode(eventWriter, "description", data.getDescription());
+// createNode(eventWriter, "weight", String.valueOf(data.getWeight()));
+// eventWriter.add(eventFactory.createEndElement("", "", constraintType));
+// eventWriter.add(end);
+// }
+// eventWriter.add(eventFactory.createEndElement("", "", "constraintList"));
+// eventWriter.add(end);
+// eventWriter.add(eventFactory.createEndDocument());
+// eventWriter.close();
+ }
+
+// private void createNode(XMLEventWriter eventWriter, String name, String value)
+// throws XMLStreamException {
+//
+// XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+// XMLEvent end = eventFactory.createDTD("\n");
+// XMLEvent tab = eventFactory.createDTD("\t");
+// // Create Start node
+// StartElement sElement = eventFactory.createStartElement("", "", name);
+// eventWriter.add(tab);
+// eventWriter.add(sElement);
+// // Create Content
+// Characters characters = eventFactory.createCharacters(value);
+// eventWriter.add(characters);
+// // Create End node
+// EndElement eElement = eventFactory.createEndElement("", "", name);
+// eventWriter.add(eElement);
+// eventWriter.add(end);
+//
+// }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLImporter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLImporter.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLImporter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/ConstraintXMLImporter.java Mon Jun 3 16:06:47 2013
@@ -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.ruta.cde.utils;
+
+import java.util.ArrayList;
+
+import org.apache.uima.ruta.cde.RutaConstraintFactory;
+import org.eclipse.core.runtime.IPath;
+
+@SuppressWarnings({ "unchecked", "null", "restriction" })
+public class ConstraintXMLImporter {
+
+ ArrayList<ConstraintData> constraints;
+
+ IPath inputPath;
+
+ RutaConstraintFactory factory;
+
+ // IAugurConstraint constraint;
+
+ public ConstraintXMLImporter() {
+ super();
+ this.factory = new RutaConstraintFactory();
+ }
+
+ public ArrayList<ConstraintData> readXML(IPath inputPath) {
+// System.out.println(inputPath.toOSString());
+ this.inputPath = inputPath;
+ constraints = new ArrayList<ConstraintData>();
+
+// try {
+// // First create a new XMLInputFactory
+// XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+// // Setup a new eventReader
+// InputStream in = new FileInputStream(inputPath.toOSString());
+// XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
+// // Read the XML document
+// IAugurTMConstraint constraint = null;
+// ConstraintData data = null;
+// while (eventReader.hasNext()) {
+// XMLEvent event = eventReader.nextEvent();
+//
+// if (event.isStartElement()) {
+//// System.out.println(event.asStartElement().getName().getLocalPart());
+// if (event.asStartElement().getName().getLocalPart().equals("SimpleRutaConstraint")) {
+// StartElement startElement = event.asStartElement();
+// constraint = factory.createConstraint(startElement.getName().getLocalPart());
+// data = new ConstraintData(constraint);
+// constraints.add(data);
+// }
+// }
+//
+// if (event.isStartElement()) {
+// if (event.asStartElement().getName().getLocalPart().equals("ListRutaConstraint")) {
+// StartElement startElement = event.asStartElement();
+// constraint = factory.createConstraint(startElement.getName().getLocalPart());
+// data = new ConstraintData(constraint);
+// constraints.add(data);
+// }
+// }
+//
+// if(event.isStartElement()) {
+// if(event.asStartElement().getName().getLocalPart().equals("rule")) {
+// event = eventReader.nextEvent();
+// constraint.setRule(event.asCharacters().getData());
+// continue;
+// }
+// }
+//
+// if(event.isStartElement()) {
+// if(event.asStartElement().getName().getLocalPart().equals("description")) {
+// event = eventReader.nextEvent();
+// constraint.setDescription(event.asCharacters().getData());
+// continue;
+// }
+// }
+//
+// if(event.isStartElement()) {
+// if(event.asStartElement().getName().getLocalPart().equals("weight")) {
+// event = eventReader.nextEvent();
+// data.setWeight(Integer.valueOf(event.asCharacters().getData()));
+// continue;
+// }
+// }
+// }
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+ return constraints;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/DocumentData.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/DocumentData.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/DocumentData.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/DocumentData.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,74 @@
+/*
+ * 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.ruta.cde.utils;
+
+import java.io.File;
+import java.util.ArrayList;
+
+public class DocumentData {
+
+ private File document;
+
+ private double augmentedResult;
+
+ private double fMeasure;
+
+ private ArrayList<String[]> results;
+
+ public DocumentData(File document) {
+ this.document = document;
+ this.augmentedResult = 0;
+ this.fMeasure = 0;
+ this.results = new ArrayList<String[]>();
+ }
+
+ public void setDocument(File document) {
+ this.document = document;
+ }
+
+ public void setAugmentedResult (double result) {
+ this.augmentedResult = result;
+ }
+
+ public File getDocument() {
+ return this.document;
+ }
+
+ public double getAugmentedResult () {
+ return this.augmentedResult;
+ }
+
+ public ArrayList<String[]> getResults() {
+ return results;
+ }
+
+ public void setResults(ArrayList<String[]> results) {
+ this.results = results;
+ }
+
+ public void setFMeasure(double fMeasure) {
+ this.fMeasure = fMeasure;
+ }
+
+ public double getFMeasure() {
+ return this.fMeasure;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/EvaluationMeasures.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/EvaluationMeasures.java?rev=1489049&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/EvaluationMeasures.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/cde/utils/EvaluationMeasures.java Mon Jun 3 16:06:47 2013
@@ -0,0 +1,77 @@
+/*
+ * 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.ruta.cde.utils;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Locale;
+
+import org.apache.commons.math3.linear.ArrayRealVector;
+import org.apache.commons.math3.stat.correlation.SpearmansCorrelation;
+import org.apache.commons.math3.stat.inference.TestUtils;
+
+public class EvaluationMeasures {
+
+ public static String getMeasureReport(ArrayList<Double[]> results) {
+ double[] x = new double[results.size()];
+ double[] y = new double[results.size()];
+ int index = 0;
+ for (Double[] resultPair : results) {
+ x[index] = resultPair[0];
+ y[index] = resultPair[1];
+ index++;
+ }
+ double spearmans = new SpearmansCorrelation().correlation(x, y);
+ double pairedT = TestUtils.pairedT(x, y);
+ double cosine = cosine(x, y);
+ spearmans = round(spearmans);
+ pairedT = round(pairedT);
+ cosine = round(cosine);
+
+ String report = "cosine=" + cosine + " spearmans=" + spearmans + " pairedT=" + pairedT;
+ return report;
+ }
+
+ public static double round(double d) {
+ DecimalFormat instance = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
+ instance.applyPattern("#.####");
+ String format = instance.format(d);
+ return Double.valueOf(format);
+ }
+
+ public static double cosine(double[] a1, double[] a2) {
+ ArrayRealVector v1 = new ArrayRealVector(a1);
+ ArrayRealVector v2 = new ArrayRealVector(a2);
+ return v1.dotProduct(v2) / (v1.getNorm() * v2.getNorm());
+ }
+
+ public static double cosine(ArrayList<Double[]> results) {
+ double[] x = new double[results.size()];
+ double[] y = new double[results.size()];
+ int index = 0;
+ for (Double[] resultPair : results) {
+ x[index] = resultPair[0];
+ y[index] = resultPair[1];
+ index++;
+ }
+ return cosine(x, y);
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml?rev=1489049&r1=1489048&r2=1489049&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-engine/pom.xml Mon Jun 3 16:06:47 2013
@@ -152,7 +152,7 @@ licensed under the Common Public License
org.apache.commons.lang3.*,
org.apache.commons.io.*,
org.apache.uima.fit.*,
- org.reflections.*
+ org.apache.commons.math3.*
</_exportcontents>
<Require-Bundle>
org.apache.uima.runtime