From 0b750fb6f64625d7ef5187c5661fd25442b9b7c5 Mon Sep 17 00:00:00 2001 From: Javi Corvi Date: Wed, 29 Dec 2021 14:26:04 +0100 Subject: [PATCH] add rule to detect related entity with intermediate POS to the right --- .../component/util/AnnotationUtil.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/main/java/es/bsc/inb/nlp/gate/generic/component/util/AnnotationUtil.java b/src/main/java/es/bsc/inb/nlp/gate/generic/component/util/AnnotationUtil.java index f4579cf..53d39ca 100644 --- a/src/main/java/es/bsc/inb/nlp/gate/generic/component/util/AnnotationUtil.java +++ b/src/main/java/es/bsc/inb/nlp/gate/generic/component/util/AnnotationUtil.java @@ -88,6 +88,58 @@ public class AnnotationUtil { return closest; } + /** + * Return the closes entity with an intermediate POS. This rule apply to the right of the mayor entity. + * @param doc + * @param fields + * @param finding + * @param type + * @param left_limit + * @param right_limit + * @param avoid_token_between + * @return + */ + public static Annotation getClosestAnnotationWithPOSPriorityRight(AnnotationSet fields, Annotation finding, String type, Integer right_limit, String avoid_token_between, String POS) { + AnnotationSet annotations_type = fields.get(type); + Annotation closest = null; + Integer token_between_closest = 10000; + for (Annotation annotation_type : annotations_type) { + AnnotationSet token_between = null; + if (annotation_type.getStartNode().getOffset() > finding.getEndNode().getOffset()) { + //after the finding + token_between = fields.get("Token", finding.getEndNode().getOffset(), annotation_type.getStartNode().getOffset()); + if(token_between.size()<=right_limit && tokensIncludePOS(token_between, POS)) { + //review closest of rule + if(token_between!=null && token_between.size()