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()
?
The rest are Penn Treebank phrase categories. Eg, see here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.