使用DB数据在OpenNLP中训练自己的模型

我在数据库中有数据,需要用此数据训练自己的模型。所有人都建议尝试下面的代码。

但是我可以不使用 sampleStream (不使用文件直接数据)来创建模型吗?我是openNLP的新手。

public void trainmodel() {
    DoccatModel model = null;
    InputStream dataIn = null;
    try{
        InputStreamFactory factory = getInputStreamFactory(new File("D:/training.txt"));
        ObjectStream<String> linestream = new PlainTextByLinestream(factory,Charset.defaultCharset());
        ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(linestream);

        TrainingParameters params = new TrainingParameters();
        params.put(TrainingParameters.ITERATIONS_PARAM,"100");
        params.put(TrainingParameters.CUTOFF_PARAM,"0");

        model = DocumentCategorizerME.train("en",sampleStream,params,factory);
    }catch(Exception e){
        e.printStackTrace();
    }
}
iCMS 回答:使用DB数据在OpenNLP中训练自己的模型

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1574952.html

大家都在问