当前位置: 首页>>代码示例>>Java>>正文


Java SentenceDetectorFactory类代码示例

本文整理汇总了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();
}
 
开发者ID:jprante,项目名称:elasticsearch-analysis-opennlp,代码行数:21,代码来源:Trainer.java

示例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");

}
 
开发者ID:SOBotics,项目名称:SOCVFinder,代码行数:26,代码来源:SentanceDetector.java


注:本文中的opennlp.tools.sentdetect.SentenceDetectorFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。