import java.util.List;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
class ParserDemo {
public static void main(String[] args) {
String parserModel = "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz";
LexicalizedParser lp = LexicalizedParser.loadModel(parserModel);
demoAPI(lp);
}
public static void demoAPI(LexicalizedParser lp) {
String str = "Next , we wanted to explore whether the BMP - 6 induced phosphorylation of Smad 1 / 5 / 8 also could induce transcriptional changes of target genes .";
String[] sent = str.split(" ");
//String[] sent = { "This", "is", "an", "easy", "sentence", "." };
List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
Tree parse = lp.apply(rawWords);
TreebankLanguagePack tlp = lp.treebankLanguagePack(); // PennTreebankLanguagePack for English
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
System.out.println(tdl);
System.out.println();
for(int i = 0; i < tdl.size(); i++)
{
TypedDependency td = tdl.get(i);
System.out.print(td.dep() + " ");
System.out.print(td.gov() + " ");
System.out.print(td.reln());
System.out.println();
System.out.print(td.dep().nodeString()+" ");
System.out.println(td.dep().index());
}
}
private ParserDemo() {} // static methods only
}