2

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

4

1 回答 1

2

您可以使用 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));

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

于 2013-10-30T10:52:04.537 回答