【问题标题】:GATE: JAPE rule Java RHS feature mapGATE:JAPE 规则 Java RHS 特征图
【发布时间】:2018-05-09 19:42:55
【问题描述】:

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

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

我相信它应该是优秀 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); }

除了在我的新规则中,我想对句子进行注释,然后获取包含的注释:

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

如何获取包含注释的特征图?

非常感谢

【问题讨论】:

    标签: java nlp grammar gate


    【解决方案1】:

    您可以使用 foreach 获取句子中包含的所有注释,并根据它们的主要类型或种类存储在特征图中。

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

    【讨论】:

    • 谢谢。我已经添加了你的建议,它不会抛出错误,只会吐出句子注释、句子字符串和规则名称作为特征。它不输出“团队”注释的主要类型。我还有什么需要改变的吗?
    • 我找不到你...你能ping我吗?
    【解决方案2】:

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

    我有一个类似的 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);
    }
    

    此代码将使用默认的 Sentence 注释对句子进行注释,但在 Sentence 注释的功能中显示 Number 注释的功能。

    这是输出图像:

    【讨论】:

      猜你喜欢
      • 2015-05-30
      • 2018-05-23
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多