/** * Get the feature type for the given annotation feature. If the current feature support does * not provide any feature type for the given feature, an empty value is returned. As we * usually use {@link FeatureType} objects in feature type selection lists, this method is * helpful in obtaining the selected value of such a list from the {@link AnnotationFeature} * object being edited. * * @param aAnnotationFeature * an annotation feature. * @return the corresponding feature type. */ default Optional<FeatureType> getFeatureType(AnnotationFeature aAnnotationFeature) { return getSupportedFeatureTypes(aAnnotationFeature.getLayer()).stream() .filter(t -> t.getName().equals(aAnnotationFeature.getType())).findFirst(); }
public ExportedAnnotationFeatureReference(AnnotationFeature aFeature) { super(); name = aFeature.getName(); layer = aFeature.getLayer().getName(); }
/** * Get the feature type for the given annotation feature. If the current feature support does * not provide any feature type for the given feature, an empty value is returned. As we * usually use {@link FeatureType} objects in feature type selection lists, this method is * helpful in obtaining the selected value of such a list from the {@link AnnotationFeature} * object being edited. * * @param aAnnotationFeature * an annotation feature. * @return the corresponding feature type. */ default Optional<FeatureType> getFeatureType(AnnotationFeature aAnnotationFeature) { return getSupportedFeatureTypes(aAnnotationFeature.getLayer()).stream() .filter(t -> t.getName().equals(aAnnotationFeature.getType())).findFirst(); }
public static String createTemplate(AnnotationFeature aFeature, File templateFile, int aOther) throws IOException { StringBuffer sb = new StringBuffer(); if (aFeature == null) { setMorphoTemplate(sb, aOther); } else { switch (aFeature.getLayer().getAnchoringMode()) { case SINGLE_TOKEN: setMorphoTemplate(sb, aOther); break; case TOKENS: setNgramForLable(sb, aOther); break; default: throw new IllegalStateException("Unsupported anchoring mode: [" + aFeature.getLayer().getAnchoringMode() + "]"); } } sb.append("\n"); sb.append("B\n"); FileUtils.writeStringToFile(templateFile, sb.toString()); return templateFile.getAbsolutePath(); }
public static String createTemplate(AnnotationFeature aFeature, File templateFile, int aOther) throws IOException { StringBuffer sb = new StringBuffer(); if (aFeature == null) { setMorphoTemplate(sb, aOther); } else { switch (aFeature.getLayer().getAnchoringMode()) { case SINGLE_TOKEN: setMorphoTemplate(sb, aOther); break; case TOKENS: setNgramForLable(sb, aOther); break; default: throw new IllegalStateException("Unsupported anchoring mode: [" + aFeature.getLayer().getAnchoringMode() + "]"); } } sb.append("\n"); sb.append("B\n"); FileUtils.writeStringToFile(templateFile, sb.toString()); return templateFile.getAbsolutePath(); }
@Override protected void onConfigure() { super.onConfigure(); String layertype = FeatureDetailForm.this.getModelObject().getLayer().getType(); // Currently not configurable for chains or relations // TODO: technically it is possible setVisible(!CHAIN_TYPE.equals(layertype) && !RELATION_TYPE.equals(layertype)); }
@Override protected void onConfigure() { super.onConfigure(); String layertype = FeatureDetailForm.this.getModelObject().getLayer().getType(); // Currently not configurable for chains or relations // TODO: technically it is possible setVisible(!CHAIN_TYPE.equals(layertype) && !RELATION_TYPE.equals(layertype)); }
@Override public File getMiraModel(AnnotationFeature aFeature, boolean aOtherLayer, TrainingDocument aDocument) { if (aDocument != null) { return new File(getMiraDir(aFeature), aDocument.getId() + "- " + aDocument.getProject().getId() + "-model"); } else if (aOtherLayer) { return new File(getMiraDir(aFeature), aFeature.getId() + "-model"); } else { return new File(getMiraDir(aFeature), aFeature.getLayer().getId() + "-" + aFeature.getId() + "-model"); } }
@Override protected PairwiseAnnotationResult load() { AnnotationFeature feature = featureList.getModelObject(); // Do not do any agreement if no feature has been selected yet. if (feature == null) { return null; } Map<String, List<JCas>> casMap = getJCases(); Project project = projectSelectionForm.getModelObject().project; List<DiffAdapter> adapters = CasDiff2.getAdapters(annotationService, project); AgreementFormModel pref = AgreementForm.this.getModelObject(); DiffResult diff = CasDiff2.doDiff(asList(feature.getLayer().getName()), adapters, pref.linkCompareBehavior, casMap); return AgreementUtils.getPairwiseAgreement( AgreementForm.this.getModelObject().measure, pref.excludeIncomplete, diff, feature.getLayer().getName(), feature.getName(), casMap); } }));
@Override protected PairwiseAnnotationResult load() { AnnotationFeature feature = featureList.getModelObject(); // Do not do any agreement if no feature has been selected yet. if (feature == null) { return null; } Map<String, List<JCas>> casMap = getJCases(); Project project = projectSelectionForm.getModelObject().project; List<DiffAdapter> adapters = CasDiff2.getAdapters(annotationService, project); AgreementFormModel pref = AgreementForm.this.getModelObject(); DiffResult diff = CasDiff2.doDiff(asList(feature.getLayer().getName()), adapters, pref.linkCompareBehavior, casMap); return AgreementUtils.getPairwiseAgreement( AgreementForm.this.getModelObject().measure, pref.excludeIncomplete, diff, feature.getLayer().getName(), feature.getName(), casMap); } }));
@Override public void updateFeature(JCas aJcas, AnnotationFeature aFeature,int aAddress, String aValue) { Type type = CasUtil.getType(aJcas.getCas(), aFeature.getLayer().getName()+LINK); Feature feature = type.getFeatureByBaseName(aFeature.getName()); FeatureStructure fs = BratAjaxCasUtil.selectByAddr(aJcas, FeatureStructure.class, aAddress); fs.setFeatureValueFromString(feature, aValue); }
JCas jCas = aCorrectionDocumentService.readCorrectionCas(d); TypeAdapter adapter = aAnnotationService.getAdapter(aFeature.getLayer());
public static Map<Integer, String> getMultipleAnnotation( AnnotationSchemaService aAnnotationService, Sentence sentence, AnnotationFeature aFeature) throws CASException { SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aFeature.getLayer()); Map<Integer, String> multAnno = new HashMap<>(); Type type = getType(sentence.getCAS(), adapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(type, sentence)) { boolean isBegin = true; Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); for (Token token : selectCovered(Token.class, fs)) { if (multAnno.get(getAddr(token)) == null) { if (isBegin) { multAnno.put(getAddr(token), "B-" + fs.getFeatureValueAsString(labelFeature)); isBegin = false; } else { multAnno.put(getAddr(token), "I-" + fs.getFeatureValueAsString(labelFeature)); } } } } return multAnno; }
public static Map<Integer, String> getMultipleAnnotation( AnnotationSchemaService aAnnotationService, Sentence sentence, AnnotationFeature aFeature) throws CASException { SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aFeature.getLayer()); Map<Integer, String> multAnno = new HashMap<>(); Type type = getType(sentence.getCAS(), adapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(type, sentence)) { boolean isBegin = true; Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); for (Token token : selectCovered(Token.class, fs)) { if (multAnno.get(getAddr(token)) == null) { if (isBegin) { multAnno.put(getAddr(token), "B-" + fs.getFeatureValueAsString(labelFeature)); isBegin = false; } else { multAnno.put(getAddr(token), "I-" + fs.getFeatureValueAsString(labelFeature)); } } } } return multAnno; }
@Override public void configureFeature(AnnotationFeature aFeature) { // Set properties of link features since these are currently not configurable in the UI aFeature.setMode(MultiValueMode.ARRAY); aFeature.setLinkMode(LinkMode.WITH_ROLE); aFeature.setLinkTypeRoleFeatureName("role"); aFeature.setLinkTypeTargetFeatureName("target"); aFeature.setLinkTypeName(aFeature.getLayer().getName() + WordUtils.capitalize(aFeature.getName()) + "Link"); }
/** * Listens to the user setting a feature on an annotation in the main annotation editor. Mind * that we do not need to listen to the creation of annotations since they have no effect on * the active learning sidebar as long as they have no features set. */ @OnEvent public void onFeatureValueUpdated(FeatureValueUpdatedEvent aEvent) { AnnotatorState state = getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); // If the user creates a new annotation at the site of the suggestion that is currently // offered to the user, then the AL should move on to the next available suggestion if ( alState.isSessionActive() && (!alState.getSuggestion().isPresent() || ( aEvent.getUser().equals(state.getUser().getUsername()) && aEvent.getDocument().equals(state.getDocument()) && aEvent.getFeature().getLayer().equals(alState.getLayer()) && aEvent.getFeature().getName().equals(alState.getSuggestion().get().getFeature()))) ) { reactToAnnotationsBeingCreatedOrDeleted(aEvent.getRequestTarget(), aEvent.getFeature().getLayer()); } }
@Override public void configureFeature(AnnotationFeature aFeature) { // Set properties of link features since these are currently not configurable in the UI aFeature.setMode(MultiValueMode.ARRAY); aFeature.setLinkMode(LinkMode.WITH_ROLE); aFeature.setLinkTypeRoleFeatureName("role"); aFeature.setLinkTypeTargetFeatureName("target"); aFeature.setLinkTypeName(aFeature.getLayer().getName() + WordUtils.capitalize(aFeature.getName()) + "Link"); }
/** * Listens to the user setting a feature on an annotation in the main annotation editor. Mind * that we do not need to listen to the creation of annotations since they have no effect on * the active learning sidebar as long as they have no features set. */ @OnEvent public void onFeatureValueUpdated(FeatureValueUpdatedEvent aEvent) { AnnotatorState state = getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); // If the user creates a new annotation at the site of the suggestion that is currently // offered to the user, then the AL should move on to the next available suggestion if ( alState.isSessionActive() && (!alState.getSuggestion().isPresent() || ( aEvent.getUser().equals(state.getUser().getUsername()) && aEvent.getDocument().equals(state.getDocument()) && aEvent.getFeature().getLayer().equals(alState.getLayer()) && aEvent.getFeature().getName().equals(alState.getSuggestion().get().getFeature()))) ) { reactToAnnotationsBeingCreatedOrDeleted(aEvent.getRequestTarget(), aEvent.getFeature().getLayer()); } }
@Override public String getDetails(RecommendationRejectedEvent aEvent) { try { AnnotationDetails annotation = new AnnotationDetails(); annotation.setBegin(aEvent.getBegin()); annotation.setEnd(aEvent.getEnd()); annotation.setText(aEvent.getText()); annotation.setType(aEvent.getFeature().getLayer().getName()); FeatureChangeDetails details = new FeatureChangeDetails(); details.setAnnotation(annotation); details.setValue(aEvent.getRecommendedValue()); return JSONUtil.toJsonString(details); } catch (IOException e) { log.error("Unable to log event [{}]", aEvent, e); return "<ERROR>"; } } }
public static void setFeature(AnnotationService aAnnotationService, AnnotationFeature aFeature, de.tudarmstadt.ukp.clarin.webanno.model.export.AnnotationFeature aExFeature, Project aProject, User aUser) { aFeature.setDescription(aExFeature.getDescription()); aFeature.setEnabled(aExFeature.isEnabled()); aFeature.setVisible(aExFeature.isVisible()); aFeature.setUiName(aExFeature.getUiName()); aFeature.setProject(aProject); aFeature.setLayer(aFeature.getLayer()); aFeature.setType(aExFeature.getType()); aFeature.setName(aExFeature.getName()); aAnnotationService.createFeature(aFeature); }