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
Select Git revision

Target

Select target project
  • kallimachos/Athen
1 result
Select Git revision
Show changes
Commits on Source (15)
Showing
with 704 additions and 495 deletions
...@@ -79,6 +79,8 @@ Extending ATHEN ...@@ -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 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. 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 Troubleshooting and contact
......
package de.uniwue.mk.kall.athen.part.editor.subordinate; package de.uniwue.mk.kall.athen.part.editor.subordinate;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap; 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.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type; 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.resource.metadata.TypeSystemDescription;
import org.apache.uima.ruta.engine.Ruta; 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.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.MUIElement;
...@@ -71,6 +82,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -71,6 +82,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
protected Feature editorErrorMessageFeature; protected Feature editorErrorMessageFeature;
protected Feature editorErrorTypeFeature; protected Feature editorErrorTypeFeature;
protected String rutaScript;
// for the preferences dialog // for the preferences dialog
protected Dialog preferencesDialog = null; protected Dialog preferencesDialog = null;
...@@ -93,7 +106,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -93,7 +106,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override @Override
public void handleEvent(Event arg0) { public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationAdded(arg0); onAnnotationAdded(arg0);
} }
}; };
...@@ -101,6 +115,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -101,6 +115,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override @Override
public void handleEvent(Event arg0) { public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationRemoved(arg0); onAnnotationRemoved(arg0);
} }
}; };
...@@ -128,6 +144,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -128,6 +144,8 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
@Override @Override
public void handleEvent(Event arg0) { public void handleEvent(Event arg0) {
AnnotationFS anno = (AnnotationFS) arg0.getProperty(IEventBroker.DATA);
runRutaScript(anno.getBegin(), anno.getEnd());
onAnnotationChanged(arg0); onAnnotationChanged(arg0);
} }
...@@ -288,12 +306,12 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -288,12 +306,12 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
// init the required typings and set the preferences // init the required typings and set the preferences
boolean typesValid = initTypes(); boolean typesValid = initTypes();
//also init standard types //also init standard types
initStandardTypes(); initStandardTypes();
//TODO init the guidelines //TODO init the guidelines
//TODO this should be implemented a bit better //TODO this should be implemented a bit better
while (!typesValid) { while (!typesValid) {
...@@ -363,7 +381,7 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -363,7 +381,7 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
//Optional to implement this //Optional to implement this
public void initModel(){ public void initModel(){
} }
//this is mandatory //this is mandatory
...@@ -627,7 +645,85 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple ...@@ -627,7 +645,85 @@ public abstract class AEditorSubordinateViewPart implements IPerspectiveDecouple
this.part = part2; this.part = part2;
standardSubscribeToEditorDocumentChangedEvents(class_this); 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 //TODO this could get additional things such as preprocessing/an active learning component
} }
...@@ -839,7 +839,8 @@ public class AnnotationEditorWidget extends Composite { ...@@ -839,7 +839,8 @@ public class AnnotationEditorWidget extends Composite {
* work reliably. * work reliably.
*/ */
for (Control ctrl : widget.getChildren()) { for (Control ctrl : widget.getChildren()) {
if (ctrl.getData("origin").equals("ttv")) { if (ctrl.getData("origin").equals("ttv") ||
ctrl.getData("origin").equals("editorWarning")) {
ctrl.dispose(); ctrl.dispose();
} }
} }
......
...@@ -2,6 +2,7 @@ package de.uniwue.mk.kall.athen.projectExplorer.projectDescription; ...@@ -2,6 +2,7 @@ package de.uniwue.mk.kall.athen.projectExplorer.projectDescription;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.ClosedWatchServiceException;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -29,8 +30,6 @@ public class AnnotationWorkspace { ...@@ -29,8 +30,6 @@ public class AnnotationWorkspace {
private WatchService watcher; private WatchService watcher;
private WatchKey key;
private IEventBroker broker; private IEventBroker broker;
public AnnotationWorkspace(File wsFile, IEventBroker broker) { public AnnotationWorkspace(File wsFile, IEventBroker broker) {
...@@ -50,21 +49,18 @@ public class AnnotationWorkspace { ...@@ -50,21 +49,18 @@ public class AnnotationWorkspace {
Path dir = AnnotationWorkspace.this.wsFile.toPath(); Path dir = AnnotationWorkspace.this.wsFile.toPath();
registerAll(dir); registerAll(dir);
// key = dir.register(watcher,
// StandardWatchEventKinds.ENTRY_CREATE,
// StandardWatchEventKinds.ENTRY_DELETE,
// StandardWatchEventKinds.ENTRY_MODIFY);
registerFileWatcher(); registerFileWatcher();
} catch (ClosedWatchServiceException e) {
// nothing to do (Workspace has probably been changed)
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
}; };
// execute the watch service // execute the watch service
Thread t = new Thread(r); Thread t = new Thread(r);
...@@ -93,7 +89,8 @@ public class AnnotationWorkspace { ...@@ -93,7 +89,8 @@ public class AnnotationWorkspace {
} }
private void register(Path dir) throws IOException { 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); StandardWatchEventKinds.ENTRY_MODIFY);
// if (trace) { // if (trace) {
...@@ -117,6 +114,8 @@ public class AnnotationWorkspace { ...@@ -117,6 +114,8 @@ public class AnnotationWorkspace {
WatchKey key; WatchKey key;
try { try {
key = watcher.take(); key = watcher.take();
} catch (ClosedWatchServiceException e) {
return;
} catch (InterruptedException x) { } catch (InterruptedException x) {
return; return;
} }
...@@ -171,7 +170,7 @@ public class AnnotationWorkspace { ...@@ -171,7 +170,7 @@ public class AnnotationWorkspace {
return wsFile; return wsFile;
} }
public void setWsFile(File wsFile) { private void setWsFile(File wsFile) {
this.wsFile = wsFile; this.wsFile = wsFile;
File[] listFiles = this.wsFile.listFiles(); File[] listFiles = this.wsFile.listFiles();
...@@ -211,4 +210,12 @@ public class AnnotationWorkspace { ...@@ -211,4 +210,12 @@ public class AnnotationWorkspace {
public void addProject(IAnnotationProject project) { public void addProject(IAnnotationProject project) {
this.projects.add(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 { ...@@ -326,6 +326,13 @@ public class ProjectExplorer {
* called when the workspace is changed * called when the workspace is changed
*/ */
public void onWorkSpaceChanged(AnnotationWorkspace ws) { public void onWorkSpaceChanged(AnnotationWorkspace ws) {
if (workspace != null) {
try {
workspace.close();
} catch (IOException e) {
e.printStackTrace();
}
}
this.workspace = ws; this.workspace = ws;
reload(true); reload(true);
......
package de.uniwue.kalimachos.coref.paintingStrategies; package de.uniwue.kalimachos.coref.paintingStrategies;
import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.cas.text.AnnotationFS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText; 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.Color;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import de.uniwue.kalimachos.coref.editor.drawingstructure.TypeStyleDataStructure; import de.uniwue.kalimachos.coref.editor.drawingstructure.TypeStyleDataStructure;
public class EditorWarningDrawingStrategy implements IAnnotationDrawingStrategy, IBorderDrawingStrategy { public class EditorWarningDrawingStrategy implements IAnnotationDrawingStrategy, IBorderDrawingStrategy {
@Override // color for warning
public void drawAnnotation(TypeStyleDataStructure struct, AnnotationFS anno, StyledText widget, GC gc) { 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 public EditorWarningDrawingStrategy() {
Color red = new Color(Display.getCurrent(), new RGB(0, 0, 255)); orange = new Color(Display.getCurrent(), new RGB(247, 142, 5));
Color lightRed = new Color(Display.getCurrent(), new RGB(144, 195, 212)); 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); Rectangle textBounds = widget.getTextBounds(0, 1);
int lineTop = Math.abs(widget.getTextBounds(anno.getBegin(), anno.getBegin() + 1).y - textBounds.y); int lineTop = 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 lineBottom = widget.getTextBounds(anno.getEnd() - 1, anno.getEnd()).y - textBounds.y;
Rectangle textBounds2 = widget.getTextBounds(widget.getText().length() - 2, widget.getText().length() - 1); Rectangle textBounds2 = widget.getTextBounds(widget.getText().length() - 2, widget.getText().length() - 1);
int lineCnt = Math.abs(textBounds.y) + Math.abs(textBounds2.y); int lineCnt = Math.abs(textBounds.y) + Math.abs(textBounds2.y);
int topPixel = lineToPixel(widget.getBounds().height, lineTop, lineCnt); int topPixel = lineToPixel(widget.getBounds().height - 10, lineTop, lineCnt);
int bottomPixel = lineToPixel(widget.getBounds().height, lineBottom, lineCnt); int bottomPixel = lineToPixel(widget.getBounds().height - 10, lineBottom, lineCnt);
gc.setForeground(orange); gc.setForeground(colorBorder);
gc.setBackground(lightOrange); gc.setBackground(colorFill);
if (bottomPixel == topPixel) { if (bottomPixel == topPixel) {
// increase the rectangle artificially // increase the rectangle artificially
bottomPixel += 3; bottomPixel += 3;
topPixel -= 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) { public static int lineToPixel(int height, int line, int lineCnt) {
......
...@@ -84,7 +84,7 @@ public class OWLUtil { ...@@ -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_TYPE = "MEDIE_NODE_TYPE";
public static final String MED_IE_NODE_CATEGORY = "MEDIE_NODE_CATEGORY"; 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_RESPECT_NEGATION = "MEDIE_RESPECT_NEGATION";
public static final String MED_IE_SINGLETON = "MED_IE_SINGLETON"; public static final String MED_IE_SINGLETON = "MED_IE_SINGLETON";
...@@ -194,7 +194,7 @@ public class OWLUtil { ...@@ -194,7 +194,7 @@ public class OWLUtil {
return identicalProbs; return identicalProbs;
} }
public OWLClass getClassForName(String className, OWLOntology ont) { public static OWLClass getClassForName(String className, OWLOntology ont) {
for (OWLClass c : ont.getClassesInSignature()) { for (OWLClass c : ont.getClassesInSignature()) {
...@@ -948,7 +948,7 @@ public class OWLUtil { ...@@ -948,7 +948,7 @@ public class OWLUtil {
public static boolean isMedicalAttributeClass(OWLClass oc, OWLOntology ontology) { public static boolean isMedicalAttributeClass(OWLClass oc, OWLOntology ontology) {
OWLAnnotation medieNodeTypeAnnotation = getMEDIENodeTypeAnnotation(oc, ontology); OWLAnnotation medieNodeTypeAnnotation = getMEDIENodeCategoryAnnotation(oc, ontology);
if (medieNodeTypeAnnotation == null) if (medieNodeTypeAnnotation == null)
return false; return false;
...@@ -956,7 +956,7 @@ public class OWLUtil { ...@@ -956,7 +956,7 @@ public class OWLUtil {
if (medieNodeTypeAnnotation.getValue() instanceof OWLLiteral) { if (medieNodeTypeAnnotation.getValue() instanceof OWLLiteral) {
OWLLiteral literal = (OWLLiteral) medieNodeTypeAnnotation.getValue(); OWLLiteral literal = (OWLLiteral) medieNodeTypeAnnotation.getValue();
return literal.getLiteral().equals(ATTRIBUTE); return literal.getLiteral().equals(ATTRIBUTE.toLowerCase());
} }
return false; return false;
} }
...@@ -1278,8 +1278,8 @@ public class OWLUtil { ...@@ -1278,8 +1278,8 @@ public class OWLUtil {
POSTPROCESSING.toLowerCase(), createOntology); POSTPROCESSING.toLowerCase(), createOntology);
addEntityToOntology(postProcRoot, createOntology); addEntityToOntology(postProcRoot, createOntology);
addAnnotationToEntity(annotationPostProc, postProcRoot, createOntology); addAnnotationToEntity(annotationPostProc, postProcRoot, createOntology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, "BOOLEAN",
"BOOLEAN", createOntology); createOntology);
addAnnotationToEntity(annotationAtt, postProcRoot, createOntology); addAnnotationToEntity(annotationAtt, postProcRoot, createOntology);
} }
...@@ -1310,8 +1310,7 @@ public class OWLUtil { ...@@ -1310,8 +1310,7 @@ public class OWLUtil {
public static void changeToPostProcessing(OWLClass newClass, OWLOntology ontology) { public static void changeToPostProcessing(OWLClass newClass, OWLOntology ontology) {
OWLAnnotation annotation = createAnnotation(OWLUtil.MED_IE_NODE_CATEGORY, OWLAnnotation annotation = createAnnotation(OWLUtil.MED_IE_NODE_CATEGORY,
POSTPROCESSING.toLowerCase(), ontology); POSTPROCESSING.toLowerCase(), ontology);
OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, OWLAnnotation annotationAtt = createAnnotation(OWLUtil.MED_IE_NODE_TYPE, "BOOLEAN", ontology);
"BOOLEAN", ontology);
addAnnotationToEntity(annotation, newClass, ontology); addAnnotationToEntity(annotation, newClass, ontology);
addAnnotationToEntity(annotationAtt, newClass, ontology); addAnnotationToEntity(annotationAtt, newClass, ontology);
...@@ -1382,7 +1381,6 @@ public class OWLUtil { ...@@ -1382,7 +1381,6 @@ public class OWLUtil {
// load a properties file // load a properties file
prop.load(input); prop.load(input);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally { } finally {
...@@ -1397,4 +1395,54 @@ public class OWLUtil { ...@@ -1397,4 +1395,54 @@ public class OWLUtil {
return prop; 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; package de.uniwue.mkrug.kallimachos.annotation.editor.wizard;
import java.io.File; 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.e4.core.services.events.IEventBroker;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
...@@ -13,7 +10,6 @@ import de.uniwue.mk.kall.athen.appDelegation.util.ApplicationPreferences; ...@@ -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.appDelegation.util.ApplicationUtil;
import de.uniwue.mk.kall.athen.events.IAnnotationEditorEvents; 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.AnnotationProject;
import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.AnnotationProjectDescriptor;
import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.IAnnotationProject; import de.uniwue.mk.kall.athen.projectExplorer.projectDescription.IAnnotationProject;
public class NewProjectWizard extends Wizard { public class NewProjectWizard extends Wizard {
...@@ -54,19 +50,6 @@ public class NewProjectWizard extends Wizard { ...@@ -54,19 +50,6 @@ public class NewProjectWizard extends Wizard {
boolean mkdir = child.mkdirs(); 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); IAnnotationProject proj = new AnnotationProject(newProjectRoot);
......
...@@ -28,6 +28,12 @@ public class ChangeWorkSpaceHandler { ...@@ -28,6 +28,12 @@ public class ChangeWorkSpaceHandler {
DirectoryDialog dialog = new DirectoryDialog(shell); DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setMessage("Choose a directory as workspace"); dialog.setMessage("Choose a directory as workspace");
String wsOld = ApplicationUtil.getFromPreferences(ApplicationPreferences.WORKSPACE, null);
if (wsOld != null) {
dialog.setFilterPath(wsOld);
}
String selection = dialog.open(); String selection = dialog.open();
// Save to preferences // Save to preferences
......