edu.stanford.nlp.trees.GrammaticalStructureFactory Java Examples
The following examples show how to use
edu.stanford.nlp.trees.GrammaticalStructureFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NERTool.java From Criteria2Query with Apache License 2.0 | 6 votes |
/** * Word Dependency Author:chi Date:2017-3-22 * */ public Collection<TypedDependency> outputDependency(Tree t) { TreebankLanguagePack tlp = new PennTreebankLanguagePack(); // tlp.setGenerateOriginalDependencies(true); Standford Dependency GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(t); Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(); int countforitem = 0; int source = 0; int target = 0; for (TypedDependency item : tdl) { System.out.println(item); } return tdl; }
Example #2
Source File: MainTest.java From dependensee with GNU General Public License v2.0 | 6 votes |
/** * Test of writeImage method, of class Main. */ @Test public void testWriteImage() throws Exception { String text = "A quick brown fox jumped over the lazy dog."; TreebankLanguagePack tlp = new PennTreebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); LexicalizedParser lp = LexicalizedParser.loadModel(); lp.setOptionFlags(new String[]{"-maxLength", "500", "-retainTmpSubcategories"}); TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), ""); List<CoreLabel> wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize(); Tree tree = lp.apply(wordList); GrammaticalStructure gs = gsf.newGrammaticalStructure(tree); Collection<TypedDependency> tdl = gs.typedDependenciesCollapsed(); Main.writeImage(tdl, "image.png", 3); assert (new File("image.png").exists()); }
Example #3
Source File: StanfordLexicalDemo.java From Natural-Language-Processing-with-Java-Second-Edition with MIT License | 5 votes |
public static void main(String args[]){ String parseModel = getResourcePath() + "englishPCFG.ser.gz"; LexicalizedParser lexicalizedParser = LexicalizedParser.loadModel(parseModel); String [] sentenceArray = {"The", "cow" ,"jumped", "over", "the", "moon", "."}; List<CoreLabel> words = SentenceUtils.toCoreLabelList(sentenceArray); Tree parseTree = lexicalizedParser.apply(words); parseTree.pennPrint(); TreePrint treePrint = new TreePrint("typedDependenciesCollapsed"); treePrint.printTree(parseTree); String sentence = "The cow jumped over the moon."; TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), ""); Tokenizer<CoreLabel> tokenizer = tokenizerFactory.getTokenizer(new StringReader(sentence)); List<CoreLabel> wordList = tokenizer.tokenize(); parseTree = lexicalizedParser.apply(wordList); TreebankLanguagePack tlp = lexicalizedParser.treebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(parseTree); List<TypedDependency> tdl = gs.typedDependenciesCCprocessed(); System.out.println(tdl); for(TypedDependency dependency : tdl) { System.out.println("Governor Word: [" + dependency.gov() + "] Relation: [" + dependency.reln().getLongName() + "] Dependent Word: [" + dependency.dep() + "]"); } }
Example #4
Source File: CoreNLP.java From Criteria2Query with Apache License 2.0 | 5 votes |
/** * Word Dependency Author:chi Date:2017-3-22 * */ public Collection<TypedDependency> outputDependency(Tree t) { TreebankLanguagePack tlp = new PennTreebankLanguagePack(); // tlp.setGenerateOriginalDependencies(true); Standford Dependency GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(t); Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(); int countforitem = 0; int source = 0; int target = 0; return tdl; }
Example #5
Source File: Chapter7.java From Natural-Language-Processing-with-Java-Second-Edition with MIT License | 4 votes |
private static void usingStanfordLexicalizedParser() { String parserModel = "C:/Current Books in Progress/NLP and Java/Models/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"; LexicalizedParser lexicalizedParser = LexicalizedParser.loadModel(parserModel); // This option shows parsing a list of correctly tokenized words System.out.println("---First option"); String[] senetenceArray = {"The", "cow", "jumped", "over", "the", "moon", "."}; List<CoreLabel> words = Sentence.toCoreLabelList(senetenceArray); Tree parseTree = lexicalizedParser.apply(words); parseTree.pennPrint(); System.out.println(); // This option shows loading and using an explicit tokenizer System.out.println("---Second option"); String sentence = "The cow jumped over the moon."; TokenizerFactory<CoreLabel> tokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), ""); Tokenizer<CoreLabel> tokenizer = tokenizerFactory.getTokenizer(new StringReader(sentence)); List<CoreLabel> wordList = tokenizer.tokenize(); parseTree = lexicalizedParser.apply(wordList); TreebankLanguagePack tlp = lexicalizedParser.treebankLanguagePack(); // PennTreebankLanguagePack for English GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(parseTree); List<TypedDependency> tdl = gs.typedDependenciesCCprocessed(); System.out.println(tdl); for (TypedDependency dependency : tdl) { System.out.println("Governor Word: [" + dependency.gov() + "] Relation: [" + dependency.reln().getLongName() + "] Dependent Word: [" + dependency.dep() + "]"); } System.out.println(); // You can also use a TreePrint object to print trees and dependencies // System.out.println("---Using TreePrint"); // TreePrint treePrint = new TreePrint("penn,typedDependenciesCollapsed"); // treePrint.printTree(parseTree); // System.out.println("TreePrint Formats"); // for (String format : TreePrint.outputTreeFormats) { // System.out.println(format); // } // System.out.println(); }