0

I am trying to add a list of all contained "all_tags" annotations as a feature of a new annotation using Java RHS rule.

Below only adds one annotation rather than all of them in a list:

AnnotationSet contTagAS = getContainedAnnotations(inputAS,spanAs).get("all_tags");

for (Annotation tagAnn : contTagAS.inDocumentOrder())
{
  FeatureMap lookupFeatures  = tagAnn.getFeatures();
  tag = lookupFeatures.get("type").toString();  
}

I want each all_tags "type" to be added as features separated by commmas, i.e "type 1, type 2, type 3"

I have tried List Annotation classes but cannot find the right method.

Many thanks

dedek
  • 7,981
  • 3
  • 38
  • 68
FJ1993
  • 115
  • 1
  • 8

1 Answers1

1
AnnotationSet contTagAS = getContainedAnnotations(inputAS,spanAs).get("all_tags");

StringJoiner joiner = new StringJoiner(",");

for (Annotation tagAnn : contTagAS.inDocumentOrder())
{
  FeatureMap lookupFeatures  = tagAnn.getFeatures();
  String tag = lookupFeatures.get("type").toString();
  joiner.add(tag);
}

outputAS.add(
    spanAs.firstNode(), 
    spanAs.lastNode(), 
    "new annotation", 
    featureMap("tags", joiner.toString())
);
dedek
  • 7,981
  • 3
  • 38
  • 68