} else if (CAS.TYPE_NAME_INTEGER.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setIntValue(mStructureFeature, number.intValue()); } else if (CAS.TYPE_NAME_LONG.equals(mStructureFeature.getRange() .getName())) {
multiAnnoFs.setIntValue(endF, aEnd); setAnnoRefPerUnit(aUnit, aType, aRef, multiAnnoFs);
multiAnnoFs.setIntValue(endF, aEnd); setAnnoRefPerUnit(aUnit, aType, aRef, multiAnnoFs);
multiAnnoFs.setIntValue(endF, aEnd); setAnnoRefPerUnit(aUnit, aType, aRef, multiAnnoFs);
@Nullable AnnotationFS getAnnotation(CAS cas, int begin, int end, int value) { if (begin < 0) { throw new IllegalArgumentException("Begin: " + begin + "before 0."); } if (end < begin) { throw new IllegalArgumentException( annotationClassName + " - illegal annotation span at begin: " + begin + " end: " + end); } if (!zeroLengthEmitted && end == begin) { return null; } TypeSystem typeSystem = cas.getTypeSystem(); Type type = typeSystem.getType(annotationClassName); if (type == null) { throw new IllegalStateException("Annotation class not found: " + annotationClassName); } AnnotationFS annotation = cas.createAnnotation(type, begin, end); if (valueIncluded) { Feature valueFeature = type.getFeatureByBaseName("value"); annotation.setIntValue(valueFeature, value); } return annotation; }
sofaBuilder.length() ); annotation.setIntValue(valueFeat, (int) ch); completedAnnotations.add(annotation); } else {
private void setFeatureValue(AnnotationFS annotationFS, Feature feature, Object o) { if (feature != null && o != null) { Type range = feature.getRange(); String rangeName = range.getName(); if (rangeName.equals(CAS.TYPE_NAME_STRING) && o instanceof String) { annotationFS.setStringValue(feature, (String) o); } else if (rangeName.equals(CAS.TYPE_NAME_INTEGER) && o instanceof Number) { annotationFS.setIntValue(feature, ((Number) o).intValue()); } else if (rangeName.equals(CAS.TYPE_NAME_DOUBLE) && o instanceof Number) { annotationFS.setDoubleValue(feature, ((Number) o).doubleValue()); } else if (rangeName.equals(CAS.TYPE_NAME_FLOAT) && o instanceof Number) { annotationFS.setFloatValue(feature, ((Number) o).floatValue()); } else if (rangeName.equals(CAS.TYPE_NAME_BYTE) && o instanceof Number) { annotationFS.setByteValue(feature, ((Number) o).byteValue()); } else if (rangeName.equals(CAS.TYPE_NAME_SHORT) && o instanceof Number) { annotationFS.setShortValue(feature, ((Number) o).shortValue()); } else if (rangeName.equals(CAS.TYPE_NAME_LONG) && o instanceof Number) { annotationFS.setLongValue(feature, ((Number) o).longValue()); } else if (rangeName.equals(CAS.TYPE_NAME_BOOLEAN) && o instanceof Boolean) { annotationFS.setBooleanValue(feature, (Boolean) o); } else if (rangeName.equals(CAS.TYPE_NAME_STRING) & o instanceof Type) { annotationFS.setStringValue(feature, ((Type) o).getName()); } } else { throw new IllegalArgumentException("Not able to assign feature value: " + o + " -> " + feature); } }
@Override public void visitEndTag(Tag tag) { String name = getName(tag); AnnotationFS found = null; for (int i = annotationStack.size() - 1; i >= 0; i--) { AnnotationFS each = annotationStack.get(i); Feature nameFeature = each.getType().getFeatureByBaseName("name"); String eachName = each.getStringValue(nameFeature); if (name.equals(eachName)) { int endOffset = getEndOffset(tag); Feature endFeature = each.getType().getFeatureByBaseName("end"); each.setIntValue(endFeature, endOffset); found = each; break; } } if (found != null) { annotationStack.remove(found); annotations.add(found); } }
public void visitEndTag(Tag tag) { String name = getName(tag); AnnotationFS found = null; for (int i = annotationStack.size() - 1; i >= 0; i--) { AnnotationFS each = (AnnotationFS) annotationStack.get(i); // // Java 6: // Iterator<AnnotationFS> descendingIterator = annotationStack.descendingIterator(); // while (descendingIterator.hasNext()) { // AnnotationFS each = (AnnotationFS) descendingIterator.next(); Feature nameFeature = each.getType().getFeatureByBaseName("name"); String eachName = each.getStringValue(nameFeature); if (name.equals(eachName)) { int endOffset = getEndOffset(tag); Feature endFeature = each.getType().getFeatureByBaseName("end"); each.setIntValue(endFeature, endOffset); found = each; break; } } if (found != null) { annotationStack.remove(found); annotations.add(found); } }
@Override public void controlWordEncountered(KeywordAction keywordAction) { AnnotationFS annotation; int currentTextIndex = sofaBuilder.length(); String controlWord = keywordAction.getControlWord(); Type type; if (annotationTypeForControlWord.containsKey(controlWord)) { type = annotationTypeForControlWord.get(controlWord); } else { return; } annotation = destinationView.createAnnotation(type, currentTextIndex, currentTextIndex); Feature paramFeature = type.getFeatureByBaseName("param"); if (keywordAction.hasParameter()) { annotation.setIntValue(paramFeature, keywordAction.getParameter()); } Feature indexFeature = type.getFeatureByBaseName("index"); annotation.setIntValue(indexFeature, keywordAction.getBegin()); Feature knownFeature = type.getFeatureByBaseName("known"); annotation.setBooleanValue(knownFeature, true); destinationView.addFsToIndexes(annotation); }
@Override public void wroteToDestination(String destinationName, int destinationIndex, TextRange originalDocumentTextLocation) { AnnotationFS viewIndex = originalDocumentView .createAnnotation(viewIndexType, originalDocumentTextLocation.getStartIndex(), originalDocumentTextLocation.getEndIndex()); viewIndex.setStringValue(destinationNameFeature, destinationName); viewIndex.setIntValue(destinationIndexFeature, destinationIndex); originalDocumentView.addFsToIndexes(viewIndex); } }
/** * Wide right annotation side. * * @param document the document * @param annotation the annotation */ public static void wideRightAnnotationSide(ICasDocument document, AnnotationFS annotation) { Type annotationType = annotation.getType(); Feature endFeature = annotationType.getFeatureByBaseName("end"); if (annotation.getEnd() < document.getCAS().getDocumentText().length()) { annotation.setIntValue(endFeature, annotation.getEnd() + 1); } document.update(annotation); }
/** * Widens the annotation and sends and sends an update notification * to the provided document. * * @param document the document * @param annotation the annotation */ public static void wideLeftAnnotationSide(ICasDocument document, AnnotationFS annotation) { Type annotationType = annotation.getType(); Feature beginFeature = annotationType.getFeatureByBaseName("begin"); if (annotation.getBegin() > 0) { annotation.setIntValue(beginFeature, annotation.getBegin() - 1); } document.update(annotation); }
/** * Lower left annotation side. * * @param document the document * @param annotation the annotation */ public static void lowerLeftAnnotationSide(ICasDocument document, AnnotationFS annotation) { Type annotationType = annotation.getType(); Feature beginFeature = annotationType.getFeatureByBaseName("begin"); if (annotation.getBegin() < annotation.getEnd()) { annotation.setIntValue(beginFeature, annotation.getBegin() + 1); } document.update(annotation); }
/** * Lower right annotation side. * * @param document the document * @param annotation the annotation */ public static void lowerRightAnnotationSide(ICasDocument document, AnnotationFS annotation) { Type annotationType = annotation.getType(); Feature endFeature = annotationType.getFeatureByBaseName("end"); if (annotation.getBegin() < annotation.getEnd()) { annotation.setIntValue(endFeature, annotation.getEnd() - 1); } document.update(annotation); }
case WIDE_L: if (fs.getBegin() > 0) { fs.setIntValue(beginFeature, fs.getBegin() - 1); fs.setIntValue(beginFeature, fs.getBegin() + 1); fs.setIntValue(endFeature, fs.getEnd() - 1); fs.setIntValue(endFeature, fs.getEnd() + 1);
uRelation.setIntValue(beginFeature, uRelationBegin); uRelation.setIntValue(endFeature, uRelationEnd); AnnotationFS uEvent = mapStructureRoles(bEvent, evMapping); uEvent.setIntValue(beginFeature, bTrigger.getBegin()); uEvent.setIntValue(endFeature, bTrigger.getEnd());
} else if (CAS.TYPE_NAME_INTEGER.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setIntValue(mStructureFeature, number.intValue()); } else if (CAS.TYPE_NAME_LONG.equals(mStructureFeature.getRange() .getName())) {
if (range.equals(UIMAConstants.TYPE_INTEGER)) { int v = numberExpr.getIntegerValue(element.getParent()); annotationFS.setIntValue(featureByBaseName, v); } else if (range.equals(UIMAConstants.TYPE_DOUBLE)) { double v = numberExpr.getDoubleValue(element.getParent());
annot.setFloatValue(updateFeatures[f].getFeature(), Float.parseFloat(featureValue)); } else if (type == Feature.INTEGER_FEATURE) { annot.setIntValue(updateFeatures[f].getFeature(), Integer.parseInt(featureValue)); } else if (type == Feature.STRING_FEATURE) { annot.setStringValue(updateFeatures[f].getFeature(), featureValue);