使用 JAPE 或 Groovy 更改门文档中的特征名称

Change feature name in gate document with JAPE or Groovy

我有一个这样的 GATE 文档:

我需要更改注释中的特征名称。在这里,我需要将 type 更改为 category

是否可以使用 JAPE 规则或 Groovy 脚本来做到这一点?

是的,也是。 JAPE 规则可能是最简单的:

Phase: RenameFeature
Input: Mention
Options: control = all

Rule: Rename
({Mention}):mention
-->
:mention {
  for(Annotation a : mentionAnnots) {
    a.getFeatures().put("category", a.getFeatures().remove("type"));
    // note Map.remove returns the value we just removed
  }
}

在标有 :label 的 RHS Java 块内,变量 labelAnnots 是一个 AnnotationSet,其中包含与 LHS 上的标签匹配的注释。在这种情况下,只有其中一个,但 for 循环仍然是从集合中访问单个 Annotation 的最方便的方法。