Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • kallimachos/Athen
1 result
Show changes
Commits on Source (15)
Showing
with 704 additions and 495 deletions
......@@ -79,6 +79,8 @@ Extending ATHEN
ATHEN is written as a eclipse 4 RCP Application, which means it is based on plugins that can be loaded dynamically at runtime. Currently ATHEN supports the loading of
a new view for the annotation perspective while ATHEN is running. If you need to know how this works, please contact me.
If you are interested in extending the functionality of ATHEN you should consider reading the [developer handbook](https://gitlab2.informatik.uni-wuerzburg.de/kallimachos/Athen/wikis/developer-handbook) of ATHEN
Troubleshooting and contact
......
......@@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import de.uniwue.dw.ie.algorithm.IMedicalInformationExtractionAlgorithm;
import de.uniwue.dw.ie.algorithm.SimpleIEAlgorithm;
......@@ -51,535 +52,554 @@ import de.uniwue.mkrug.kall.typesystemutil.Util_impl;
public class MedIEOWLView extends AEditorSubordinateViewPart {
@Inject
static EPartService partService;
@Inject
static EPartService partService;
public static final String ONTOLOGY_BASE_IRI = "http://www.semanticweb.org/uniwue/athen/medOntologies/";
public static final String ONTOLOGY_BASE_IRI = "http://www.semanticweb.org/uniwue/athen/medOntologies/";
// E4 DI OBJECTS used to communicate with the editor
@Inject
static IEventBroker broker;
// E4 DI OBJECTS used to communicate with the editor
@Inject
static IEventBroker broker;
private String segmentTypeS = "de.uniwue.dw.segmentation.Segment";
private String segmentTypeS = "de.uniwue.dw.segmentation.Segment";
private String segmentTypeStop = "de.uniwue.dw.segmentation.SegmentStop";
private String segmentTypeStop = "de.uniwue.dw.segmentation.SegmentStop";
// algorithm
public static IMedicalInformationExtractionAlgorithm ieAlgorithm = new SimpleIEAlgorithm();
// algorithm
public static IMedicalInformationExtractionAlgorithm ieAlgorithm = new SimpleIEAlgorithm();
// UI
private Button buttonCreateTerminology;
// UI
private Button buttonCreateTerminology;
private Button buttonLoadTerminology;
private Button buttonLoadTerminology;
private Button buttonSaveTerminology;
private Button buttonSaveTerminology;
private Button buttonApplyTerminology;
private Button buttonApplyTerminology;
private Button buttonUseAutosave;
private Button buttonUseAutosave;
private Button buttonCreateRelation;
private Button buttonCreateRelation;
// the ontology editor
private IEOntologyTreeComposite tree;
// the ontology editor
private IEOntologyTreeComposite tree;
// helper
private String openedTerminologyPath;
// helper
private String openedTerminologyPath;
private Util_impl util;
private Util_impl util;
private Timer autoSaveTimer;
private Timer autoSaveTimer;
private TimerTask autoSaveTask;
private TimerTask autoSaveTask;
private Shell evaluationShell;
private Shell evaluationShell;
// model
private IEOntology ontology;
// model
private IEOntology ontology;
@Inject
public MedIEOWLView() {
super();
}
@Inject
public MedIEOWLView() {
super();
}
@PostConstruct
public void postConstruct(Composite parent, MPart part) {
// layout this should stay as it is
super.overlay = parent;
@PostConstruct
public void postConstruct(Composite parent, MPart part) {
// layout this should stay as it is
super.overlay = parent;
// init the part, so that this view knows its position globally
// (required to see if it has focus)
super.partService = partService;
super.setBroker(broker);
super.part = part;
}
// init the part, so that this view knows its position globally
// (required to see if it has focus)
super.partService = partService;
super.setBroker(broker);
super.part = part;
}
@PreDestroy
public void preDestroy() {
@PreDestroy
public void preDestroy() {
}
}
@Focus
public void onFocus() {
super.onFocus();
@Focus
public void onFocus() {
super.onFocus();
if (ontology != null && !tree.isDisposed()) {
tree.setOntology(ontology);
if (ontology != null && !tree.isDisposed()) {
tree.setOntology(ontology);
// also save it once !! TODO
renewPage();
}
}
// also save it once !! TODO
renewPage();
}
}
@Persist
public void save() {
@Persist
public void save() {
}
}
@Override
public void initModel() {
// TODO Auto-generated method stub
@Override
public void initModel() {
// TODO Auto-generated method stub
}
}
@Override
public boolean initTypes() {
// set the util, update for every document change
Type segmentType = super.editor.getCas().getTypeSystem().getType(segmentTypeS);
this.util = new Util_impl(super.editor.getCas());
// set the relevant types to visible
editor.changeVisibility(util.getIEEntityGoldType(), true);
editor.changeVisibility(util.getIERelationGoldType(), true);
// make segments visible with the bracket style
editor.changeVisibility(segmentType, true);
//editor.setActiveMode(segmentType);
@Override
public boolean initTypes() {
// set the util, update for every document change
Type segmentType = super.editor.getCas().getTypeSystem().getType(segmentTypeS);
this.util = new Util_impl(super.editor.getCas());
// set the relevant types to visible
editor.changeVisibility(util.getIEEntityGoldType(), true);
editor.changeVisibility(util.getIERelationGoldType(), true);
// make segments visible with the bracket style
editor.changeVisibility(segmentType, true);
// editor.setActiveMode(segmentType);
editor.changeVisibility(util.getIEEntitySystemType(), true);
editor.changeVisibility(util.getIERelationSystemType(), true);
editor.changeVisibility(util.getIEEntitySystemType(), true);
editor.changeVisibility(util.getIERelationSystemType(), true);
// TODO do we need any layer?
editor.changeLayer(util.getIERelationGoldType(), 1);
editor.changeLayer(util.getIERelationSystemType(), 2);
// TODO do we need any layer?
editor.changeLayer(util.getIERelationGoldType(), 1);
editor.changeLayer(util.getIERelationSystemType(), 2);
StyleRange srSeg = new StyleRange();
srSeg.background = Display.getCurrent().getSystemColor(4);
AnnoStyle bracketSegmentStyle = new AnnoStyle(new BracketDrawingStrategy(srSeg), srSeg);
editor.changeStyle(segmentType, bracketSegmentStyle);
StyleRange srSeg = new StyleRange();
srSeg.background = Display.getCurrent().getSystemColor(4);
AnnoStyle bracketSegmentStyle = new AnnoStyle(new BracketDrawingStrategy(srSeg), srSeg);
editor.changeStyle(segmentType, bracketSegmentStyle);
// create the style
StyleRange rangeTempAtt = new StyleRange();
rangeTempAtt.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleTempAtt = new AnnoStyle(new MedIEViewEntityDrawingStrategy(rangeTempAtt), rangeTempAtt);
// create the style
StyleRange rangeTempAtt = new StyleRange();
rangeTempAtt.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleTempAtt = new AnnoStyle(new MedIEViewEntityDrawingStrategy(rangeTempAtt),
rangeTempAtt);
editor.changeStyle(util.getIEEntityGoldType(), styleTempAtt);
editor.changeStyle(util.getIEEntityGoldType(), styleTempAtt);
// style for IERelation
StyleRange rangeIERel = new StyleRange();
rangeIERel.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleIERel = new AnnoStyle(
new MedIEViewRelationDrawingStrategy(rangeIERel, util.getIERelationGoldEntityFromFeature(),
util.getIERelationGoldEntityToFeature(), util.getIERelationGoldLabelFeature()),
rangeIERel);
// style for IERelation
StyleRange rangeIERel = new StyleRange();
rangeIERel.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleIERel = new AnnoStyle(
new MedIEViewRelationDrawingStrategy(rangeIERel,
util.getIERelationGoldEntityFromFeature(),
util.getIERelationGoldEntityToFeature(), util.getIERelationGoldLabelFeature()),
rangeIERel);
editor.changeStyle(util.getIERelationGoldType(), styleIERel);
editor.changeStyle(util.getIERelationGoldType(), styleIERel);
// system styles
StyleRange rangeTempIESystem = new StyleRange();
rangeTempIESystem.background = new Color(overlay.getDisplay(), 66, 217, 44);
AnnoStyle styleTempIESystem = new AnnoStyle(new MedIEViewEntityDrawingStrategy(rangeTempIESystem), rangeTempIESystem);
editor.changeStyle(util.getIEEntitySystemType(), styleTempIESystem);
// system styles
StyleRange rangeTempIESystem = new StyleRange();
rangeTempIESystem.background = new Color(overlay.getDisplay(), 66, 217, 44);
AnnoStyle styleTempIESystem = new AnnoStyle(
new MedIEViewEntityDrawingStrategy(rangeTempIESystem), rangeTempIESystem);
editor.changeStyle(util.getIEEntitySystemType(), styleTempIESystem);
// style for IERelation
StyleRange rangeIERelSystem = new StyleRange();
Feature displayLabel = util.getIERelationSystemType().getFeatureByBaseName("DisplayLabel");
rangeIERelSystem.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleIERelSystem = new AnnoStyle(new MedIEViewRelationDrawingStrategy(rangeIERel,
util.getIERelationSystemEntityFromFeature(), util.getIERelationSystemEntityToFeature(), displayLabel),
rangeIERel);
// style for IERelation
StyleRange rangeIERelSystem = new StyleRange();
Feature displayLabel = util.getIERelationSystemType().getFeatureByBaseName("DisplayLabel");
rangeIERelSystem.background = new Color(overlay.getDisplay(), 156, 151, 17);
AnnoStyle styleIERelSystem = new AnnoStyle(new MedIEViewRelationDrawingStrategy(rangeIERel,
util.getIERelationSystemEntityFromFeature(), util.getIERelationSystemEntityToFeature(),
displayLabel), rangeIERel);
editor.changeStyle(util.getIERelationSystemType(), styleIERelSystem);
editor.changeStyle(util.getIERelationSystemType(), styleIERelSystem);
return true;
}
return true;
}
@Override
protected void initLayout(Composite parent) {
@Override
protected void initLayout(Composite parent) {
parent.setLayout(new GridLayout(3, false));
parent.setLayout(new GridLayout(3, false));
GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_VERTICAL));
parent.setLayoutData(gd);
GridData gd = new GridData(
GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_VERTICAL));
parent.setLayoutData(gd);
// button composite
initButtonComposite(parent);
// button composite
initButtonComposite(parent);
System.out.println(tree);
tree = new IEOntologyTreeComposite(parent, SWT.NONE, editor);
GridData gdTree = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
gdTree.horizontalSpan = 3;
System.out.println(tree);
tree = new IEOntologyTreeComposite(parent, SWT.NONE, editor);
GridData gdTree = new GridData(
GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
gdTree.horizontalSpan = 3;
tree.setLayoutData(gdTree);
tree.setLayoutData(gdTree);
if (this.ontology != null) {
tree.setOntology(ontology);
renewPage();
}
if (this.ontology != null) {
tree.setOntology(ontology);
renewPage();
}
}
}
private void initButtonComposite(Composite parent) {
buttonCreateTerminology = new Button(parent, SWT.PUSH);
private void initButtonComposite(Composite parent) {
buttonCreateTerminology = new Button(parent, SWT.PUSH);
buttonCreateTerminology.setText("Create Terminology");
buttonCreateTerminology.setText("Create Terminology");
buttonCreateTerminology.addSelectionListener(new SelectionAdapter() {
buttonCreateTerminology.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter a terminology name",
"", null);
if (dlg.open() == Window.OK) {
String ontIri = ONTOLOGY_BASE_IRI + dlg.getValue();
InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "",
"Enter a terminology name", "", null);
if (dlg.open() == Window.OK) {
String ontIri = ONTOLOGY_BASE_IRI + dlg.getValue();
OWLOntology ont = OWLUtil.createMedOntology(ontIri);
OWLOntology ont = OWLUtil.createMedOntology(ontIri);
if (ont != null) {
ontology = new IEOntology(ont);
updateOntology();
}
if (ont != null) {
ontology = new IEOntology(ont);
updateOntology();
}
}
}
}
}
});
});
buttonLoadTerminology = new Button(parent, SWT.PUSH);
buttonLoadTerminology = new Button(parent, SWT.PUSH);
buttonLoadTerminology.setText("Load Terminology");
buttonLoadTerminology.setText("Load Terminology");
buttonLoadTerminology.addSelectionListener(new SelectionAdapter() {
buttonLoadTerminology.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);
dlg.setText("Open");
String path = dlg.open();
if (path == null)
return;
FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN);
dlg.setText("Open");
String path = dlg.open();
if (path == null)
return;
openedTerminologyPath = path;
openedTerminologyPath = path;
ontology = IEOntology.loadOntologyFromFile(openedTerminologyPath);
ontology = IEOntology.loadOntologyFromFile(openedTerminologyPath);
// check if all necessary nodes are present
OWLUtil.addMedicalRootNodesIfNecessary(ontology.getOntology());
// check if all necessary nodes are present
OWLUtil.addMedicalRootNodesIfNecessary(ontology.getOntology());
updateOntology();
// TODO add the loaded terminology to the widget
updateOntology();
// TODO add the loaded terminology to the widget
// also save it once !! TODO
renewPage();
// also save it once !! TODO
renewPage();
}
}
});
});
buttonSaveTerminology = new Button(parent, SWT.PUSH);
buttonSaveTerminology = new Button(parent, SWT.PUSH);
buttonSaveTerminology.setText("Save Terminology");
buttonSaveTerminology.setText("Save Terminology");
buttonSaveTerminology.addSelectionListener(new SelectionAdapter() {
buttonSaveTerminology.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
if (ontology == null)
return;
if (ontology == null)
return;
FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
dlg.setText("Save Terminology");
dlg.setFileName(OWLUtil.getOntologyIRI(ontology.getOntology()).getFragment());
String[] filterExt = { "*.owl", "*.txt", "*.png" };
dlg.setFilterExtensions(filterExt);
openedTerminologyPath = dlg.open();
FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
dlg.setText("Save Terminology");
dlg.setFileName(OWLUtil.getOntologyIRI(ontology.getOntology()).getFragment());
String[] filterExt = { "*.owl", "*.txt", "*.png" };
dlg.setFilterExtensions(filterExt);
openedTerminologyPath = dlg.open();
if (openedTerminologyPath == null || dlg.getFilterIndex() == -1)
return;
if (openedTerminologyPath == null || dlg.getFilterIndex() == -1)
return;
if (dlg.getFilterIndex() == 1) {
// Save as text
if (dlg.getFilterIndex() == 1) {
// Save as text
if (openedTerminologyPath.endsWith(".txt")) {
openedTerminologyPath += ".txt";
}
// TODO yet unsupported
if (openedTerminologyPath.endsWith(".txt")) {
openedTerminologyPath += ".txt";
}
// TODO yet unsupported
}
}
else if (dlg.getFilterIndex() == 2) {
else if (dlg.getFilterIndex() == 2) {
// save as PNG
if (!openedTerminologyPath.endsWith(".png")) {
openedTerminologyPath += ".png";
}
// save as PNG
if (!openedTerminologyPath.endsWith(".png")) {
openedTerminologyPath += ".png";
}
// TODO unsupported yet
}
// TODO unsupported yet
}
else if (dlg.getFilterIndex() == 0) {
else if (dlg.getFilterIndex() == 0) {
// save as xml
if (!openedTerminologyPath.endsWith(".owl")) {
openedTerminologyPath += ".owl";
}
IEOntology.saveOntologyToFile(openedTerminologyPath, ontology);
// save as xml
if (!openedTerminologyPath.endsWith(".owl")) {
openedTerminologyPath += ".owl";
}
IEOntology.saveOntologyToFile(openedTerminologyPath, ontology);
}
}
}
}
});
});
buttonApplyTerminology = new Button(parent, SWT.PUSH);
buttonApplyTerminology = new Button(parent, SWT.PUSH);
buttonApplyTerminology.setText("Apply Terminology");
buttonApplyTerminology.setText("Apply Terminology");
buttonApplyTerminology.addSelectionListener(new SelectionAdapter() {
buttonApplyTerminology.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
// clean old types
applyExtractionAlgorithm();
// clean old types
applyExtractionAlgorithm();
}
}
});
});
buttonCreateRelation = new Button(parent, SWT.PUSH);
buttonCreateRelation.setText("Create Relation");
buttonCreateRelation.addSelectionListener(new SelectionAdapter() {
buttonCreateRelation = new Button(parent, SWT.PUSH);
buttonCreateRelation.setText("Create Relation");
buttonCreateRelation.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
RelationCreationDialog dialog = new RelationCreationDialog(Display.getCurrent().getActiveShell(),
editor);
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
RelationCreationDialog dialog = new RelationCreationDialog(
Display.getCurrent().getActiveShell(), editor);
if (dialog.open() == Dialog.OK) {
// blab
if (dialog.open() == Dialog.OK) {
// blab
// this is the tricky part we need to assure that our
// relation has gold entities!
AnnotationFS createdRelation = dialog.getCreatedRelation();
AnnotationFS from = (AnnotationFS) createdRelation
.getFeatureValue(util.getIERelationGoldEntityFromFeature());
AnnotationFS to = (AnnotationFS) createdRelation
.getFeatureValue(util.getIERelationGoldEntityToFeature());
// this is the tricky part we need to assure that our
// relation has gold entities!
AnnotationFS createdRelation = dialog.getCreatedRelation();
AnnotationFS from = (AnnotationFS) createdRelation
.getFeatureValue(util.getIERelationGoldEntityFromFeature());
AnnotationFS to = (AnnotationFS) createdRelation
.getFeatureValue(util.getIERelationGoldEntityToFeature());
if (from.getType().getShortName().equals(util.getIEEntitySystemType().getShortName())) {
// clone system to gold to prevent them from being
// deleted
AnnotationFS goldEntity = cloneSystemEntityToGoldEntity(from);
editor.getCas().addFsToIndexes(goldEntity);
createdRelation.setFeatureValue(util.getIERelationGoldEntityFromFeature(), goldEntity);
if (from.getType().getShortName().equals(util.getIEEntitySystemType().getShortName())) {
// clone system to gold to prevent them from being
// deleted
AnnotationFS goldEntity = cloneSystemEntityToGoldEntity(from);
editor.getCas().addFsToIndexes(goldEntity);
createdRelation.setFeatureValue(util.getIERelationGoldEntityFromFeature(), goldEntity);
}
if (to.getType().getShortName().equals(util.getIEEntitySystemType().getShortName())) {
// clone system to gold to prevent them from being
// deleted
AnnotationFS goldEntity = cloneSystemEntityToGoldEntity(to);
editor.getCas().addFsToIndexes(goldEntity);
createdRelation.setFeatureValue(util.getIERelationGoldEntityToFeature(), goldEntity);
}
editor.addAnnotation(createdRelation);
}
}
private AnnotationFS cloneSystemEntityToGoldEntity(AnnotationFS systemEntity) {
AnnotationFS goldEntity = systemEntity.getCAS().createAnnotation(util.getIEEntityGoldType(),
systemEntity.getBegin(), systemEntity.getEnd());
// ste the according features
goldEntity.setFeatureValueFromString(util.getIEEntityGoldCategoryFeature(),
systemEntity.getFeatureValueAsString(util.getIEEntitySystemCategoryFeature()));
goldEntity.setFeatureValueFromString(util.getIEEntityGoldConstructedByFeature(),
systemEntity.getFeatureValueAsString(util.getIEEntitySystemConstructedByFeature()));
return goldEntity;
}
});
Button buttonEvaluate = new Button(parent, SWT.PUSH);
buttonEvaluate.setText("Evaluate");
buttonEvaluate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* Open a shell to display the LuceneView. If it is already
* displayed in a shell, bring the shell to the foreground
* instead.
*/
if (evaluationShell == null) {
evaluationShell = new Shell(SWT.CLOSE | SWT.TITLE | SWT.RESIZE | SWT.MAX | SWT.MIN | SWT.MODELESS);
evaluationShell.setText("Evaluation View");
evaluationShell.setLayout(new GridLayout());
new EvaluationComposite(evaluationShell, SWT.NONE, ontology, broker);
evaluationShell.addDisposeListener(event -> evaluationShell = null);
evaluationShell.pack();
evaluationShell.open();
} else {
evaluationShell.setActive();
}
}
});
buttonUseAutosave = new Button(parent, SWT.CHECK);
buttonUseAutosave.setText("Use Autosave?:");
buttonUseAutosave.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
buttonUseAutosave.getSelection();
if (buttonUseAutosave.getSelection()) {
autoSaveTimer = new Timer(true);
autoSaveTimer.schedule(autoSaveTask, 0, 300000);
} else {
if (autoSaveTimer != null) {
autoSaveTimer.cancel();
}
}
}
});
autoSaveTask = new TimerTask() {
@Override
public void run() {
if (openedTerminologyPath == null) {
return;
}
String autosavePath = openedTerminologyPath.replaceAll("\\.xml", "").replaceAll("\\.txt", "");
// TODO does nothing at the moment...
// JAXB.marshal(terminology, new File(autosavePath +
// "_autosave.xml"));
}
};
buttonUseAutosave.setSelection(true);
}
private void renewPage() {
super.overlay.layout();
}
private void applyExtractionAlgorithm() {
cleanOldAnnotations();
if (editor != null && ontology != null) {
ieAlgorithm.extract(editor.getCas(), ontology.getOntology());
// reassign TP/FN/FP features to the relations
for (AnnotationFS relSystem : editor.getCas().getAnnotationIndex(util.getIERelationSystemType())) {
String resultType = determineCorrectnessOfRelation(relSystem);
relSystem.setFeatureValueFromString(util.getIERelationSystemLabelFeature(), resultType);
}
editor.invokeReload();
}
}
private String determineCorrectnessOfRelation(AnnotationFS relSystem) {
for (AnnotationFS relGold : editor.getCas().getAnnotationIndex(util.getIERelationGoldType())) {
// span
if (relSystem.getBegin() == relGold.getBegin() && relSystem.getEnd() == relGold.getEnd()) {
// assigned entities
boolean entitiesMatch = testEntitiesForMatch(relSystem, relGold);
if (entitiesMatch) {
return "TP";
}
}
}
return "FP";
}
private boolean testEntitiesForMatch(AnnotationFS relSystem, AnnotationFS relGold) {
AnnotationFS entFromGold = (AnnotationFS) relGold.getFeatureValue(util.getIERelationGoldEntityFromFeature());
AnnotationFS entFromSystem = (AnnotationFS) relSystem
.getFeatureValue(util.getIERelationSystemEntityFromFeature());
AnnotationFS entToGold = (AnnotationFS) relGold.getFeatureValue(util.getIERelationGoldEntityToFeature());
AnnotationFS entToSystem = (AnnotationFS) relSystem.getFeatureValue(util.getIERelationSystemEntityToFeature());
if (entFromGold == null || entFromSystem == null || entToGold == null || entToSystem == null)
return false;
if (entFromGold.getBegin() != entFromSystem.getBegin() || entFromGold.getEnd() != entFromSystem.getEnd())
return false;
if (entToGold.getBegin() != entToSystem.getBegin() || entToGold.getEnd() != entToSystem.getEnd())
return false;
return true;
}
private void cleanOldAnnotations() {
List<AnnotationFS> toDelete = new ArrayList<>();
for (AnnotationFS entity : editor.getCas().getAnnotationIndex(util.getIEEntitySystemType())) {
toDelete.add(entity);
}
for (AnnotationFS rel : editor.getCas().getAnnotationIndex(util.getIERelationSystemType())) {
toDelete.add(rel);
}
// also IECounter and IEPos
for (AnnotationFS rel : editor.getCas().getAnnotationIndex(
editor.getCas().getTypeSystem().getType("de.uniwue.mk.kallimachos.ie.IEPostprocessing"))) {
toDelete.add(rel);
}
for (AnnotationFS rel : editor.getCas()
.getAnnotationIndex(editor.getCas().getTypeSystem().getType("de.uniwue.mk.kallimachos.ie.IECount"))) {
toDelete.add(rel);
}
// speed up
for (int i = 0; i < toDelete.size(); i++) {
if (i == toDelete.size() - 1) {
editor.removeAnnotation(toDelete.get(i));
} else {
editor.getCas().removeFsFromIndexes(toDelete.get(i));
}
}
}
private void updateOntology() {
// we need to change the tree obviously
tree.setOntology(ontology);
}
}
if (to.getType().getShortName().equals(util.getIEEntitySystemType().getShortName())) {
// clone system to gold to prevent them from being
// deleted
AnnotationFS goldEntity = cloneSystemEntityToGoldEntity(to);
editor.getCas().addFsToIndexes(goldEntity);
createdRelation.setFeatureValue(util.getIERelationGoldEntityToFeature(), goldEntity);
}
editor.addAnnotation(createdRelation);
}
}
private AnnotationFS cloneSystemEntityToGoldEntity(AnnotationFS systemEntity) {
AnnotationFS goldEntity = systemEntity.getCAS().createAnnotation(util.getIEEntityGoldType(),
systemEntity.getBegin(), systemEntity.getEnd());
// ste the according features
goldEntity.setFeatureValueFromString(util.getIEEntityGoldCategoryFeature(),
systemEntity.getFeatureValueAsString(util.getIEEntitySystemCategoryFeature()));
goldEntity.setFeatureValueFromString(util.getIEEntityGoldConstructedByFeature(),
systemEntity.getFeatureValueAsString(util.getIEEntitySystemConstructedByFeature()));
return goldEntity;
}
});
Button buttonEvaluate = new Button(parent, SWT.PUSH);
buttonEvaluate.setText("Evaluate");
buttonEvaluate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* Open a shell to display the LuceneView. If it is already displayed in a shell, bring the
* shell to the foreground instead.
*/
if (evaluationShell == null) {
evaluationShell = new Shell(
SWT.CLOSE | SWT.TITLE | SWT.RESIZE | SWT.MAX | SWT.MIN | SWT.MODELESS);
evaluationShell.setText("Evaluation View");
evaluationShell.setLayout(new GridLayout());
new EvaluationComposite(evaluationShell, SWT.NONE, ontology, broker);
evaluationShell.addDisposeListener(event -> evaluationShell = null);
evaluationShell.pack();
evaluationShell.open();
} else {
evaluationShell.setActive();
}
}
});
buttonUseAutosave = new Button(parent, SWT.CHECK);
buttonUseAutosave.setText("Use Autosave?:");
buttonUseAutosave.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
buttonUseAutosave.getSelection();
if (buttonUseAutosave.getSelection()) {
autoSaveTimer = new Timer(true);
autoSaveTimer.schedule(autoSaveTask, 0, 300000);
} else {
if (autoSaveTimer != null) {
autoSaveTimer.cancel();
}
}
}
});
autoSaveTask = new TimerTask() {
@Override
public void run() {
if (openedTerminologyPath == null) {
return;
}
String autosavePath = openedTerminologyPath.replaceAll("\\.xml", "").replaceAll("\\.txt",
"");
// TODO does nothing at the moment...
// JAXB.marshal(terminology, new File(autosavePath +
// "_autosave.xml"));
}
};
buttonUseAutosave.setSelection(true);
}
private void renewPage() {
super.overlay.layout();
}
private void applyExtractionAlgorithm() {
cleanOldAnnotations();
if (editor != null && ontology != null) {
try {
// we need to make a hard copy of the ontology or the editor will show/save the expanded one
// after applying the algorithms once
OWLOntology tempOntology = OWLUtil.copyOntology(ontology.getOntology());
OWLUtil.expandTerminology(tempOntology);
ieAlgorithm.extract(editor.getCas(), tempOntology);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
// reassign TP/FN/FP features to the relations
for (AnnotationFS relSystem : editor.getCas()
.getAnnotationIndex(util.getIERelationSystemType())) {
String resultType = determineCorrectnessOfRelation(relSystem);
relSystem.setFeatureValueFromString(util.getIERelationSystemLabelFeature(), resultType);
}
editor.invokeReload();
}
}
private String determineCorrectnessOfRelation(AnnotationFS relSystem) {
for (AnnotationFS relGold : editor.getCas().getAnnotationIndex(util.getIERelationGoldType())) {
// span
if (relSystem.getBegin() == relGold.getBegin() && relSystem.getEnd() == relGold.getEnd()) {
// assigned entities
boolean entitiesMatch = testEntitiesForMatch(relSystem, relGold);
if (entitiesMatch) {
return "TP";
}
}
}
return "FP";
}
private boolean testEntitiesForMatch(AnnotationFS relSystem, AnnotationFS relGold) {
AnnotationFS entFromGold = (AnnotationFS) relGold
.getFeatureValue(util.getIERelationGoldEntityFromFeature());
AnnotationFS entFromSystem = (AnnotationFS) relSystem
.getFeatureValue(util.getIERelationSystemEntityFromFeature());
AnnotationFS entToGold = (AnnotationFS) relGold
.getFeatureValue(util.getIERelationGoldEntityToFeature());
AnnotationFS entToSystem = (AnnotationFS) relSystem
.getFeatureValue(util.getIERelationSystemEntityToFeature());
if (entFromGold == null || entFromSystem == null || entToGold == null || entToSystem == null)
return false;
if (entFromGold.getBegin() != entFromSystem.getBegin()
|| entFromGold.getEnd() != entFromSystem.getEnd())
return false;
if (entToGold.getBegin() != entToSystem.getBegin()
|| entToGold.getEnd() != entToSystem.getEnd())
return false;
return true;
}
private void cleanOldAnnotations() {
List<AnnotationFS> toDelete = new ArrayList<>();
for (AnnotationFS entity : editor.getCas().getAnnotationIndex(util.getIEEntitySystemType())) {
toDelete.add(entity);
}
for (AnnotationFS rel : editor.getCas().getAnnotationIndex(util.getIERelationSystemType())) {
toDelete.add(rel);
}
// also IECounter and IEPos
for (AnnotationFS rel : editor.getCas().getAnnotationIndex(editor.getCas().getTypeSystem()
.getType("de.uniwue.mk.kallimachos.ie.IEPostprocessing"))) {
toDelete.add(rel);
}
for (AnnotationFS rel : editor.getCas().getAnnotationIndex(
editor.getCas().getTypeSystem().getType("de.uniwue.mk.kallimachos.ie.IECount"))) {
toDelete.add(rel);
}
// speed up
for (int i = 0; i < toDelete.size(); i++) {
if (i == toDelete.size() - 1) {
editor.removeAnnotation(toDelete.get(i));
} else {
editor.getCas().removeFsFromIndexes(toDelete.get(i));
}
}
}
private void updateOntology() {
// we need to change the tree obviously
tree.setOntology(ontology);
}
}
\ No newline at end of file
package de.uniwue.mk.kall.athen.part.editor.subordinate;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
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.resource.metadata.TypeSystemDescription;
import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.util.CasCopier;
import org.apache.uima.util.InvalidXMLException;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
......@@ -71,6 +82,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
protected Feature editorErrorMessageFeature;
protected Feature editorErrorTypeFeature;
protected String rutaScript;
// for the preferences dialog
protected Dialog preferencesDialog = null;
......@@ -93,7 +106,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override
public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationAdded(arg0);
}
};
......@@ -101,6 +115,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override
public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationRemoved(arg0);
}
};
......@@ -128,6 +144,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override
public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationChanged(arg0);
}
......@@ -288,12 +306,12 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
// init the required typings and set the preferences
boolean typesValid = initTypes();
//also init standard types
initStandardTypes();
//TODO init the guidelines
//TODO this should be implemented a bit better
while (!typesValid) {
......@@ -363,7 +381,7 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
//Optional to implement this
public void initModel(){
}
//this is mandatory
......@@ -627,7 +645,85 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
this.part = part2;
standardSubscribeToEditorDocumentChangedEvents(class_this);
}
/**
* This method copies the line of text that includes the begin and end indices and all
* Annotations on it into a new CAS. On this new CAS the rutaScript is executed and
* any Annotations of Type "de.uniwue.kalimachos.coref.type.athenWarningType" are copied back
* into the Editor's CAS. <br/>
* If this View has no rutaScript set nothing is done.
* @param begin
* @param end
*/
protected void runRutaScript(int begin, int end) {
if (rutaScript == null) {
return;
}
/*
* get the line of text that contains begin to end from the editor
*/
int lineNumber = editor.getWidget().getLineAtOffset(begin);
String lineText = editor.getWidget().getLine(lineNumber);
int lineBegin = editor.getWidget().getOffsetAtLine(lineNumber);
int lineEnd = lineBegin + lineText.length();
Runnable runnable = () -> {
try {
/*
* remove old warning Annotations before running the script
*/
HashSet<AnnotationFS> set = new HashSet<>();
editor.getCas().getAnnotationIndex(editorErrorType).forEach(anno -> {
if (anno.getBegin() >= lineBegin && anno.getEnd() <= lineEnd) {
set.add(anno);
}
});;
set.forEach(anno -> editor.getCas().removeFsFromIndexes(anno));
CAS cas = ApplicationUtil.createCAS();
cas.setDocumentText(editor.getCas().getDocumentText());
CasCopier copier = new CasCopier(editor.getCas(), cas);
/*
* copy Annotations that are between lineBegin and lineEnd to the new CAS
*/
editor.getCas().getAnnotationIndex().forEach(annotation -> {
if (annotation.getBegin() >= lineBegin && annotation.getEnd() <= lineEnd) {
FeatureStructure copy = copier.copyFs(annotation);
addCopyToCas(copy, cas);
}
});
/*
* Run script
*/
Ruta.apply(cas, rutaScript);
/*
* Copy error Annotations into the editor's CAS
*/
CasCopier resultCopier = new CasCopier(cas, editor.getCas());
cas.getAnnotationIndex(editorErrorType).forEach(anno -> {
FeatureStructure copyFs = resultCopier.copyFs(anno);
editor.getCas().addFsToIndexes(copyFs);
});
/*
* Reload editor widget
*/
editor.getDisplay().asyncExec(() -> editor.invokeReload());
} catch (AnalysisEngineProcessException | InvalidXMLException
| ResourceInitializationException | ResourceConfigurationException
| IOException | URISyntaxException e) {
e.printStackTrace();
}
};
Thread thread = new Thread(runnable);
thread.start();
}
private void addCopyToCas(FeatureStructure copy, CAS cas) {
cas.addFsToIndexes(copy);
copy.getType().getFeatures().stream().filter(feature -> !feature.getRange().isPrimitive()).
filter(feature -> copy.getFeatureValue(feature) != null).
forEach(feature -> addCopyToCas(copy.getFeatureValue(feature), cas));
}
//TODO this could get additional things such as preprocessing/an active learning component
}
......@@ -839,7 +839,8 @@ public class AnnotationEditorWidget extends Composite {
* work reliably.
*/
for (Control ctrl : widget.getChildren()) {
if (ctrl.getData("origin").equals("ttv")) {
if (ctrl.getData("origin").equals("ttv") ||
ctrl.getData("origin").equals("editorWarning")) {
ctrl.dispose();
}
}
......
......@@ -2,6 +2,7 @@ package de.uniwue.mk.kall.athen.projectExplorer.projectDescription;
import java.io.File;
import java.io.IOException;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
......@@ -29,8 +30,6 @@ public class AnnotationWorkspace {
private WatchService watcher;
private WatchKey key;
private IEventBroker broker;
public AnnotationWorkspace(File wsFile, IEventBroker broker) {
......@@ -50,21 +49,18 @@ public class AnnotationWorkspace {
Path dir = AnnotationWorkspace.this.wsFile.toPath();
registerAll(dir);
// key = dir.register(watcher,
// StandardWatchEventKinds.ENTRY_CREATE,
// StandardWatchEventKinds.ENTRY_DELETE,
// StandardWatchEventKinds.ENTRY_MODIFY);
registerFileWatcher();
} catch (ClosedWatchServiceException e) {
// nothing to do (Workspace has probably been changed)
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
// execute the watch service
Thread t = new Thread(r);
......@@ -93,7 +89,8 @@ public class AnnotationWorkspace {
}
private void register(Path dir) throws IOException {
WatchKey key = dir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
dir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
// if (trace) {
......@@ -117,6 +114,8 @@ public class AnnotationWorkspace {
WatchKey key;
try {
key = watcher.take();
} catch (ClosedWatchServiceException e) {
return;
} catch (InterruptedException x) {
return;
}
......@@ -171,7 +170,7 @@ public class AnnotationWorkspace {
return wsFile;
}
public void setWsFile(File wsFile) {
private void setWsFile(File wsFile) {
this.wsFile = wsFile;
File[] listFiles = this.wsFile.listFiles();
......@@ -211,4 +210,12 @@ public class AnnotationWorkspace {
public void addProject(IAnnotationProject project) {
this.projects.add(project);
}
/**
* Closes the WatchService for this Workspace.
* @throws IOException
*/
public void close() throws IOException {
watcher.close();
}
}
......@@ -326,6 +326,13 @@ public class ProjectExplorer {
* called when the workspace is changed
*/
public void onWorkSpaceChanged(AnnotationWorkspace ws) {
if (workspace != null) {
try {
workspace.close();
} catch (IOException e) {
e.printStackTrace();
}
}
this.workspace = ws;
reload(true);
......
package de.uniwue.kalimachos.coref.paintingStrategies;
import org.apache.uima.cas.text.AnnotationFS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import de.uniwue.kalimachos.coref.editor.drawingstructure.TypeStyleDataStructure;
public class EditorWarningDrawingStrategy implements IAnnotationDrawingStrategy, IBorderDrawingStrategy {
@Override
public void drawAnnotation(TypeStyleDataStructure struct, AnnotationFS anno, StyledText widget, GC gc) {
// color for warning
private Color orange;
private Color lightOrange;
// color for error
private Color red;
private Color lightRed;
// color for warning
Color orange = new Color(Display.getCurrent(), new RGB(247, 142, 5));
Color lightOrange = new Color(Display.getCurrent(), new RGB(250, 186, 102));
// color for error
Color red = new Color(Display.getCurrent(), new RGB(0, 0, 255));
Color lightRed = new Color(Display.getCurrent(), new RGB(144, 195, 212));
public EditorWarningDrawingStrategy() {
orange = new Color(Display.getCurrent(), new RGB(247, 142, 5));
lightOrange = new Color(Display.getCurrent(), new RGB(250, 186, 102));
red = new Color(Display.getCurrent(), new RGB(0, 0, 255));
lightRed = new Color(Display.getCurrent(), new RGB(144, 195, 212));
}
// draw a rectangle for an annotation
@Override
public void drawAnnotation(TypeStyleDataStructure struct, final AnnotationFS anno,
final StyledText widget, GC gc) {
// set colour depending on the ErrorType of the Annotation
String type = anno.getFeatureValueAsString(
anno.getType().getFeatureByBaseName("ErrorType"));
Color colorFill = lightOrange;
Color colorBorder = orange;
if (type != null && type.contains("rror")) {
colorFill = lightRed;
colorBorder = red;
}
// draw a rectangle for an annotation
Rectangle textBounds = widget.getTextBounds(0, 1);
int lineTop = Math.abs(widget.getTextBounds(anno.getBegin(), anno.getBegin() + 1).y - textBounds.y);
int lineBottom = Math.abs(widget.getTextBounds(anno.getEnd() - 1, anno.getEnd()).y - textBounds.y);
int lineTop = widget.getTextBounds(anno.getBegin(), anno.getBegin() + 1).y - textBounds.y;
int lineBottom = widget.getTextBounds(anno.getEnd() - 1, anno.getEnd()).y - textBounds.y;
Rectangle textBounds2 = widget.getTextBounds(widget.getText().length() - 2, widget.getText().length() - 1);
int lineCnt = Math.abs(textBounds.y) + Math.abs(textBounds2.y);
int topPixel = lineToPixel(widget.getBounds().height, lineTop, lineCnt);
int bottomPixel = lineToPixel(widget.getBounds().height, lineBottom, lineCnt);
int topPixel = lineToPixel(widget.getBounds().height - 10, lineTop, lineCnt);
int bottomPixel = lineToPixel(widget.getBounds().height - 10, lineBottom, lineCnt);
gc.setForeground(orange);
gc.setBackground(lightOrange);
gc.setForeground(colorBorder);
gc.setBackground(colorFill);
if (bottomPixel == topPixel) {
// increase the rectangle artificially
bottomPixel += 3;
topPixel -= 3;
}
gc.drawRectangle(widget.getBounds().width - widget.getRightMargin() - 2, topPixel + 2, 6, bottomPixel
- topPixel - 2);
gc.fillRectangle(new Rectangle(widget.getBounds().width - (widget.getRightMargin() + 1), topPixel + 1 + 2,
7 - 2, bottomPixel - topPixel - 1 - 2));
orange.dispose();
lightOrange.dispose();
red.dispose();
lightRed.dispose();
Rectangle innerRect = new Rectangle(widget.getBounds().width - widget.getRightMargin() - 4,
topPixel + 1 + 2, 8, bottomPixel - topPixel - 1 - 2);
Rectangle outerRect = new Rectangle(widget.getBounds().width - widget.getRightMargin() - 5,
topPixel + 2, 10, bottomPixel - topPixel - 2);
gc.drawRectangle(outerRect);
gc.fillRectangle(innerRect);
Composite composite = new Composite(widget, SWT.NONE);
composite.setBounds(innerRect);
composite.setBackground(colorFill);
composite.setData("origin", "editorWarning");
composite.setToolTipText(anno.getFeatureValueAsString(
anno.getType().getFeatureByBaseName("ErrorMessage")));
composite.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
}
@Override
public void mouseDown(MouseEvent e) {
widget.setSelection(anno.getBegin(), anno.getEnd());
}
@Override
public void mouseDoubleClick(MouseEvent e) {
}
});
}
public static int lineToPixel(int height, int line, int lineCnt) {
......
......@@ -84,7 +84,7 @@ public class OWLUtil {
public static final String MED_IE_NODE_TYPE = "MEDIE_NODE_TYPE";
public static final String MED_IE_NODE_CATEGORY = "MEDIE_NODE_CATEGORY";
public static final String MED_IE_RESPECT_NEGATION = "MEDIE_RESPECT_NEGATION";
public static final String MED_IE_SINGLETON = "MED_IE_SINGLETON";
......@@ -194,7 +194,7 @@ public class OWLUtil {
return identicalProbs;
}
public OWLClass getClassForName(String className, OWLOntology ont) {
public static OWLClass getClassForName(String className, OWLOntology ont) {
for (OWLClass c : ont.getClassesInSignature()) {
......@@ -948,7 +948,7 @@ public class OWLUtil {
public static boolean isMedicalAttributeClass(OWLClass oc, OWLOntology ontology) {
OWLAnnotation medieNodeTypeAnnotation = getMEDIENodeTypeAnnotation(oc, ontology);
OWLAnnotation medieNodeTypeAnnotation = getMEDIENodeCategoryAnnotation(oc, ontology);
if (medieNodeTypeAnnotation == null)
return false;
......@@ -956,7 +956,7 @@ public class OWLUtil {
if (medieNodeTypeAnnotation.getValue() instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) medieNodeTypeAnnotation.getValue();
return literal.getLiteral().equals(ATTRIBUTE);
return literal.getLiteral().equals(ATTRIBUTE.toLowerCase());
}
return false;
}
......@@ -1278,8 +1278,8 @@ public class OWLUtil {
POSTPROCESSING.toLowerCase(), createOntology);
addEntityToOntology(postProcRoot, createOntology);
addAnnotationToEntity(annotationPostProc, postProcRoot, createOntology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE,
"BOOLEAN", createOntology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, "BOOLEAN",
createOntology);
addAnnotationToEntity(annotationAtt, postProcRoot, createOntology);
}
......@@ -1310,8 +1310,7 @@ public class OWLUtil {
public static void changeToPostProcessing(OWLClass newClass, OWLOntology ontology) {
OWLAnnotation annotation = createAnnotation(OWLUtil.MED_IE_NODE_CATEGORY,
POSTPROCESSING.toLowerCase(), ontology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE,
"BOOLEAN", ontology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, "BOOLEAN", ontology);
addAnnotationToEntity(annotation, newClass, ontology);
addAnnotationToEntity(annotationAtt, newClass, ontology);
......@@ -1382,7 +1381,6 @@ public class OWLUtil {
// load a properties file
prop.load(input);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
......@@ -1397,4 +1395,54 @@ public class OWLUtil {
return prop;
}
public static Collection<OWLClass> getTemplatesOnClass(OWLClass owlClass, OWLOntology ontology) {
List<OWLClass> classes = new ArrayList<OWLClass>();
List<OWLAnnotation> annosOfType = getAllAnnotationsOfType("TEMPLATE", owlClass, ontology);
for (OWLAnnotation anno : annosOfType) {
String className = ((OWLLiteral) anno.getValue()).getLiteral();
OWLClass classByIRI = getClassForName(className, ontology);
if (classByIRI != null) {
classes.add(classByIRI);
}
}
return classes;
}
public static void expandTerminology(OWLOntology ontology) {
List<OWLClass> attributes = getMedicalAttributes(ontology);
for (OWLClass attribute : attributes) {
Collection<OWLClass> templatesOnClass = getTemplatesOnClass(attribute, ontology);
for (OWLClass template : templatesOnClass) {
List<OWLClass> values = getAllSubsumedClasses(template, ontology);
for (OWLClass value : values) {
OWLClass expandedValue = createNewClass(ontology,
attribute.getIRI().getFragment() + "_" + value.getIRI().getFragment());
OWLAnnotation nodeType = createAnnotation(MED_IE_NODE_CATEGORY, "choice", ontology);
addAnnotationToEntity(nodeType, expandedValue, ontology);
setDisplayName(expandedValue, ontology, getDisplayName(value, ontology));
for (String regex : getAllRegexFromClass(value, ontology)) {
OWLAnnotation newRegex = createAnnotation("Regex", regex, ontology);
addAnnotationToEntity(newRegex, expandedValue, ontology);
}
assignAsSubclass(attribute, expandedValue, ontology);
}
}
List<OWLAnnotation> annotations = getAllAnnotationsOfType("TEMPLATE", attribute, ontology);
for (OWLAnnotation annotation : annotations) {
deleteAnnotationFromOntology(annotation, attribute, ontology);
}
}
}
public static OWLOntology copyOntology(OWLOntology ontology) throws OWLOntologyCreationException {
OWLOntologyManager tempMgr = OWLManager.createOWLOntologyManager();
OWLOntology tempOntology = tempMgr.createOntology(ontology.getOntologyID());
tempMgr.addAxioms(tempOntology, ontology.getAxioms());
return tempOntology;
}
}
package de.uniwue.mkrug.kallimachos.annotation.editor.wizard;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.wizard.Wizard;
......@@ -13,7 +10,6 @@ import de.uniwue.mk.kall.athen.appDelegation.util.ApplicationPreferences;
import de.uniwue.mk.kall.athen.appDelegation.util.ApplicationUtil;
import de.uniwue.mk.kall.athen.events.IAnnotationEditorEvents;
import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.AnnotationProject;
import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.AnnotationProjectDescriptor;
import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.IAnnotationProject;
public class NewProjectWizard extends Wizard {
......@@ -54,19 +50,6 @@ public class NewProjectWizard extends Wizard {
boolean mkdir = child.mkdirs();
if (folder.equals(AnnotationProjectDescriptor.DESCRIPTOR_FOLDER)) {
// add the default typesystem
InputStream source = ApplicationUtil.getBundleRessourceAsStream("/ressources/CorefTypeSystem.xml");
File target = new File(child.getAbsolutePath() + fileSeparator + "CorefTypeSystem.xml");
try {
Files.copy(source, target.toPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
IAnnotationProject proj = new AnnotationProject(newProjectRoot);
......
......@@ -28,6 +28,12 @@ public class ChangeWorkSpaceHandler {
DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setMessage("Choose a directory as workspace");
String wsOld = ApplicationUtil.getFromPreferences(ApplicationPreferences.WORKSPACE, null);
if (wsOld != null) {
dialog.setFilterPath(wsOld);
}
String selection = dialog.open();
// Save to preferences
......