gpt4 book ai didi

java - GATE:JAPE规则Java RHS特征图

转载 作者:行者123 更新时间:2023-12-02 02:09:17 25 4
gpt4 key购买 nike

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

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

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

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

非常感谢

最佳答案

您可以使用 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);
}

关于java - GATE:JAPE规则Java RHS特征图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50260935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com