从GATE数据存储区读取带注释的数据

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

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

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 types = new HashSet(); 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 ,但你可以自己处理打开和关闭文件)。