public void startup() throws Exception { super.startup(); InputStream modelStream = MaryProperties.needStream(propertyPrefix + "model"); InputStream posMapperStream = MaryProperties.getStream(propertyPrefix + "posMap"); tagger = new POSTaggerME(new POSModel(modelStream)); modelStream.close(); if (posMapperStream != null) { posMapper = new HashMap<String, String>(); BufferedReader br = new BufferedReader(new InputStreamReader(posMapperStream, "UTF-8")); String line; while ((line = br.readLine()) != null) { // skip comments and empty lines if (line.startsWith("#") || line.trim().equals("")) continue; // Entry format: POS GPOS, i.e. two space-separated entries per line StringTokenizer st = new StringTokenizer(line); String pos = st.nextToken(); String gpos = st.nextToken(); posMapper.put(pos, gpos); } posMapperStream.close(); } }
partsOfSpeech = tagger.tag(tokens);
private static POSModel trainPOSModel(POSTaggerFactory factory) throws IOException { return POSTaggerME.train("eng", createSampleStream(), TrainingParameters.defaultParams(), factory); }
POSTaggerME tagger = new POSTaggerME(model); String[] tags = tagger.tag(whitespaceTokenizerLine);
POSTaggerME.populatePOSDictionary(trainingSampleStream, (MutableTagDictionary)dict, this.tagdicCutoff); } else { POSModel model = POSTaggerME.train(languageCode, trainingSampleStream, params, this.factory); POSEvaluator evaluator = new POSEvaluator(new POSTaggerME(model), listeners);
public final POSModel train(final TrainingParameters params) { // features if (getPosTaggerFactory() == null) { throw new IllegalStateException( "Classes derived from AbstractTrainer must " + " create a POSTaggerFactory features!"); } // training model POSModel trainedModel = null; POSEvaluator posEvaluator = null; try { trainedModel = POSTaggerME.train(this.lang, this.trainSamples, params, getPosTaggerFactory()); final POSTaggerME posTagger = new POSTaggerME(trainedModel); posEvaluator = new POSEvaluator(posTagger); posEvaluator.evaluate(this.testSamples); } catch (final IOException e) { System.err.println("IO error while loading training and test sets!"); e.printStackTrace(); System.exit(1); } System.out.println("Final result: " + posEvaluator.getWordAccuracy()); return trainedModel; }
new RecommendationException("Key [" + KEY_MODEL + "] not found in context")); POSTaggerME tagger = new POSTaggerME(model); .toArray(String[]::new); Sequence[] bestSequences = tagger.topKSequences(tokens);
POSTaggerME.populatePOSDictionary(sampleStream, (MutableTagDictionary)dict, params.getTagDictCutoff()); } else { model = opennlp.tools.postag.POSTaggerME.train(params.getLang(), sampleStream, mlParams, postaggerFactory);
public Sequence[] topKSequences(String[] sentence) { return this.topKSequences(sentence, null); }
@Deprecated public static void test(AbstractModel model) throws IOException { POSTaggerME tagger = new POSTaggerME(model, (TagDictionary) null); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (String line = in.readLine(); line != null; line = in.readLine()) { System.out.println(tagger.tag(line)); } }
POSTaggerME.populatePOSDictionary(trainingSampleStream, (MutableTagDictionary)dict, this.tagdicCutoff); } else { POSModel model = POSTaggerME.train(languageCode, trainingSampleStream, params, this.factory); POSEvaluator evaluator = new POSEvaluator(new POSTaggerME(model), listeners);
POSTaggerME.populatePOSDictionary(sampleStream, (MutableTagDictionary)dict, params.getTagDictCutoff()); } else { model = opennlp.tools.postag.POSTaggerME.train(params.getLang(), sampleStream, mlParams, postaggerFactory);
public Sequence[] topKSequences(String[] sentence) { return this.topKSequences(sentence, null); }
public void startup() throws Exception { super.startup(); InputStream modelStream = MaryProperties.needStream(propertyPrefix + "model"); InputStream posMapperStream = MaryProperties.getStream(propertyPrefix + "posMap"); tagger = new POSTaggerME(new POSModel(modelStream)); modelStream.close(); if (posMapperStream != null) { posMapper = new HashMap<String, String>(); BufferedReader br = new BufferedReader(new InputStreamReader(posMapperStream, "UTF-8")); String line; while ((line = br.readLine()) != null) { // skip comments and empty lines if (line.startsWith("#") || line.trim().equals("")) continue; // Entry format: POS GPOS, i.e. two space-separated entries per line StringTokenizer st = new StringTokenizer(line); String pos = st.nextToken(); String gpos = st.nextToken(); posMapper.put(pos, gpos); } posMapperStream.close(); } }
POSModel model = new POSModel(modelIn); POSTaggerME tagger = new POSTaggerME(model); String tags[] = tagger.tag(sentence.toArray(new String[sentence.size()]));
partsOfSpeech = tagger.tag(tokens);
POSTaggerME.populatePOSDictionary(trainingSampleStream, (MutableTagDictionary)dict, this.tagdicCutoff); } else { POSModel model = POSTaggerME.train(languageCode, trainingSampleStream, params, this.factory); POSEvaluator evaluator = new POSEvaluator(new POSTaggerME(model), listeners);