List of usage examples for edu.stanford.nlp.trees GrammaticalStructure allTypedDependencies
List allTypedDependencies
To view the source code for edu.stanford.nlp.trees GrammaticalStructure allTypedDependencies.
Click Source Link
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordDependencyConverter.java
License:Open Source License
protected void doCreateDependencyTags(JCas aJCas, TreebankLanguagePack aLP, Tree parseTree, List<Token> tokens) { GrammaticalStructure gs; try {/*w ww . j a v a 2 s.c o m*/ gs = aLP.grammaticalStructureFactory(aLP.punctuationWordRejectFilter(), aLP.typedDependencyHeadFinder()) .newGrammaticalStructure(parseTree); } catch (UnsupportedOperationException e) { // We already warned in the model provider if dependencies are not supported, so here // we just do nothing and skip the dependencies. return; } Collection<TypedDependency> dependencies = null; switch (mode) { case BASIC: dependencies = gs.typedDependencies(); // gs.typedDependencies(false); break; case NON_COLLAPSED: dependencies = gs.allTypedDependencies(); // gs.typedDependencies(true); break; case COLLAPSED_WITH_EXTRA: dependencies = gs.typedDependenciesCollapsed(true); break; case COLLAPSED: dependencies = gs.typedDependenciesCollapsed(false); break; case CC_PROPAGATED: dependencies = gs.typedDependenciesCCprocessed(true); break; case CC_PROPAGATED_NO_EXTRA: dependencies = gs.typedDependenciesCCprocessed(false); break; case TREE: dependencies = gs.typedDependenciesCollapsedTree(); break; } for (TypedDependency currTypedDep : dependencies) { int govIndex = currTypedDep.gov().index(); int depIndex = currTypedDep.dep().index(); if (govIndex != 0) { // Stanford CoreNLP produces a dependency relation between a verb and ROOT-0 which // is not token at all! Token govToken = tokens.get(govIndex - 1); Token depToken = tokens.get(depIndex - 1); StanfordAnnotator.createDependencyAnnotation(aJCas, currTypedDep.reln(), govToken, depToken); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParser.java
License:Open Source License
protected void doCreateDependencyTags(ParserGrammar aParser, StanfordAnnotator sfAnnotator, Tree parseTree, List<Token> tokens) { GrammaticalStructure gs; try {// w ww . j a v a 2 s .c o m TreebankLanguagePack tlp = aParser.getTLPParams().treebankLanguagePack(); gs = tlp.grammaticalStructureFactory(tlp.punctuationWordRejectFilter(), tlp.typedDependencyHeadFinder()) .newGrammaticalStructure(parseTree); } catch (UnsupportedOperationException e) { // We already warned in the model provider if dependencies are not supported, so here // we just do nothing and skip the dependencies. return; } Collection<TypedDependency> dependencies = null; switch (mode) { case BASIC: dependencies = gs.typedDependencies(); // gs.typedDependencies(false); break; case NON_COLLAPSED: dependencies = gs.allTypedDependencies(); // gs.typedDependencies(true); break; case COLLAPSED_WITH_EXTRA: dependencies = gs.typedDependenciesCollapsed(true); break; case COLLAPSED: dependencies = gs.typedDependenciesCollapsed(false); break; case CC_PROPAGATED: dependencies = gs.typedDependenciesCCprocessed(true); break; case CC_PROPAGATED_NO_EXTRA: dependencies = gs.typedDependenciesCCprocessed(false); break; case TREE: dependencies = gs.typedDependenciesCollapsedTree(); break; } for (TypedDependency currTypedDep : dependencies) { int govIndex = currTypedDep.gov().index(); int depIndex = currTypedDep.dep().index(); if (govIndex != 0) { // Stanford CoreNLP produces a dependency relation between a verb and ROOT-0 which // is not token at all! Token govToken = tokens.get(govIndex - 1); Token depToken = tokens.get(depIndex - 1); sfAnnotator.createDependencyAnnotation(currTypedDep.reln(), govToken, depToken); } } }
From source file:edu.iastate.airl.semtus.generator.impl.Generator.java
License:Open Source License
public void process(final ArrayList<Sentence<Word>> sentenceList) { ruleProcessor = new RuleEngine(this); /************************************************************************** * Generate dependencies here/*from w ww . j a va 2 s. co m*/ **************************************************************************/ try { this.generatedTrees = PluginHandler.generateTrees(sentenceList); StructureAnalyzer thisAnalyzer = new StructureAnalyzer(); this.generatedDependencies = new Object[this.generatedTrees.size()][][]; int count = 0; for (Tree thisTree : this.generatedTrees) { // System.out.println(thisTree); GrammaticalStructure thisStructure = thisAnalyzer.analyzeTree(thisTree); Collection<TypedDependency> theseDependencies = thisStructure.allTypedDependencies(); this.generatedDependencies[count] = new Object[theseDependencies.size()][3]; int i = 0; for (TypedDependency thisDependency : theseDependencies) { this.generatedDependencies[count][i][0] = thisDependency.reln().toString(); this.generatedDependencies[count][i][1] = thisDependency.gov().toString().substring(0, thisDependency.gov().toString().indexOf("-")); this.generatedDependencies[count][i][2] = thisDependency.dep().toString().substring(0, thisDependency.dep().toString().indexOf("-")); System.out.println(this.generatedDependencies[count][i][0].toString() + " ( " + this.generatedDependencies[count][i][1].toString() + ", " + this.generatedDependencies[count][i][2].toString() + " )"); i++; } count++; } } catch (IOException excp) { excp.printStackTrace(); } if (this.generatedDependencies == null) { // logger.debug("Failed to parse the sentence"); System.out.println("Failed to parse the sentence"); } this.ruleProcessor.process(this.generatedTrees, this.generatedDependencies); Iterator<Triple> iter = this.tripleList.iterator(); while (iter.hasNext()) { Triple thisTriple = (Triple) iter.next(); generateRDFTriples(thisTriple.getSubjectResourceString(), thisTriple.getObject(), thisTriple.getPredicateStringArray()); } }
From source file:gate.stanford.DependencyMode.java
License:Open Source License
protected static Collection<TypedDependency> getDependencies(GrammaticalStructure gs, DependencyMode mode, boolean includeExtras) { Collection<TypedDependency> result = null; if (mode.equals(Typed)) { result = gs.typedDependencies(includeExtras); } else if (mode.equals(AllTyped)) { result = gs.allTypedDependencies(); } else if (mode.equals(TypedCollapsed)) { result = gs.typedDependenciesCollapsed(includeExtras); } else if (mode.equals(TypedCCprocessed)) { result = gs.typedDependenciesCCprocessed(includeExtras); }//from w w w . ja v a 2s.c om return result; }