views:

28

answers:

1

I need phrases returned from Stanford parser to use to in my program.

A: 

Do you just want the tokens (words)? If so, you want something like:

Reader r; // initialized somehow by you
Tokenizer<CoreLabel> tokenizer = new PTBTokenizer<CoreLabel>(r, new CoreLabelTokenFactory(), "");
while (tokenizer.hasNext()) {
  CoreLabel token = tokenizer.next();
  System.out.println(token);
}

Or do you want the phrases in the parse tree? If so, you should get the returned Tree as in ParserDemo in the distribution and use the phrases (subtrees) in it (you can iterate over them:

Tree parse = lp.apply(sentence);
for (Tree subtree : tree) {
  System.out.println(subtree);
}
Christopher Manning