GATE:JAPE 规则 Java RHS 特征图

GATE: JAPE rule Java RHS feature map

我正在尝试在句子注释中获取现有注释及其特征,即对于每个句子,可能有多个具有主要类型、字符串和类型特征的注释。

我想要一个新的“句子包含”注释,其中包含包含的注释及其各自特征的特征图。

我相信它应该是优秀的 Gate Jape 语法教程 pdf 中以下规则的扩展:

Phase:usingJAVAinRHS  
Input:  Lookup  
Options: control = all  
Rule: javainRHS1  
(  
{Lookup.majorType == Team}  
)  
:team  
-->  
{  
gate.AnnotationSet team = (gate.AnnotationSet)bindings.get("team");       
gate.Annotation teamAnn = (gate.Annotation)team.iterator().next();   
gate.FeatureMap features = Factory.newFeatureMap(); 
features.put("teamOfSport", teamAnn.getFeatures().get("minorType"));  
features.put("rule","javainRHS1");  
outputAS.add(team.firstNode(), team.lastNode(), "Team",features); }

除了在我的新规则中,我想注释 Sentence,然后获取包含的注释:

Phase:usingJAVAinRHS  
Input:  Lookup Sentence  
Options: control = all  
Rule: javainRHS1  
(  
{Sentence contains {Lookup.majorType == Team}}  
)  
:team  
-->  
{  
gate.AnnotationSet team = (gate.AnnotationSet)bindings.get("team");   
gate.Annotation teamAnn = (gate.Annotation)team.iterator().next();   
gate.FeatureMap features = Factory.newFeatureMap(); 
features.put("teamOfSport",   teamAnn.getFeatures().get("minorType"));  
features.put("rule","javainRHS1");  
outputAS.add(team.firstNode(), team.lastNode(), "Team",features); }  

如何获取包含标注的feature map?

非常感谢

您可以使用foreach 获取句子中包含的所有注释,并根据它们的majorType 或kind 存储在feature map 中。

Imports: {
import static gate.Utils.*;
}
Phase:usingJAVAinRHS  
Input:  Lookup Sentence  
Options: control = appelt
Rule: javainRHS1  
(  
{Sentence contains {Lookup.majorType == Team}}  
)  
:team  
-->  
{  
    gate.AnnotationSet team = (gate.AnnotationSet)bindings.get("team"); 
    gate.FeatureMap features = Factory.newFeatureMap(); 
    for(Annotation annotation:team.inDocumentOrder())  
    {
        if(annotation.getType() == "Lookup"){
            features.put(annotation.getFeatures().get("majorType"),stringFor(doc,annotation));
        }
        else{
            features.put(annotation.getType(), stringFor(doc,annotation));
        }
    }
    features.put("rule","javainRHS1");  
    outputAS.add(team.firstNode(), team.lastNode(), "Team",features); 
}  

创建一个新注释只是为了找出“Team”并编写另一条规则,将 Team 的注释复制到 RHS 中的默认 Sentence 注释

我有一个类似的 jape 规则,我需要注释句子并将句子中的数字添加为它的特征。

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);
}

此代码将使用默认的句子注释对句子进行注释,但会在句子注释的特征中显示数字注释的特征。

这是输出图像: