我们可以在GATE中对Annotations进行分组吗?

时间:2014-01-06 14:51:42

标签: java text-mining gate

如何在两个注释之间对所有注释进行分组?

我是GATE的新手,我正在尝试将注释组合在一起,不确定我们是否可以这样做,请帮忙。 例如在以下文本中:

Page-1
Age:53 
Person: Nathan

Page-2
Treatment : Initial Evaluation
History: Yes

Page-3
..........

如果我的地名词典列表包含不同的标签,每个页码,年龄,人物,治疗,历史等的页面标签。我想将Page-1 Annotation下的Page-1到Page-2的所有标签和所有标签分组介于第2页的Page-2和Page-3之间。

如果有关此问题的更多信息,请与我们联系。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我并不完全确定“组合在一起”的含义,但您当然可以创建跨越每个“页面”内容的注释。假设您在每个“Page-1”,“Page-2”等上都有PageNumber注释,那么您可以使用类似的内容创建从PageNumber到下一个control = once的注释。我使用Imports: { import static gate.Utils.*; } Phase: PageSpans Input: PageNumber Options: control = once Rule: PageSpan ({PageNumber}) --> { try { List<Annotation> numbers = inDocumentOrder(inputAS.get("PageNumber")); for(int i = 0; i < numbers.size(); i++) { outputAS.add(start(numbers.get(i)), // from start of this PageNumber, to... (i+1 < numbers.size() ? start(numbers.get(i+1)) // start of the next number, or... : end(doc) // ...if no more PageNumbers then end of document ), "Page", // store the text under the PageNumber as a feature of Page featureMap("id", stringFor(doc, numbers.get(i)))); } } catch(InvalidOffsetException e) { throw new JapeException("Invalid offset from existing annotation", e); } } JAPE来执行此操作,您可以等效地使用Groovy脚本或自定义PR

Page

在评论中,您要求将每个“页面”下的所有注释移动到单独的注释集中。一旦完成上述操作,这将是相对简单的,如果您在Imports: { import static gate.Utils.*; } Phase: SetPerPage Input: Age X Y // and whatever other annotation types you want to copy Options: control = all Rule: MoveToPageSet ({Age}|{X}|{Y}):entity --> :entity { try { for(Annotation e : entityAnnots) { // find the (only) Page annotation that covers this entity Annotation thePage = getOnlyAnn(getCoveringAnnotations(inputAS, e, "Page")); // get the corresponding annotation set AnnotationSet pageSet = doc.getAnnotations( (String)thePage.getFeatures().get("id")); // and copy the annotation into it pageSet.add(start(e), end(e), e.getType(), e.getFeatures()); } } catch(InvalidOffsetException e) { throw new JapeException("Invalid offset from existing annotation", e); } // optionally remove from input set // inputAS.removeAll(entityAnnots); } 注释中将页码作为功能,就像我使用“id”功能一样。然后你可以定义另一个做这样的JAPE:

{{1}}
相关问题