CAS消费者没有按预期工作

时间:2014-06-25 18:31:59

标签: uima

我有一个CAS消费者AE,它应该在管道中迭代CAS对象,序列化它们并将序列化的CAS添加到xml文件中。       公共类DataWriter扩展了JCasConsumer_ImplBase {

private File outputDirectory;

public static final String PARAM_OUTPUT_DIRECTORY = "outputDir";
@ConfigurationParameter(name=PARAM_OUTPUT_DIRECTORY, defaultValue=".")
private String outputDir;

CasToInlineXml cas2xml;

public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    ConfigurationParameterInitializer.initialize(this, context);

    outputDirectory = new File(outputDir);
    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }
}

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
    String file = fileCollectionReader.fileName;
    File outFile = new File(outputDirectory, file + ".xmi");
    FileOutputStream out = null;



    try {
        out = new FileOutputStream(outFile);
        String xmlAnnotations = cas2xml.generateXML(jCas.getCas());
        out.write(xmlAnnotations.getBytes("UTF-8"));
       /* XmiCasSerializer ser = new XmiCasSerializer(jCas.getCas().getTypeSystem());
        XMLSerializer xmlSer = new XMLSerializer(out, false);
        ser.serialize(jCas.getCas(), xmlSer.getContentHandler());*/

        if (out != null) {
            out.close();
        }
    }
    catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
    catch (CASException e) {
        throw new AnalysisEngineProcessException(e);
    }
}

我在所有注释器之后在管道中使用它,但它无法读取CAS对象(我在jCas.getCas()中得到NullPointerException)。看起来我似乎并不了解CAS消费者的正确用法。我很感激任何建议。

0 个答案:

没有答案