Commit 0b750fb6 authored by Javi Corvi's avatar Javi Corvi
Browse files

add rule to detect related entity with intermediate POS to the right

parent 5e2ba496
Pipeline #26600 passed with stage
in 1 minute and 52 seconds
......@@ -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()<token_between_closest) {
closest = annotation_type;
token_between_closest = token_between.size();
}
}
}
}
return closest;
}
/**
* Return try if the list of token has a POS
* @param token_between
* @param pOS
* @return
*/
private static boolean tokensIncludePOS(AnnotationSet token_between, String POS) {
if(POS==null || POS.contentEquals("")) {
return false;
}else {
for (Annotation annotation : token_between) {
if(annotation.getFeatures().get("pos").toString().startsWith(POS)) {
return true;
}
}
}
return false;
}
/**
*
* @param token_between
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment