/** * Returns the typed dependencies of this grammatical structure. These * are the basic word-level typed dependencies, where each word is dependent * on one other thing, either a word or the starting ROOT, and the * dependencies have a tree structure. This corresponds to the * command-line option "basicDependencies". * * @return The typed dependencies of this grammatical structure */ public Collection<TypedDependency> typedDependencies() { return typedDependencies(Extras.NONE); }
break; case BASIC: deps = gs.typedDependencies(includeExtras); break; default:
GrammaticalStructure gs = gsf.newGrammaticalStructure(outputTree); if (basicDependencies) { print(gs.typedDependencies(), "xml", includeTags, pw); GrammaticalStructure gs = gsf.newGrammaticalStructure(outputTree); if (basicDependencies) { print(gs.typedDependencies(), includeTags, pw);
Collection<TypedDependency> bungRoots = null; System.out.println("------------- basic dependencies ---------------"); List<TypedDependency> gsb = gs.typedDependencies(GrammaticalStructure.Extras.NONE); System.out.println(StringUtils.join(gsb, "\n")); connected = GrammaticalStructure.isConnected(gsb); List<TypedDependency> gse = gs.typedDependencies(GrammaticalStructure.Extras.MAXIMAL); System.out.println(StringUtils.join(gse, "\n")); connected = GrammaticalStructure.isConnected(gse); printDependencies(gs, gs.typedDependencies(GrammaticalStructure.Extras.NONE), tree, conllx, false, opts.convertToUPOS); } else { System.out.println(altDepPrinter.dependenciesToString(gs, gs.typedDependencies(GrammaticalStructure.Extras.NONE), tree));
/** * Returns all the typed dependencies of this grammatical structure. * These are like the basic (uncollapsed) dependencies, but may include * extra arcs for control relationships, etc. This corresponds to the * "nonCollapsed" option. */ public Collection<TypedDependency> allTypedDependencies() { return typedDependencies(Extras.MAXIMAL); }
/** * @see edu.stanford.nlp.trees.GrammaticalStructure#typedDependencies(edu.stanford.nlp.trees.GrammaticalStructure.Extras) */ @Deprecated public List<TypedDependency> typedDependencies(boolean includeExtras) { return typedDependencies(includeExtras ? Extras.MAXIMAL : Extras.NONE); }
public List<TypedDependency> typedDependenciesEnhanced() { List<TypedDependency> tdl = typedDependencies(Extras.MAXIMAL); addEnhancements(tdl, UniversalEnglishGrammaticalStructure.ENHANCED_OPTIONS); return tdl; }
public List<TypedDependency> typedDependenciesEnhancedPlusPlus() { List<TypedDependency> tdl = typedDependencies(Extras.MAXIMAL); addEnhancements(tdl, UniversalEnglishGrammaticalStructure.ENHANCED_PLUS_PLUS_OPTIONS); return tdl; }
/** * Calls dependenciesToCoNLLXString with the basic dependencies * from a grammatical structure. * * (see {@link #dependenciesToCoNLLXString(Collection, CoreMap)}) */ public static String dependenciesToCoNLLXString(GrammaticalStructure gs, CoreMap sentence) { return dependenciesToCoNLLXString(gs.typedDependencies(), sentence); }
/** * Get the typed dependencies after collapsing them. * The "collapsed" option corresponds to calling this method with argument * {@code true}. * * @param includeExtras If true, the list of typed dependencies * returned may include "extras", like controlling subjects * @return collapsed dependencies */ public List<TypedDependency> typedDependenciesCollapsed(Extras includeExtras) { List<TypedDependency> tdl = typedDependencies(includeExtras); collapseDependencies(tdl, false, includeExtras); return tdl; }
/** * Get the typed dependencies after mostly collapsing them, but keep a tree * structure. In order to do this, the code does: * <ol> * <li> no relative clause processing * <li> no xsubj relations * <li> no propagation of conjuncts * </ol> * This corresponds to the "tree" option. * * @return collapsed dependencies keeping a tree structure */ public Collection<TypedDependency> typedDependenciesCollapsedTree() { List<TypedDependency> tdl = typedDependencies(Extras.NONE); collapseDependenciesTree(tdl); return tdl; }
/** * Get the typed dependencies after collapsing them and processing eventual * CC complements. The effect of this part is to distributed conjoined * arguments across relations or conjoined predicates across their arguments. * This is generally useful, and we generally recommend using the output of * this method with the second argument being {@code true}. * The "CCPropagated" option corresponds to calling this method with an * argument of {@code true}. * * @param includeExtras If true, the list of typed dependencies * returned may include "extras", such as controlled subject links. * @return collapsed dependencies with CC processed */ public List<TypedDependency> typedDependenciesCCprocessed(Extras includeExtras) { List<TypedDependency> tdl = typedDependencies(includeExtras); collapseDependencies(tdl, true, includeExtras); return tdl; }
/** * Read in typed dependencies in CoNLLX format. * * @param filename * @throws IOException */ static protected List<Collection<TypedDependency>> readDepsCoNLLX(String filename) throws IOException { List<GrammaticalStructure> gss = GrammaticalStructure.readCoNLLXGrammaticalStructureCollection(filename, new fakeShortNameToGRel(), new GraphLessGrammaticalStructureFactory()); List<Collection<TypedDependency>> readDeps = new ArrayList<>(gss.size()); for (GrammaticalStructure gs : gss) { Collection<TypedDependency> deps = gs.typedDependencies(); readDeps.add(deps); } return readDeps; }
private List<Dependency<Label, Label, Object>> getSortedDeps(Tree tree, Predicate<Dependency<Label, Label, Object>> filter) { if (gsf != null) { GrammaticalStructure gs = gsf.newGrammaticalStructure(tree); Collection<TypedDependency> deps = gs.typedDependencies(GrammaticalStructure.Extras.NONE); List<Dependency<Label, Label, Object>> sortedDeps = new ArrayList<>(); for (TypedDependency dep : deps) { sortedDeps.add(new NamedDependency(dep.gov(), dep.dep(), dep.reln().toString())); } Collections.sort(sortedDeps, Dependencies.dependencyIndexComparator()); return sortedDeps; } else { Set<Dependency<Label, Label, Object>> depsSet = tree.mapDependencies(filter, hf, "root"); List<Dependency<Label, Label, Object>> sortedDeps = new ArrayList<>(depsSet); Collections.sort(sortedDeps, Dependencies.dependencyIndexComparator()); return sortedDeps; } }
/** * Get GrammaticalRelation between gov and dep, and null if gov is not the * governor of dep. */ public GrammaticalRelation getGrammaticalRelation(IndexedWord gov, IndexedWord dep) { List<GrammaticalRelation> labels = Generics.newArrayList(); for (TypedDependency dependency : typedDependencies(Extras.MAXIMAL)) { if (dependency.gov().equals(gov) && dependency.dep().equals(dep)) { labels.add(dependency.reln()); } } return getGrammaticalRelationCommonAncestor(gov, gov, dep, dep, labels); }
private void parseTextFile(BufferedReader input, PrintWriter output) { DocumentPreprocessor preprocessor = new DocumentPreprocessor(input); preprocessor.setSentenceFinalPuncWords(config.tlp.sentenceFinalPunctuationWords()); preprocessor.setEscaper(config.escaper); preprocessor.setSentenceDelimiter(config.sentenceDelimiter); preprocessor.setTokenizerFactory(config.tlp.getTokenizerFactory()); Timing timer = new Timing(); MaxentTagger tagger = new MaxentTagger(config.tagger); List<List<TaggedWord>> tagged = new ArrayList<>(); for (List<HasWord> sentence : preprocessor) { tagged.add(tagger.tagSentence(sentence)); } log.info(String.format("Tagging completed in %.2f sec.%n", timer.stop() / 1000.0)); timer.start(); int numSentences = 0; for (List<TaggedWord> taggedSentence : tagged) { GrammaticalStructure parse = predict(taggedSentence); Collection<TypedDependency> deps = parse.typedDependencies(); for (TypedDependency dep : deps) output.println(dep); output.println(); numSentences++; } long millis = timer.stop(); double seconds = millis / 1000.0; log.info(String.format("Parsed %d sentences in %.2f seconds (%.2f sents/sec).%n", numSentences, seconds, numSentences / seconds)); }
/** * Returns the typed dependencies of this grammatical structure. These * are the basic word-level typed dependencies, where each word is dependent * on one other thing, either a word or the starting ROOT, and the * dependencies have a tree structure. This corresponds to the * command-line option "basicDependencies". * * @return The typed dependencies of this grammatical structure */ public Collection<TypedDependency> typedDependencies() { return typedDependencies(false); }
/** * Returns all the typed dependencies of this grammatical structure. * These are like the basic (uncollapsed) dependencies, but may include * extra arcs for control relationships, etc. This corresponds to the * "nonCollapsed" option. */ public Collection<TypedDependency> allTypedDependencies() { return typedDependencies(true); }
/** * Returns the typed dependencies of this grammatical structure. These * are basic word-level typed dependencies, where each word other than the * root of the sentence is dependent on one other word, and the * dependencies have a tree structure. * * @return The typed dependencies of this grammatical structure */ public Collection<TypedDependency> typedDependencies() { return typedDependencies(false); }
/** * @see edu.stanford.nlp.trees.GrammaticalStructure#typedDependencies(edu.stanford.nlp.trees.GrammaticalStructure.Extras) */ @Deprecated public List<TypedDependency> typedDependencies(boolean includeExtras) { return typedDependencies(includeExtras ? Extras.MAXIMAL : Extras.NONE); }