use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationPageBase method ensureRequiredFeatureValuesSet.
/**
* Checks if all required features on all annotations are set. If a required feature value is
* missing, then the method scrolls to that location and schedules a re-rendering. In such
* a case, an {@link IllegalStateException} is thrown.
*/
protected void ensureRequiredFeatureValuesSet(AjaxRequestTarget aTarget, JCas aJcas) {
AnnotatorState state = getModelObject();
CAS editorCas = aJcas.getCas();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(state.getProject())) {
TypeAdapter adapter = annotationService.getAdapter(layer);
List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
// If no feature is required, then we can skip the whole procedure
if (features.stream().allMatch((f) -> !f.isRequired())) {
continue;
}
// Check each feature structure of this layer
for (AnnotationFS fs : select(editorCas, adapter.getAnnotationType(editorCas))) {
for (AnnotationFeature f : features) {
if (WebAnnoCasUtil.isRequiredFeatureMissing(f, fs)) {
// Find the sentence that contains the annotation with the missing
// required feature value
Sentence s = WebAnnoCasUtil.getSentence(aJcas, fs.getBegin());
// Put this sentence into the focus
state.setFirstVisibleUnit(s);
actionRefreshDocument(aTarget);
// Inform the user
throw new IllegalStateException("Document cannot be marked as finished. Annotation with ID [" + WebAnnoCasUtil.getAddr(fs) + "] on layer [" + layer.getUiName() + "] is missing value for feature [" + f.getUiName() + "].");
}
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class BratAnnotationEditor method getLayersToRender.
private List<AnnotationLayer> getLayersToRender() {
AnnotatorState state = getModelObject();
List<AnnotationLayer> layersToRender = new ArrayList<>();
for (AnnotationLayer layer : state.getAnnotationLayers()) {
boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName());
boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE) && (state.getMode().equals(Mode.AUTOMATION) || state.getMode().equals(Mode.CORRECTION) || state.getMode().equals(Mode.CURATION));
if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) {
layersToRender.add(layer);
}
}
return layersToRender;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class BratAnnotationEditor method actionDoAction.
private Object actionDoAction(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException {
StringValue layerParam = request.getParameterValue(PARAM_SPAN_TYPE);
if (!layerParam.isEmpty()) {
long layerId = Long.parseLong(layerParam.beforeFirst('_'));
AnnotationLayer layer = annotationService.getLayer(layerId);
if (!StringUtils.isEmpty(layer.getOnClickJavascriptAction())) {
// parse the action
List<AnnotationFeature> features = annotationService.listAnnotationFeature(layer);
AnnotationFS anno = WebAnnoCasUtil.selectByAddr(jCas, paramId.getId());
Map<String, Object> functionParams = OnClickActionParser.parse(layer, features, getModelObject().getDocument(), anno);
// define anonymous function, fill the body and immediately execute
String js = String.format("(function ($PARAM){ %s })(%s)", layer.getOnClickJavascriptAction(), JSONUtil.toJsonString(functionParams));
aTarget.appendJavaScript(js);
}
}
return null;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class OrthographyLayerInitializer method configure.
@Override
public void configure(Project aProject) throws IOException {
AnnotationLayer orthography = new AnnotationLayer(SofaChangeAnnotation.class.getName(), "Orthography Correction", SPAN_TYPE, aProject, true);
orthography.setAllowStacking(false);
orthography.setMultipleTokens(false);
orthography.setLockToTokenOffset(true);
annotationSchemaService.createLayer(orthography);
AnnotationFeature correction = new AnnotationFeature();
correction.setDescription("Correct this token using the specified operation.");
correction.setName("value");
correction.setType(CAS.TYPE_NAME_STRING);
correction.setProject(aProject);
correction.setUiName("Correction");
correction.setLayer(orthography);
annotationSchemaService.createFeature(correction);
TagSet operationTagset = annotationSchemaService.createTagSet("operation to be done with specified in tokenIDs token/tokens in order to correct", "Operation", "en", new String[] { "replace", "insert_before", "insert_after", "delete" }, new String[] { "replace", "insert before", "insert after", "delete" }, aProject);
AnnotationFeature operation = new AnnotationFeature();
operation.setDescription("An operation taken to change this token.");
operation.setName("operation");
operation.setType(CAS.TYPE_NAME_STRING);
operation.setProject(aProject);
operation.setUiName("Operation");
operation.setLayer(orthography);
operation.setVisible(false);
operation.setTagset(operationTagset);
annotationSchemaService.createFeature(operation);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class PartOfSpeechLayerInitializer method configure.
@Override
public void configure(Project aProject) throws IOException {
TagSet posTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/mul-pos-ud.json").getInputStream(), annotationSchemaService);
AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject);
AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, aProject, true);
AnnotationFeature tokenPosFeature = new AnnotationFeature(aProject, tokenLayer, "pos", "pos", POS.class.getName());
annotationSchemaService.createFeature(tokenPosFeature);
posLayer.setAttachType(tokenLayer);
posLayer.setAttachFeature(tokenPosFeature);
annotationSchemaService.createLayer(posLayer);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, posLayer, "PosValue", "PosValue", CAS.TYPE_NAME_STRING, "Part-of-speech tag", posTagSet));
}
Aggregations