Commit feb4664c authored by Javi Corvi's avatar Javi Corvi
Browse files

Annotation Util Methods

parent 6639e48c
Pipeline #26211 passed with stage
in 1 minute and 44 seconds
......@@ -11,8 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencies>
......
package es.bsc.inb.nlp.gate.generic.component.util;
import gate.Annotation;
import gate.AnnotationSet;
/**
*
* @author javi
*
*/
public class AnnotationUtil {
public static Integer right_limit = 50;
public static Integer left_limit = 50;
public static String example() {
return "llegue";
}
/**
*
* @param doc
* @param fields
* @param finding
* @param type
* @param left_limit
* @param right_limit
* @param avoid_token_between
* @return
*/
public static Annotation getClosestAnnotation(AnnotationSet fields, Annotation finding, String type, Integer left_limit, Integer right_limit, String avoid_token_between) {
//AnnotationSet treatment_related_triggers = fields.get(type, sentence.getStartNode().getOffset(), sentence.getEndNode().getOffset());
AnnotationSet annotations_type = fields.get(type);
Annotation closest = null;
Integer token_between_closest = 10000;
Boolean beforeFinding = false;
for (Annotation annotation_type : annotations_type) {
//System.out.println(type + ": " + gate.Utils.stringFor(doc, annotation_type));
//si el finding esta despues del trigger
AnnotationSet token_between = null;
if (finding.getStartNode().getOffset() > annotation_type.getEndNode().getOffset()) {
//before the finding
token_between = fields.get("Token", annotation_type.getEndNode().getOffset(), finding.getStartNode().getOffset());
if(token_between.size()<=left_limit) {
beforeFinding = true;
}else {
token_between = null;
}
}else 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) {
token_between = null;
}
}else {
closest = annotation_type;
token_between_closest = 0;
}
//if token do not contain in the middle specific tokens and the quantity of tokens is less than the closest one or are the same quantity but the closest one is not from the left side ....
if(token_between!=null && tokensDoNotContain(token_between, avoid_token_between) && ((token_between.size()<token_between_closest) || token_between.size()==token_between_closest && !beforeFinding)) {
closest = annotation_type;
token_between_closest = token_between.size();
}
}
return closest;
}
/**
*
* @param token_between
* @param avoid_token_between
* @return
*/
private static boolean tokensDoNotContain(AnnotationSet token_between, String avoid_token_between) {
if(avoid_token_between==null || avoid_token_between.contentEquals("")) {
return true;
}else {
for (Annotation annotation : token_between) {
if(annotation.getFeatures().get("word").equals(avoid_token_between)) {
return false;
}
}
}
return true;
}
}
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