| | package SentenceSplitting; |
| |
|
| | import java.io.BufferedReader; |
| | import java.io.File; |
| | import java.io.FileOutputStream; |
| | import java.io.FileReader; |
| | import java.io.IOException; |
| | import java.io.Reader; |
| | import java.nio.charset.StandardCharsets; |
| |
|
| | import opennlp.tools.dictionary.Dictionary; |
| | import opennlp.tools.ml.EventTrainer; |
| | import opennlp.tools.sentdetect.SentenceDetectorFactory; |
| | import opennlp.tools.sentdetect.SentenceDetectorME; |
| | import opennlp.tools.sentdetect.SentenceModel; |
| | import opennlp.tools.sentdetect.SentenceSampleStream; |
| | import opennlp.tools.util.InputStreamFactory; |
| | import opennlp.tools.util.MarkableFileInputStreamFactory; |
| | import opennlp.tools.util.PlainTextByLineStream; |
| | import opennlp.tools.util.TrainingParameters; |
| | import opennlp.tools.util.model.ModelType; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | public class CreateModelSS { |
| | |
| | public static void main (String args[]) throws IOException |
| | { |
| | String trainFile = args[0]; |
| | String outModel = args[1]; |
| | String modelName = args[2]; |
| | String abbrFile = args[3]; |
| | |
| | |
| | File destDir = new File(outModel); |
| | |
| | |
| | Dictionary abbrDictionary = makeAbbrDictionary(abbrFile); |
| | |
| | |
| | InputStreamFactory in = new MarkableFileInputStreamFactory(new File(trainFile)); |
| | |
| | |
| | TrainingParameters mlParams = new TrainingParameters(); |
| | mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(4000)); |
| | mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(3)); |
| | mlParams.put(TrainingParameters.TRAINER_TYPE_PARAM, EventTrainer.EVENT_VALUE); |
| | mlParams.put(TrainingParameters.ALGORITHM_PARAM, ModelType.MAXENT.name()); |
| | |
| | |
| | SentenceDetectorFactory sentenceDetectorFactory = SentenceDetectorFactory.create(null, "es", true, abbrDictionary, ".?!".toCharArray()); |
| | SentenceModel sentdetectModel = SentenceDetectorME.train( |
| | "es", |
| | new SentenceSampleStream(new PlainTextByLineStream(in, StandardCharsets.UTF_8)), |
| | sentenceDetectorFactory, |
| | mlParams); |
| | |
| | |
| | |
| | File outFile = new File(destDir,modelName); |
| | FileOutputStream outFileStream = new FileOutputStream(outFile); |
| | sentdetectModel.serialize(outFileStream); |
| | } |
| | |
| | |
| | |
| | |
| | public static Dictionary makeAbbrDictionary(String abbrFile) throws IOException |
| | { |
| | Dictionary dictionary = new Dictionary(); |
| | |
| | Reader reader = new BufferedReader(new FileReader(abbrFile)); |
| | dictionary = Dictionary.parseOneEntryPerLine(reader); |
| | |
| | return dictionary; |
| | } |
| | } |
| |
|