Copy versions

Find an annotation of one type and copy modified versions of its features to all contained annotations of a specified type.

Rule: ArticleMention

   /* Get the Article annotations and its span (to use for start and end points) */
   AnnotationSet span    = (gate.AnnotationSet) bindings.get("article");
   Annotation  article   = span.iterator().next();

   /* Get all the contained Mention annotations */
   AnnotationSet mentions = inputAS.getContained(span.firstNode().getOffset(), 
   Iterator<Annotation>  mentionIter = mentions.iterator();

   FeatureMap articleFeatures  = article.getFeatures();
   Set        articleFKeys     = articleFeatures.keySet();
   Annotation mention;
   FeatureMap mentionFeatures, additionalFeatures;
   Iterator   keyIter;
   Object     key, value;
   String     mKey;

   /* Produce a modified FeatureMap from that of the Article */
   additionalFeatures  = gate.Factory.newFeatureMap();
   keyIter             = articleFKeys.iterator();
   while(keyIter.hasNext()) {
       key =;

       /* ignore non-String keys; we don't expect them and wouldn't know
          what to do with them */
       if (key instanceof String) {
          value = articleFeatures.get(key);
          mKey     = "article_" + ((String) key);
          additionalFeatures.put(mKey, value);

   /* Iterate through the Mentions and copy modified versions of the Article's features
      into each Mention's feature map */
   while (mentionIter.hasNext()) {
      mention          =;
      mentionFeatures  = mention.getFeatures();
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License