public Parser getParser(String grammar) throws InvalidFormatException, IOException { InputStream is = new FileInputStream(grammar); ParserModel model = new ParserModel(is); Parser result = ParserFactory.create(model); is.close(); return (result); }
public NLPUtils() throws FileNotFoundException, IOException { InputStream modelInSent = NLPUtils.class.getClassLoader().getResourceAsStream("en-sent.bin"); InputStream modelInParser = NLPUtils.class.getClassLoader().getResourceAsStream("en-parser-chunking.bin"); SentenceModel modelSent = new SentenceModel(modelInSent); sentenceDetector = new SentenceDetectorME(modelSent); ParserModel modelParser = new ParserModel(modelInParser); parser = ParserFactory.create(modelParser); modelInSent.close(); modelInParser.close(); }