Pergunta

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

Foi útil?

Solução

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);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top