首页 > 解决方案 > GATE 根据查询注解 ON TOKEN 对句子进行注解

问题描述

我正在使用 GATE 8.5,在执行标记器和句子拆分器之后,我执行我的地名词典匹配以获取一些标记上的查找注释,现在我想搜索那些具有查找注释的标记,以通过一些注释来注释包含这些标记的句子,我尝试类似:

Iterator sentenceIterator = 
inputAnnSet.get(ANNIEConstants.SENTENCE_ANNOTATION_TYPE).iterator(), 
tokenIterator;
        while(sentenceIterator.hasNext()) 
{Annotation sentenceAnnotation = 
(Annotation)sentenceIterator.next();
 tokenIterator =  doc.getAnnotations().get("Lookup").iterator();
            while(tokenIterator.hasNext())
            { Annotation tokenAnnotation = (Annotation)tokenIterator.next();                
if(tokenAnnotation.getFeatures().get("majorType").equals("mytype") )
                {
                    sentenceAnnotation.getFeatures().put(new 
String("SentenceType"),  
new String(doc.getContent().getContent(tokenAnnotation.getStartNode().getOffset(),
tokenAnnotation.getEndNode().getOffset()).toString()));

问候

标签: javaannotationsgate

解决方案


我认为您的代码将无法正常工作。您只需要查看特定句子中包含的标记:

AnnotationSet lookupAnnotations =  doc.getAnnotations().get("Lookup");
for ( Annotation sentenceAnnotation : inputAnnSet.get(ANNIEConstants.SENTENCE_ANNOTATION_TYPE)) {
    for ( Annotation tokenAnnotation : gate.Utils.getContainedAnnotations(
            lookupAnnotations, sentenceAnnotation)) 
    {
        Object majorType = tokenAnnotation.getFeatures().get("majorType");
        if (majorType != null && majorType.equals("mytype")) {
            sentenceAnnotation.getFeatures().put(
                    "SentenceType", gate.Utils.stringFor(doc, tokenAnnotation));
            break; //move to next sentence, this one is finished
        }
    }
}

推荐阅读