0

我是ClearTKUIMA的新手。到目前为止,我找不到任何关于如何创建不涉及文件的管道的示例。

我正在尝试使用 cleartk 和 UIMA 处理存储在 Java 字符串变量中的小文本,并返回一个 XML 字符串(ClearTK TimeML注释器的结果)。

我能够提供一个字符串作为输入(参见代码摘录),但代码远非优雅(需要执行 set 和 CAS 的空 URI。)此外,输出正在保存到文件中,但我想返回一个字符串(将输出保存到文件然后将文件读回内存是没有意义的)。

import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.fit.pipeline.SimplePipeline;
import org.apache.uima.jcas.JCas;
import org.cleartk.corpus.timeml.TempEval2007Writer;
import org.cleartk.opennlp.tools.PosTaggerAnnotator;
import org.cleartk.snowball.DefaultSnowballStemmer;
import org.cleartk.timeml.event.*;
import org.cleartk.timeml.time.TimeTypeAnnotator;
import org.cleartk.timeml.tlink.TemporalLinkEventToDocumentCreationTimeAnnotator;
import org.cleartk.timeml.tlink.TemporalLinkEventToSameSentenceTimeAnnotator;
import org.cleartk.timeml.tlink.TemporalLinkEventToSubordinatedEventAnnotator;
import org.cleartk.timeml.type.DocumentCreationTime;
import org.cleartk.token.tokenizer.TokenAnnotator;
import org.cleartk.util.cr.FilesCollectionReader;

...

String documentText = "First make sure that you are using eggs that are several days old...";
JCas sourceCas = createJCas();

sourceCas.setDocumentText(documentText);
ViewUriUtil.setURI(sourceCas, new URI(""));

SimplePipeline.runPipeline(
        sourceCas,
        org.cleartk.opennlp.tools.SentenceAnnotator.getDescription(),
        TokenAnnotator.getDescription(),
        PosTaggerAnnotator.getDescription(),
        DefaultSnowballStemmer.getDescription("English"),
        org.cleartk.opennlp.tools.ParserAnnotator.getDescription(),
        org.cleartk.timeml.time.TimeAnnotator.FACTORY.getAnnotatorDescription(),
        TimeTypeAnnotator.FACTORY.getAnnotatorDescription(),
        EventAnnotator.FACTORY.getAnnotatorDescription(),
        EventTenseAnnotator.FACTORY.getAnnotatorDescription(),
        EventAspectAnnotator.FACTORY.getAnnotatorDescription(),
        EventClassAnnotator.FACTORY.getAnnotatorDescription(),
        EventPolarityAnnotator.FACTORY.getAnnotatorDescription(),
        EventModalityAnnotator.FACTORY.getAnnotatorDescription(),
        AnalysisEngineFactory.createEngineDescription(AddEmptyDCT.class),
        TemporalLinkEventToDocumentCreationTimeAnnotator.FACTORY.getAnnotatorDescription(),
        TemporalLinkEventToSameSentenceTimeAnnotator.FACTORY.getAnnotatorDescription(),
        TemporalLinkEventToSubordinatedEventAnnotator.FACTORY.getAnnotatorDescription(),
        TempEval2007Writer.getDescription("file:///tmp/out.tml"));

让管道将字符串作为输入并生成另一个字符串作为执行结果的推荐方法是什么?

4

2 回答 2

0

像你一样运行你的引擎SimplePipeline,然后sourceCas像这样从你那里检索你感兴趣的注释:

Collection<MyAnnotation> myAnnotation = JCasUtil.select(sourceCas, MyAnnotation.class);
String myproperty = myAnnotation.getMyproperty();
于 2015-07-14T12:01:14.207 回答
0

org.apache.uima.fit.factory.AggregateBuilder我最喜欢的方法是不使用管道,而是通过 Lee Becker 在这篇文章中推荐的手动创建分析引擎。

    AggregateBuilder builder = new AggregateBuilder();
    builder.add(org.cleartk.opennlp.tools.SentenceAnnotator.getDescription());
    builder.add(TokenAnnotator.getDescription());
    builder.add(DefaultSnowballStemmer.getDescription("English"));
    builder.add(org.cleartk.opennlp.tools.ParserAnnotator.getDescription());
    builder.add(org.cleartk.timeml.time.TimeAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(TimeTypeAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventTenseAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventAspectAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventClassAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventPolarityAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(EventModalityAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(AnalysisEngineFactory.createEngineDescription(AddEmptyDCT.class));
    builder.add(TemporalLinkEventToDocumentCreationTimeAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(TemporalLinkEventToSameSentenceTimeAnnotator.FACTORY.getAnnotatorDescription());
    builder.add(TemporalLinkEventToSubordinatedEventAnnotator.FACTORY.getAnnotatorDescription());

    AnalysisEngine aggregateEngine = builder.createAggregate();
    JCas sourceCas = createJCas();
    sourceCas.setDocumentText(documentText);
    ViewUriUtil.setURI(sourceCas, new URI(""));

    aggregateEngine.process(sourceCas);

    String timeMlXml = TempEval2007Writer.toTimeML(sourceCas);
于 2015-07-15T15:56:14.747 回答