【问题标题】:Read annotated data from GATE datastore从 GATE 数据存储中读取带注释的数据
【发布时间】:2013-11-09 18:34:25
【问题描述】:

我使用 GATE 通过其包含的情感手动注释大量文本。为了进一步处理这个文本,我喜欢将它从数据存储中导出到我自己的 Java 应用程序中。我没有找到有关如何执行此操作的文档。我已经编写了一个将数据导入数据存储区的程序,但我不知道如何将注释从数据存储区中取出。我还尝试使用 Luke (https://code.google.com/p/luke/) 打开基于 lucene 的数据存储。它是一个能够读取 Lucene 索引的工具。但是无法使用该工具打开 Gate Lucene 数据存储 :( 有没有人知道如何从数据存储中读取带注释的文本?

【问题讨论】:

    标签: java gate


    【解决方案1】:

    您可以使用 GATE API 从数据存储中加载文档,然后以正常方式将它们导出为 GATE XML(省略导入和异常处理):

    Gate.init();
    DataStore ds = Factory.openDataStore("gate.creole.annic.SearchableDataStore", "file:/path/to/datastore");
    List docIds = ds.getLrIds("gate.corpora.DocumentImpl");
    for(Object id : docIds) {
      Document d = (Document)Factory.createResource("gate.corpora.DocumentImpl",
                gate.Utils.featureMap(DataStore.DATASTORE_FEATURE_NAME, ds,
                                      DataStore.LR_ID_FEATURE_NAME, id));
      try {
        File outputFile = new File(...); // based on doc name, sequential number, etc.
        DocumentStaxUtils.writeDocument(d, outputFile);
      } finally {
        Factory.deleteResource(d);
      }
    }
    

    如果您想将注释编写为内联 XML,请将 DocumentStaxUtils.writeDocument 替换为类似

    Set<String> types = new HashSet<String>();
    types.add("Person");
    types.add("Location"); // and whatever others you're interested in
    FileUtils.write(outputFile, d.toXml(d.getAnnotations().get(types), true));
    

    (为方便起见,我使用FileUtils from Apache commons-io,但您同样可以自己处理打开和关闭文件)。

    【讨论】:

    • 酷!感谢您的快速答复。我不得不将 gate.creole.annic.SearchableDataStore 更改为 gate.persist.LuceneDataStoreImpl,但这取决于之前如何保存数据存储
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    相关资源
    最近更新 更多