Search code examples
javanlpstanford-nlp

Stanford Java NLP Constituency labels abbreviations


Using the Stanford Java CoreNLP library, I have this:

            String text = "My name is Anthony";
            CoreDocument doc = new CoreDocument(text);
            pipeline.annotate(doc);
            for(Tree t : doc.sentences().get(0).constituencyParse()) {
                String tmp = "";
                for(Word w : t.yieldWords()) {
                    tmp = tmp + " " + w.word();
                }
                System.out.println(t.label().toString() + " - " + WordParts.getValue(t.label().toString()) + " - " + tmp);

Right now, the program outputs this:

ROOT - INVALID -  My name is Anthony
S - INVALID -  My name is Anthony
NP - INVALID -  My name
PRP$ - Possessive pronoun -  My
My-1 - INVALID -  My
NN - Singular noun -  name
name-2 - INVALID -  name
VP - INVALID -  is Anthony
VBZ - 3rd person singular present verb -  is
Subject:  Anthony
is-3 - INVALID -  is
NP - INVALID -  Anthony
NNP - Proper singular noun -  Anthony
Anthony-4 - INVALID -  Anthony

The WordParts.java abbreviations come from this post (Java Stanford NLP: Part of Speech labels?) and the class file can be found here: (https://github.com/AJ4real/References/blob/master/WordParts.java) I know that the labels are not Parts of Speech because some of the values return INVALID, so how can I find the full terms for the abbreviations that come from t.label().toString()?


Solution

  • The rest are Penn Treebank phrase categories. E.g., see here:

    https://gist.github.com/nlothian/9240750