views:

132

answers:

2

I'm using Stanford Parser to parse the dependence relations between pair of words, but I also need the tagging of words. However, in the ParseDemo.java, the program only output the Tagging Tree. I need each word's tagging like this:

My/PRP$ dog/NN also/RB likes/VBZ eating/VBG bananas/NNS ./.

not like this:

(ROOT
  (S
    (NP (PRP$ My) (NN dog))
    (ADVP (RB also))
    (VP (VBZ likes)
      (S
        (VP (VBG eating)
          (S
            (ADJP (NNS bananas))))))
    (. .)))

Who can help me? thanks a lot.

+2  A: 

When running edu.stanford.nlp.parser.lexparser.LexicalizedParser on the command line, you want to use:

-outputFormat "wordsAndTags"

Programatically, use the TreePrint class constructed with formatString="wordsAndTags" and call printTree, like this:

TreePrint posPrinter = new TreePrint("wordsAndTags", yourPrintWriter);
posPrinter.printTree(yourLexParser.getBestParse());
msbmsb
+1  A: 

Or, if you're more interested in manipulating the tags in a program, and don't need the TreePrint functionality, you can just get the tagged words as a List: Tree parse = lp.apply(Arrays.asList(sent)); List taggedWords = parse.taggedYield();

Christopher Manning