The Stanford Parser的一个例子
- - 丕子The Stanford Parser挺强大的,支持中英文,用了RNN等. 1 他 _ PN PN _ 3 conj _ _. 2 和 _ CC CC _ 3 cc _ _. 3 我 _ PN PN _ 8 nsubj _ _. 4 在 _ P P _ 8 prep _ _. 5 学校 _ NN NN _ 6 lobj _ _.
The Stanford Parser挺强大的,支持中英文,用了RNN等。
import java.util.Collection;
import java.util.List;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
class ParserDemo {
public static void main(String[] args) {
LexicalizedParser lp = LexicalizedParser
.loadModel("edu/stanford/nlp/models/lexparser/xinhuaFactored.ser.gz");
String[] sent = { "他", "和", "我", "在", "学校", "里", "常", "打", "桌球", "。" };
List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
Tree parse = lp.apply(rawWords);
parse.pennPrint();
System.out.println();
TreebankLanguagePack tlp = lp.getOp().langpack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
//Stanford dependencies in the CoNLL format
System.out.println(GrammaticalStructure.dependenciesToString(gs,
gs.typedDependencies(), parse, true, false));
Collection<TypedDependency> tdl = gs.allTypedDependencies();
System.out.println(tdl);
System.out.println();
System.out.println(parse.taggedYield());
System.out.println();
}
}
结果可以自己处理:
1 他 _ PN PN _ 3 conj _ _
2 和 _ CC CC _ 3 cc _ _
3 我 _ PN PN _ 8 nsubj _ _
4 在 _ P P _ 8 prep _ _
5 学校 _ NN NN _ 6 lobj _ _
6 里 _ LC LC _ 4 plmod _ _
7 常 _ AD AD _ 8 advmod _ _
8 打 _ VV VV _ 0 root _ _
9 桌球 _ NN NN _ 8 dobj _ _
10 。 _ PU PU _ 0 erased _ _
| 您可能也喜欢: | ||||
《The Company Man》-观感 |
The Sound of Silence |
The Spider:一个“面向对象”的机器学习Matlab工具箱 |
The End of the Beginning of Active Learning |
[英文] How the brain recognizes objects |
| 无觅 | ||||