Commit a77152e4 authored by Markus Krug's avatar Markus Krug

annobrowser is now able to execute ruta

fixed a minor bug in the dependency analyzer which was off by an offset
parent f8e4c599
Pipeline #7481 passed with stages
in 17 minutes and 55 seconds
package de.uniwue.mk.kall.athen.annotationbrowserview.ui;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.util.InvalidXMLException;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.layout.GridLayout;
......@@ -124,6 +134,7 @@ public class AnnotationBrowserView extends AEditorSubordinateViewPart {
@Override
public boolean initTypes() {
// hide all types
editor.allStylesInvisible();
// try to set default editor stylings to given annotations
......@@ -150,6 +161,8 @@ public class AnnotationBrowserView extends AEditorSubordinateViewPart {
return false;
}
private void setDefaultHistoricalDrawingStrategies() {
Type historicalSemnaticType = editor.getCas().getTypeSystem()
......
package de.uniwue.mk.kall.athen.annotationbrowserwidget;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.uima.cas.FSIndex;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.impl.AnnotationImpl;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.util.InvalidXMLException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
......@@ -15,17 +20,18 @@ import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.Display;
import org.eclipse.swt.widgets.Label;
......@@ -48,9 +54,12 @@ public class AnnotationBrowserWidget extends Composite {
private Label labelSearchAnnotations;
private Label labelSearchFeatureValue;
private Button buttonApplyRUTA;
private Text textSearchTypes;
private Text textSearchAnnotations;
private Text textSearchFeatureValue;
private Text textApplyRUTA;
private AnnotationTextFilter textFilter;
private TreeViewerAlphabeticalSorter alphabeticalSorter;
......@@ -124,6 +133,24 @@ public class AnnotationBrowserWidget extends Composite {
});
buttonApplyRUTA = new Button(this, SWT.NONE);
buttonApplyRUTA.setText("Apply RUTA");
textApplyRUTA = new Text(this, SWT.NONE | SWT.BORDER);
textApplyRUTA.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
textApplyRUTA.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
buttonApplyRUTA.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String rutaRule = textApplyRUTA.getText();
if (rutaRule != null && rutaRule.trim().length() > 0) {
applyRuta(rutaRule);
}
}
});
createTreeViewer();
}
......@@ -501,4 +528,39 @@ public class AnnotationBrowserWidget extends Composite {
editor.removeAnnotation(toDelete.get(0));
}
}
private void applyRuta(String rule) {
// delete all eval annotation beforehand
List<AnnotationFS> evalAnnos = new ArrayList<>();
for (AnnotationFS a : editor.getCas()
.getAnnotationIndex(editor.getCas().getTypeSystem().getType("de.uniwue.medIE.Eval"))) {
evalAnnos.add(a);
}
for (AnnotationFS a : evalAnnos) {
editor.getCas().removeFsFromIndexes(a);
}
String[] elements = rule.split(" ");
try {
Ruta.apply(editor.getCas(), rule + "{->MARK(Eval,1," + elements.length + ")};");
} catch (AnalysisEngineProcessException | InvalidXMLException | ResourceInitializationException
| ResourceConfigurationException | IOException | URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// delete all ruta stuff
List<AnnotationFS> annos = new ArrayList<>();
for (AnnotationFS a : editor.getCas().getAnnotationIndex()) {
if (a.getType().getName().contains(".ruta.")) {
annos.add(a);
}
}
for (AnnotationFS a : annos) {
editor.getCas().removeFsFromIndexes(a);
}
viewer.setInput(editor);
}
}
......@@ -22,7 +22,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import de.uniwue.mk.athen.textwidget.struct.AnnoStyle;
import de.uniwue.mk.athen.textwidget.struct.EditorLine;
import de.uniwue.mk.kall.athen.widget.editor.EEditorEvent;
import de.uniwue.mk.kall.editorPainting.paintingstrategies.specialized.DependencyDrawingStrategy;
import de.uniwue.mkrug.kall.typesystemutil.Util_impl;
......@@ -106,7 +105,6 @@ public class DependencyParseAnalyzer extends AEditorSubordinateTextWidgetAnalyze
}
}
}
@Override
......@@ -191,8 +189,9 @@ public class DependencyParseAnalyzer extends AEditorSubordinateTextWidgetAnalyze
this.analyzerWidget.changeStyle(this.typeDepParseNewCAS, style2);
this.analyzerWidget.getWidget()
.setTopMargin(super.overlay.getClientArea().height
- analyzerWidget.getWidget().getEditorLines().get(0).getLineHeight()*2-10-DependencyDrawingStrategy.ANCHOR_HEIGHT);
.setTopMargin(super.overlay.getClientArea().height
- analyzerWidget.getWidget().getEditorLines().get(0).getLineHeight() * 2 - 10
- DependencyDrawingStrategy.ANCHOR_HEIGHT);
this.analyzerWidget.changeVisibility(this.typeDepParseNewCAS, true);
this.analyzerWidget.changeLayer(this.typeDepParseNewCAS, 0);
......@@ -229,7 +228,7 @@ public class DependencyParseAnalyzer extends AEditorSubordinateTextWidgetAnalyze
private void onEditorMouseMoved(Object changedObject) {
Point p = (Point) changedObject;
p.x+=analyzerWidget.getWidget().getHorizontalBar().getSelection();
analyzerWidget.getWidget().setCursor(cursorStandard);
// now check if also in x range
......@@ -240,8 +239,8 @@ public class DependencyParseAnalyzer extends AEditorSubordinateTextWidgetAnalyze
for (AnnotationFS dep : analyzerWidget.getCas().getAnnotationIndex(typeDepParseNewCAS)) {
Rectangle rectangle = analyzerWidget.getWidget().getTextBounds(dep.getBegin(), dep.getEnd() - 1);
Rectangle anchorArea = drawingStrategy.calculateAnchorArea(rectangle);
if (anchorArea.contains(p)) {
boolean depChanged = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment