GATE:gate.corpora.DocumentJsonUtils 的工作示例

GATE: A working example for gate.corpora.DocumentJsonUtils

我一直在努力了解如何在位于 gate.corpora.DocumentJsonUtils 的 GATE 中使用 JSON 导出器。有人可以提供一个工作示例吗?我不太确定在哪里可以找到或如何构建所有方法都需要的 Map<String,Collection<Annotation>> annotationsMap

这是为我解决问题的 "quick" 技巧。不知道他们为什么决定使用这种特定的数据结构。也不确定为什么这不是在内部作为默认选项完成的,因为它是从文档派生的。

¯\_(ツ)_/¯

  public static String makeJson(Document doc) {

    AnnotationSet as = doc.getAnnotations();

    Map<String, Collection<Annotation>> anns = new HashMap<>();

    anns.put("MyAnnotations", as.inDocumentOrder());

    try {
      return DocumentJsonUtils.toJson(doc, anns);
    } catch (IOException ex) {
      return "";
    }
  }