List of usage examples for edu.stanford.nlp.parser.lexparser LexicalizedParser setOptionFlags
@Override public void setOptionFlags(String... flags)
From source file:com.parse.Dependency.java
public static void main(String[] args) { LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); lp.setOptionFlags(new String[] { "-maxLength", "80", "-retainTmpSubcategories", }); String[] sent = { "This", "is", "an", "easy", "sentence", "." }; List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent); Tree parse = lp.apply(rawWords);/*from w w w . ja v a2 s . c o m*/ parse.pennPrint(); System.out.println(); TreebankLanguagePack tlp = new PennTreebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(parse); List<TypedDependency> tdl = gs.typedDependenciesCCprocessed(); System.out.println(tdl); //System.out.println(); //TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed"); // tp.printTree(parse); String sentence = "which movies were directed by Christopher Nolan"; Tree t2 = lp.parse(sentence); System.out.println(t2.firstChild().toString()); gs = gsf.newGrammaticalStructure(t2); tdl = gs.typedDependenciesCCprocessed(); System.out.println(tdl); System.out.println(tdl.get(0).dep().nodeString()); }
From source file:dependencies.ParsingUtils.java
License:Open Source License
private static LexicalizedParser getLexicalizedParserInstance() { LexicalizedParser lp = new LexicalizedParser(Paths.depParserPath + "/englishPCFG.ser.gz"); lp.setOptionFlags(new String[] { "-maxLength", "60", "-retainTmpSubcategories" }); return lp;/*w ww. j ava 2 s.c o m*/ }
From source file:DependencyParser.Parser.java
public void CallParser(String text) // start of the main method { try {//from w w w.j av a 2 s . c o m TreebankLanguagePack tlp = new PennTreebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); LexicalizedParser lp = LexicalizedParser .loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); lp.setOptionFlags(new String[] { "-maxLength", "500", "-retainTmpSubcategories" }); TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), ""); List<CoreLabel> wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize(); Tree tree = lp.apply(wordList); GrammaticalStructure gs = gsf.newGrammaticalStructure(tree); Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(true); System.out.println(tdl); PrintWriter pw = new PrintWriter("H:\\Thesis Development\\Thesis\\NLP\\src\\nlp\\Text-Parsed.txt"); TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed"); tp.printTree(tree, pw); pw.close(); Main.writeImage(tree, tdl, "H:\\Thesis Development\\Thesis\\NLP\\src\\nlp\\image.png", 3); assert (new File("image.png").exists()); } catch (FileNotFoundException f) { } catch (Exception ex) { Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.iastate.airl.semtus.parser.Parser.java
License:Open Source License
/** * Load the grammar// w w w .j a v a 2 s .c o m * * @param thisInputStream * serialized grammar file input stream * @return LexicalizedParser */ protected LexicalizedParser load(ObjectInputStream thisInputStream) { try { LexicalizedParser thisParser = new LexicalizedParser(thisInputStream); thisParser.setOptionFlags(new String[] { "-maxLength", "80", "-retainTmpSubcategories" }); return thisParser; } catch (Exception e) { System.out.println(e.toString()); return null; } }
From source file:Engines.Test.StanfordParser.TreeHandling.java
License:Open Source License
public static void test(String text) { TreebankLanguagePack tlp = new PennTreebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); lp.setOptionFlags(new String[] { "-maxLength", "500", "-retainTmpSubcategories" }); TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), ""); List<CoreLabel> wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize(); Tree tree = lp.apply(wordList);/* ww w .ja va 2 s . c o m*/ GrammaticalStructure gs = gsf.newGrammaticalStructure(tree); Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(true); }