【问题标题】:How to remove UIMA annotations?如何删除 UIMA 注释?
【发布时间】:2013-12-30 17:14:15
【问题描述】:

我在管道中使用了一些 UIMA 注释器。它运行以下任务:

  • 分词器
  • 分句器
  • 公报
  • 我的注释器

问题是我不想将所有注释(Token、Sentence、SubToken、Time、myAnnotations 等)写入磁盘,因为文件很快就会变得非常大。

我想删除所有注释,只保留 My Annotator 创建的注释。

我正在使用下一个库:

  1. uimaFIT 2.0.0
  2. 清除TK 1.4.1
  3. 马文

我正在使用org.apache.uima.fit.pipeline.SimplePipeline

SimplePipeline.runPipeline(
    UriCollectionReader.getCollectionReaderFromDirectory(filesDirectory), //directory with text files
    UriToDocumentTextAnnotator.getDescription(),
    StanfordCoreNLPAnnotator.getDescription(),//stanford tokenize, ssplit, pos, lemma, ner, parse, dcoref
    AnalysisEngineFactory.createEngineDescription(//
        XWriter.class, 
        XWriter.PARAM_OUTPUT_DIRECTORY_NAME, outputDirectory,
        XWriter.PARAM_FILE_NAMER_CLASS_NAME, ViewURIFileNamer.class.getName())
);

我正在尝试做的是使用 Standford NLP 注释器(来自 ClearTK)并删除无用的注释。

我该怎么做?

据我所知,您可以将 removeFromIndexes(); 方法与 Annotation 实例一起使用。

我是否需要创建一个 UIMA 处理器并将其添加到我的管道中?

【问题讨论】:

    标签: java nlp uima


    【解决方案1】:

    最后我创建了一个 Engine 来移除无用的注解:

    public class AnnotationRemover extends JCasAnnotator_ImplBase {
        public static AnalysisEngineDescription getDescription() throws ResourceInitializationException {
            return AnalysisEngineFactory.createEngineDescription(AnnotationRemover.class);
        }
    
        public void initialize(UimaContext context) throws ResourceInitializationException {
            super.initialize(context);
        }
    
        public void process(JCas jCas) throws AnalysisEngineProcessException {
            List<TOP> tops = new ArrayList<TOP>(JCasUtil.selectAll(jCas));
            for (TOP t : tops) {
                if (!t.getType().getName().equals("mypackage.MyAnnotation")) 
                    t.removeFromIndexes();
                }
            }
    }
    

    我将删除所有注释,只留下 mypackage.MyAnnotation 注释

    【讨论】:

      【解决方案2】:

      是的:在 MyAnnotator 和 XWriter 之间添加另一个注释器,它会删除除您之外的所有注释。

      【讨论】:

      • 你能帮我吗?
      【解决方案3】:

      我使用 java 8 重写了德国 Attanasios 解决方案,并将其更改为过滤掉具有不同 annotationTypePrefix 的任何内容:

      public void filterAnnotations(JCas jcas, String annotationTypePrefix) {
      
          JCasUtil.selectAll(jcas)
                  .stream()
                  .filter(t -> !t.getType().getName().startsWith(annotationTypePrefix))
                  .forEach(TOP::removeFromIndexes);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-27
        • 2017-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多