本文整理汇总了Java中opennlp.tools.sentdetect.SentenceDetectorFactory类的典型用法代码示例。如果您正苦于以下问题:Java SentenceDetectorFactory类的具体用法?Java SentenceDetectorFactory怎么用?Java SentenceDetectorFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SentenceDetectorFactory类属于opennlp.tools.sentdetect包,在下文中一共展示了SentenceDetectorFactory类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trainSentences
import opennlp.tools.sentdetect.SentenceDetectorFactory; //导入依赖的package包/类
public static void trainSentences(final String inResource, String outFile) throws IOException {
InputStreamFactory inputStreamFactory = new InputStreamFactory() {
@Override
public InputStream createInputStream() throws IOException {
return Trainer.class.getResourceAsStream(inResource);
}
};
SentenceSampleStream samples = new SentenceSampleStream(new PlainTextByLineStream(inputStreamFactory, StandardCharsets.UTF_8));
TrainingParameters trainingParameters = new TrainingParameters();
trainingParameters.put(TrainingParameters.ALGORITHM_PARAM, ModelType.MAXENT.name());
trainingParameters.put(TrainingParameters.ITERATIONS_PARAM, "100");
trainingParameters.put(TrainingParameters.CUTOFF_PARAM, "0");
SentenceDetectorFactory sentenceDetectorFactory = SentenceDetectorFactory.create(null, "en", true, null, ".?!".toCharArray());
SentenceModel sentdetectModel = SentenceDetectorME.train("en", samples, sentenceDetectorFactory, trainingParameters);
//.train("en", samples, true, null, 100, 0);
samples.close();
FileOutputStream out = new FileOutputStream(outFile);
sentdetectModel.serialize(out);
out.close();
}
示例2: main
import opennlp.tools.sentdetect.SentenceDetectorFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
SentenceModel model;
Charset charset = Charset.forName("UTF-8");
InputStreamFactory isf = new MarkableFileInputStreamFactory(new File("model/openNPLTraining.txt"));
ObjectStream<String> lineStream =
new PlainTextByLineStream(isf, charset);
ObjectStream<SentenceSample> sampleStream = new SentenceSampleStream(lineStream);
try {
Dictionary dict = new Dictionary(new FileInputStream(new File("ini/stop_words.txt")));
SentenceDetectorFactory sdf = new SentenceDetectorFactory("en",true,dict,null);
TrainingParameters params = TrainingParameters.defaultParams();
model = SentenceDetectorME.train("en", sampleStream, sdf,params);
}
finally {
sampleStream.close();
}
System.out.println("done");
}