使用斯坦福Java CoreNLP库,我有这个:
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);
现在,程序输出此:
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
WordParts.java
的缩写来自此帖子(Java Stanford NLP: Part of Speech labels?),可以在这里找到类文件:(https://github.com/AJ4real/References/blob/master/WordParts.java)我知道标签不是Parts of Speech
,因为某些值返回INVALID
,那么如何找到t.label().toString()
缩写的完整术语呢?
[其余为Penn Treebank短语类别。例如,请参见此处: