/** * Get the CAS type of the this {@link TypeAdapter} * * @return the type. */ default public String getAnnotationTypeName() { return getLayer().getName(); }
default long getTypeId() { return getLayer().getId(); }
/** * Get the CAS type of the this {@link TypeAdapter} * * @return the type. */ default public String getAnnotationTypeName() { return getLayer().getName(); }
default long getTypeId() { return getLayer().getId(); }
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VSpan> annoToSpanIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } // Since we split spans into multiple ranges at sentence boundaries, we can simply check // if there are multiple ranges for a given span. This is cheaper than checking for // every annotation whether the begin/end offset is in the same sentence. for (Entry<AnnotationFS, VSpan> e : annoToSpanIdx.entrySet()) { if (e.getValue().getRanges().size() > 1) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } }
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VSpan> annoToSpanIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } // Since we split spans into multiple ranges at sentence boundaries, we can simply check // if there are multiple ranges for a given span. This is cheaper than checking for // every annotation whether the begin/end offset is in the same sentence. for (Entry<AnnotationFS, VSpan> e : annoToSpanIdx.entrySet()) { if (e.getValue().getRanges().size() > 1) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } }
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isCrossSentence()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); for (AnnotationFS fs : select(cas, type)) { if (!isBeginEndInSameSentence(aJCas, fs.getBegin(), fs.getEnd())) { messages.add(Pair.of( LogMessage.error(this, "Crossing sentence bounardies is not permitted."), fs)); } } return messages; } }
default Map<String, String> getHoverFeatures(TypeAdapter aAdapter, AnnotationFS aFs, List<AnnotationFeature> aFeatures) { FeatureSupportRegistry fsr = getFeatureSupportRegistry(); Map<String, String> hoverfeatures = new LinkedHashMap<>(); if (aAdapter.getLayer().isShowTextInHover()) { hoverfeatures.put("__spantext__", aFs.getCoveredText()); } for (AnnotationFeature feature : aFeatures) { if (!feature.isEnabled() || !feature.isIncludeInHover() || !MultiValueMode.NONE.equals(feature.getMultiValueMode())) { continue; } String text = defaultString( fsr.getFeatureSupport(feature).renderFeatureValue(feature, aFs)); hoverfeatures.put(feature.getName(), text); } return hoverfeatures; }
default Map<String, String> getHoverFeatures(TypeAdapter aAdapter, AnnotationFS aFs, List<AnnotationFeature> aFeatures) { FeatureSupportRegistry fsr = getFeatureSupportRegistry(); Map<String, String> hoverfeatures = new LinkedHashMap<>(); if (aAdapter.getLayer().isShowTextInHover()) { hoverfeatures.put("__spantext__", aFs.getCoveredText()); } for (AnnotationFeature feature : aFeatures) { if (!feature.isEnabled() || !feature.isIncludeInHover() || !MultiValueMode.NONE.equals(feature.getMultiValueMode())) { continue; } String text = defaultString( fsr.getFeatureSupport(feature).renderFeatureValue(feature, aFs)); hoverfeatures.put(feature.getName(), text); } return hoverfeatures; }
public static void addArcAnnotation(TypeAdapter aAdapter, JCas aJcas, int aAddressOriginClicked, int aAddressTargetClicked, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException { AnnotationFS originFsClicked = selectByAddr(aClickedJCas, aAddressOriginClicked); AnnotationFS targetFsClicked = selectByAddr(aClickedJCas, aAddressTargetClicked); // this is a slot arc if (aFSArcaddress.contains(".")) { addSlotArcAnnotation((SpanAdapter) aAdapter, aJcas, aFSArcaddress, aClickedJCas, aClickedFS); } // normal relation annotation arc is clicked else { AnnotationLayer layer = aAdapter.getLayer(); addRelationArcAnnotation(aJcas, aClickedFS, layer.getAttachType() != null, layer.isAllowStacking(), originFsClicked, targetFsClicked); } }
public static void addArcAnnotation(TypeAdapter aAdapter, JCas aJcas, int aAddressOriginClicked, int aAddressTargetClicked, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException { AnnotationFS originFsClicked = selectByAddr(aClickedJCas, aAddressOriginClicked); AnnotationFS targetFsClicked = selectByAddr(aClickedJCas, aAddressTargetClicked); // this is a slot arc if (aFSArcaddress.contains(".")) { addSlotArcAnnotation((SpanAdapter) aAdapter, aJcas, aFSArcaddress, aClickedJCas, aClickedFS); } // normal relation annotation arc is clicked else { AnnotationLayer layer = aAdapter.getLayer(); addRelationArcAnnotation(aJcas, aClickedFS, layer.getAttachType() != null, layer.isAllowStacking(), originFsClicked, targetFsClicked); } }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aRequest.getBegin() == aRequest.getEnd()) { if (!aAdapter.getLayer().getAnchoringMode().isZeroSpanAllowed()) { throw new AnnotationException( "Cannot create zero-width annotation on layers that lock to token boundaries."); } return aRequest; } int[] originalRange = new int[] { aRequest.getBegin(), aRequest.getEnd() }; int[] adjustedRange = adjust(aRequest.getJcas(), aAdapter.getLayer().getAnchoringMode(), originalRange); if (adjustedRange.equals(originalRange)) { return aRequest; } else { return aRequest.changeSpan(adjustedRange[0], adjustedRange[1]); } }
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VArc> aAnnoToArcIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } try { for (Entry<AnnotationFS, VArc> e : aAnnoToArcIdx.entrySet()) { JCas jcas = e.getKey().getCAS().getJCas(); if (!isBeginInSameSentence(jcas, selectByAddr(jcas, e.getValue().getSource().getId()).getBegin(), selectByAddr(jcas, e.getValue().getTarget().getId()).getBegin())) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } } catch (CASException e) { throw new IllegalStateException("Unable to obtain JCas"); } }
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isAllowStacking()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); AnnotationFS prevFS = null; List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); // Since the annotations are sorted, we can easily find stacked annotation by scanning // through the entire list and checking if two adjacent annotations have the same offsets for (AnnotationFS fs : select(cas, type)) { if (prevFS != null && prevFS.getBegin() == fs.getBegin() && prevFS.getEnd() == fs.getEnd()) { messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)); } prevFS = fs; } return messages; } }
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isAllowStacking()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); AnnotationFS prevFS = null; List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); // Since the annotations are sorted, we can easily find stacked annotation by scanning // through the entire list and checking if two adjacent annotations have the same offsets for (AnnotationFS fs : select(cas, type)) { if (prevFS != null && prevFS.getBegin() == fs.getBegin() && prevFS.getEnd() == fs.getEnd()) { messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)); } prevFS = fs; } return messages; } }
@Override public void onRender(TypeAdapter aAdapter, VDocument aResponse, Map<AnnotationFS, VArc> aAnnoToArcIdx) { if (aAdapter.getLayer().isCrossSentence()) { return; } try { for (Entry<AnnotationFS, VArc> e : aAnnoToArcIdx.entrySet()) { JCas jcas = e.getKey().getCAS().getJCas(); if (!isBeginInSameSentence(jcas, selectByAddr(jcas, e.getValue().getSource().getId()).getBegin(), selectByAddr(jcas, e.getValue().getTarget().getId()).getBegin())) { aResponse.add(new VComment(new VID(e.getKey()), ERROR, "Crossing sentence bounardies is not permitted.")); } } } catch (CASException e) { throw new IllegalStateException("Unable to obtain JCas"); } }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isCrossSentence()) { return aRequest; } if (!isBeginEndInSameSentence(aRequest.getJcas(), aRequest.getBegin(), aRequest.getEnd())) { throw new MultipleSentenceCoveredException("Annotation covers multiple sentences, " + "limit your annotation to single sentence!"); } return aRequest; }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isCrossSentence()) { return aRequest; } if (!isBeginEndInSameSentence(aRequest.getJcas(), aRequest.getBegin(), aRequest.getEnd())) { throw new MultipleSentenceCoveredException("Annotation covers multiple sentences, " + "limit your annotation to single sentence!"); } return aRequest; }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isAllowStacking()) { return aRequest; } final CAS aCas = aRequest.getJcas().getCas(); final int aBegin = aRequest.getBegin(); final int aEnd = aRequest.getEnd(); // If stacking is not allowed and there already is an annotation, then return the address // of the existing annotation. Type type = getType(aCas, aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(aCas, type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { throw new AnnotationException("Cannot create another annotation of layer [" + aAdapter.getLayer().getUiName() + "] at this location - stacking is not " + "enabled for this layer."); } } return aRequest; }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isAllowStacking()) { return aRequest; } final CAS aCas = aRequest.getJcas().getCas(); final int aBegin = aRequest.getBegin(); final int aEnd = aRequest.getEnd(); // If stacking is not allowed and there already is an annotation, then return the address // of the existing annotation. Type type = getType(aCas, aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(aCas, type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { throw new AnnotationException("Cannot create another annotation of layer [" + aAdapter.getLayer().getUiName() + "] at this location - stacking is not " + "enabled for this layer."); } } return aRequest; }