How to remove UIMA annotations?
Asked Answered
F

3

5

I'm using some UIMA annotators in a pipeline. It run tasks like:

  • tokenizer
  • sentence splitter
  • gazetizer
  • My Annotator

The problem is that I don't want to write ALL the annotations (Token, Sentence, SubToken, Time, myAnnotations, etc..) to the disk because the files gets very large quicky.

I want to remove all the annotations and keep only the created by My Annotator.

I'm working with the next libraries:

  1. uimaFIT 2.0.0
  2. ClearTK 1.4.1
  3. Maven

And I'm using a org.apache.uima.fit.pipeline.SimplePipeline with:

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

What I'm trying to do is to use the Standford NLP annotator(from ClearTK) and remove the useless annotation.

How do I do this?

From what I know, you can use the removeFromIndexes(); method from with an Annotation instance.

Do I need to create an UIMA processor and add it to my pipeline?

Fricassee answered 30/12, 2013 at 17:14 Comment(0)
F
7

Finally I created an Engine to remove the useless annotation:

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

I'm removing all the annotations leaving only the mypackage.MyAnnotation annotations

Fricassee answered 1/1, 2014 at 23:11 Comment(0)
B
2

Yes: between MyAnnotator and XWriter add another annotator that removes all annotation but yours.

Brahman answered 31/12, 2013 at 12:30 Comment(1)
Can you help me on that ?Fricassee
B
1

I rewrote German Attanasios solution using java 8 and changed it to filter out anything with a different annotationTypePrefix:

public void filterAnnotations(JCas jcas, String annotationTypePrefix) {

    JCasUtil.selectAll(jcas)
            .stream()
            .filter(t -> !t.getType().getName().startsWith(annotationTypePrefix))
            .forEach(TOP::removeFromIndexes);
}
Burgee answered 6/12, 2018 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.