Uses 6125K of libraries. Click here for Pure Java version (438L/4K/13K).
!7 lib 1008485 // stanford parser lib 1008486 // english model import edu.stanford.nlp.ling.CoreLabel; import edu.stanford.nlp.process.TokenizerFactory; import edu.stanford.nlp.parser.lexparser.LexicalizedParser; import edu.stanford.nlp.process.CoreLabelTokenFactory; import edu.stanford.nlp.process.PTBTokenizer; import edu.stanford.nlp.process.Tokenizer; import edu.stanford.nlp.trees.Tree; sS PCG_MODEL = "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"; static TokenizerFactory<CoreLabel> tokenizerFactory; static LexicalizedParser parser; static Tree parse(S str) { List<CoreLabel> tokens = tokenize(str); ret parser.apply(tokens); } static L<CoreLabel> tokenize(String str) { Tokenizer<CoreLabel> tokenizer = tokenizerFactory.getTokenizer( new StringReader(str)); ret tokenizer.tokenize(); } p { tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), "invertible=true"); parser = LexicalizedParser.loadModel(PCG_MODEL); S str = "My dog also likes eating sausage."; Tree tree = parse(str); L<Tree> leaves = tree.getLeaves(); // Print words and Pos Tags for (Tree leaf : leaves) { Tree parent = leaf.parent(tree); print(" " + leaf.label().value() + " [" + parent.label().value() + "]"); } print(); printTree(tree); } svoid printTree(Tree tree) { printTree("", tree); } svoid printTree(S indent, Tree tree) { //if (l(indent) > 4) ret; print(indent + tree.label().value()); for (Tree child : tree.getChildrenAsList()) printTree(indent + " ", child); }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008487 |
Snippet name: | Stanford Parser Test [WORKS] |
Eternal ID of this version: | #1008487/7 |
Text MD5: | 165c55ac305a3dfc53f2ee1a476f5fa3 |
Transpilation MD5: | 260168e69f45a65543a4225fdc150f6d |
Author: | stefan |
Category: | javax / a.i. parsing |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-17 17:30:56 |
Source code size: | 1589 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 388 / 1300 |
Version history: | 6 change(s) |
Referenced in: | #1008491 - stanfordParseEnglish #1008492 - stanfordPrintTree |