List of usage examples for opennlp.tools.cmdline.postag POSModelLoader POSModelLoader
public POSModelLoader()
From source file:NLP.java
public NLP() throws FileNotFoundException, IOException, URISyntaxException { itemsList = new HashMap<String, String>(); String file = (new File(NLP.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())) .toString();//from ww w . j a v a 2s. c o m String path = (new File(file).getParentFile().getPath()).toString(); model = new POSModelLoader().load(new File(path + "\\fr-pos.bin")); perfMon = new PerformanceMonitor(System.err, "sent"); tagger = new POSTaggerME(model); try (InputStream is = new FileInputStream(path + "\\fr-token.bin")) { tokenizer = new TokenizerME(new TokenizerModel(is)); } catch (Exception e) { System.out.println(e); } }
From source file:com.geocode.service.impl.AddressServiceImpl.java
@PostConstruct public void init() throws URISyntaxException { model = new POSModelLoader() .load(new File(this.getClass().getResource(basePath + "en-pos-maxent.bin").toURI())); tagger = new POSTaggerME(model); list.addAll(baseList);//w w w.ja va2 s. co m CounterHelper.readCounter(); }
From source file:os.Controller.java
public static String POSTag(String a) throws IOException { POSModel model = new POSModelLoader().load(new File("en-pos-maxent.bin")); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); POSTaggerME tagger = new POSTaggerME(model); ObjectStream<String> lineStream = new PlainTextByLineStream(new StringReader(a)); perfMon.start();/* w ww.j av a2 s . co m*/ String line, result = ""; while ((line = lineStream.read()) != null) { String whitespaceTokenizerLine[] = WhitespaceTokenizer.INSTANCE.tokenize(line); String[] tags = tagger.tag(whitespaceTokenizerLine); POSSample sample = new POSSample(whitespaceTokenizerLine, tags); result = result + sample.toString(); perfMon.incrementCounter(); } perfMon.stopAndPrintFinalResult(); textList.add(result); return result; }