I need to write a jape rule to annotate sentence and display the numbers in the sentence as features and tried the following rule
Imports: {import static gate.Utils.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern; }
Phase:Sentence
Input: Sentence Token
Options: control = appelt
Rule: SentenceNum
({Sentence}):temp
-->
{try{
AnnotationSet val = bindings.get("temp");
String strSent = doc.getContent().getContent(val.firstNode().getOffset(), val.lastNode().getOffset()).toString();
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher(strSent);
while(m.find()){
FeatureMap features = Factory.newFeatureMap();
String num = m.group();
features.put("number",num);
features.put("rule","Sentence");
outputAS.add(val.firstNode(),val.lastNode(),"Sentence",features);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
The sentence is not getting annotated fully its getting annotated only where numbers are present and also gets annotated as many times as the numbers. Can someone help me with this.
Got the answer guys
this jape rule will add the number annotation to the existing Sentence annotation This is how the output looks