Java Code Examples for opennlp.tools.namefind.NameFinderME#train()
The following examples show how to use
opennlp.tools.namefind.NameFinderME#train() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Chapter4.java From Natural-Language-Processing-with-Java-Second-Edition with MIT License | 5 votes |
private static void trainingOpenNLPNERModel() { try (OutputStream modelOutputStream = new BufferedOutputStream( new FileOutputStream(new File("modelFile")));) { ObjectStream<String> lineStream = new PlainTextByLineStream( new FileInputStream("en-ner-person.train"), "UTF-8"); ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream); TokenNameFinderModel model = NameFinderME.train("en", "person", sampleStream, null, 100, 5); model.serialize(modelOutputStream); } catch (IOException ex) { ex.printStackTrace(); } }
Example 2
Source File: OpenNlpNerRecommender.java From inception with Apache License 2.0 | 5 votes |
private TokenNameFinderModel train(List<NameSample> aNameSamples, TrainingParameters aParameters) throws RecommendationException { try (NameSampleStream stream = new NameSampleStream(aNameSamples)) { TokenNameFinderFactory finderFactory = new TokenNameFinderFactory(); return NameFinderME.train("unknown", null, stream, aParameters, finderFactory); } catch (IOException e) { LOG.error("Exception during training the OpenNLP Named Entity Recognizer model.", e); throw new RecommendationException("Error while training OpenNLP pos", e); } }