CAS consumer not working as expected

南楼画角 提交于 2019-12-11 11:39:01

问题


I have a CAS consumer AE which is expected to iterates over CAS objects in a pipeline, serialize them and add the serialized CASs to an xml file. public class DataWriter extends 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);
    }
}

I am using it inside a pipeline after all my annotators, but it couldn't read CAS objects (I am getting NullPointerException at jCas.getCas()). It looks like I don't seem to understand the proper usage of CAS consumer. I appreciate any suggestions.

来源:https://stackoverflow.com/questions/24416008/cas-consumer-not-working-as-expected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!