fucknigger
New Member
\[code\] String sentence=args; LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"); lp.setOptionFlags(new String[]{"-maxLength", "300", "-retainTmpSubcategories"}); TokenizerFactory tf = PTBTokenizer.factory(false, new WordTokenFactory()); TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed"); List tokens = tf.getTokenizer(new StringReader(sentence)).tokenize();// lp.parseTree(tokens); // parse the tokens Tree t = lp.parseTree(tokens); TreebankLanguagePack languagePack = new PennTreebankLanguagePack(); GrammaticalStructure structure = languagePack.grammaticalStructureFactory().newGrammaticalStructure(t); Collection<TypedDependency> typedDependencies = structure.typedDependenciesCollapsed(); System.out.println(typedDependencies); for(TypedDependency td : typedDependencies) print td\[/code\]Among those dependencies i want to extract only root relation??How to find the root word of a sentence using parser in java?