Jape Rule 注释句子并将句子中的数字显示为特征
Jape Rule to annotate sentence and show the numbers in the sentence as feature
我需要编写一个 jape 规则来注释句子并将句子中的数字显示为特征并尝试了以下规则
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();
}
}
句子没有得到完整的注释,它只在数字出现的地方得到注释,并且注释的次数与数字一样多。
有人可以帮我解决这个问题吗?
得到答案伙计们
Imports: {import gate.Utils;}
Phase:Sentence
Input: Token
Options: control = appelt
Rule: Number
(
{Token.category ==~ CD}
):num
-->
:num.Number = {Number = :num.Token.string}
Phase:Sentence
Input: Sentence
Options: control = appelt
Rule: GetNumber
({Sentence}):tag
-->
{
Annotation numSent = Utils.getOnlyAnn(bindings.get("tag"));
List<Annotation> val = Utils.inDocumentOrder(Utils.getContainedAnnotations(inputAS, numSent, "Number"));
List<String> str = new ArrayList<String>(val.size());
for(Annotation a : val) {
str.add((String)a.getFeatures().get("Number"));
}
numSent.getFeatures().put("Number", str);
}
此 jape 规则会将数字注释添加到现有的 Sentence 注释中
This is how the output looks
我需要编写一个 jape 规则来注释句子并将句子中的数字显示为特征并尝试了以下规则
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();
}
}
句子没有得到完整的注释,它只在数字出现的地方得到注释,并且注释的次数与数字一样多。 有人可以帮我解决这个问题吗?
得到答案伙计们
Imports: {import gate.Utils;}
Phase:Sentence
Input: Token
Options: control = appelt
Rule: Number
(
{Token.category ==~ CD}
):num
-->
:num.Number = {Number = :num.Token.string}
Phase:Sentence
Input: Sentence
Options: control = appelt
Rule: GetNumber
({Sentence}):tag
-->
{
Annotation numSent = Utils.getOnlyAnn(bindings.get("tag"));
List<Annotation> val = Utils.inDocumentOrder(Utils.getContainedAnnotations(inputAS, numSent, "Number"));
List<String> str = new ArrayList<String>(val.size());
for(Annotation a : val) {
str.add((String)a.getFeatures().get("Number"));
}
numSent.getFeatures().put("Number", str);
}
此 jape 规则会将数字注释添加到现有的 Sentence 注释中 This is how the output looks