@Override public boolean test(TypedDependency d) { return d != null && d.reln() != RELATIVE; }
/** * Alters a list in place by removing all the KILL relations */ private static void filterKill(Collection<TypedDependency> deps) { List<TypedDependency> filtered = Generics.newArrayList(); for (TypedDependency dep : deps) { if (dep.reln() != KILL) { filtered.add(dep); } } deps.clear(); deps.addAll(filtered); }
private static String toReadableString(Collection<TypedDependency> dependencies) { StringBuilder buf = new StringBuilder(); buf.append(String.format("%-20s%-20s%-20s%n", "dep", "reln", "gov")); buf.append(String.format("%-20s%-20s%-20s%n", "---", "----", "---")); for (TypedDependency td : dependencies) { buf.append(String.format("%-20s%-20s%-20s%n", td.dep(), td.reln(), td.gov())); } return buf.toString(); }
/** * This method gets rid of multiwords in conjunctions to avoid having them * creating disconnected constituents e.g., * "bread-1 as-2 well-3 as-4 cheese-5" will be turned into conj_and(bread, * cheese) and then dep(well-3, as-2) and dep(well-3, as-4) cannot be attached * to the graph, these dependencies are erased * * @param list List of words to get rid of multiword conjunctions from */ private static void eraseMultiConj(Collection<TypedDependency> list) { // find typed deps of form cc(gov, x) for (TypedDependency td1 : list) { if (td1.reln() == COORDINATION) { IndexedWord x = td1.dep(); // find typed deps of form dep(x,y) and kill them for (TypedDependency td2 : list) { if (td2.gov().equals(x) && (td2.reln() == DEPENDENT || td2.reln() == MULTI_WORD_EXPRESSION || td2.reln() == COORDINATION || td2.reln() == ADVERBIAL_MODIFIER || td2.reln() == NEGATION_MODIFIER || td2.reln() == AUX_MODIFIER)) { td2.setReln(KILL); } } } } filterKill(list); }
public static List<Collection<TypedDependency>> convertStringEquality(List<Collection<TypedDependency>> deps){ List<Collection<TypedDependency>> convertedDeps = new ArrayList<>(); for(Collection<TypedDependency> depSet : deps){ Collection<TypedDependency> converted = Generics.newHashSet(); for(TypedDependency dep : depSet){ converted.add(new TypedDependencyStringEquality(dep.reln(), dep.gov(), dep.dep())); } convertedDeps.add(converted); } return convertedDeps; }
private static List<Set<TypedDependency>> toSets(Collection<TypedDependency> depCollection) { Set<TypedDependency> depSet = Generics.newHashSet(); Set<TypedDependency> unlabeledDepSet = Generics.newHashSet(); for (TypedDependency dep : depCollection) { unlabeledDepSet.add(new TypedDependencyStringEquality(null, dep.gov(), dep.dep())); depSet.add(new TypedDependencyStringEquality(dep.reln(), dep.gov(), dep.dep())); } List<Set<TypedDependency>> l = new ArrayList<>(2); l.add(depSet); l.add(unlabeledDepSet); return l; }
/** * Given a list of typedDependencies, returns true if the node "node" is the * governor of a conj relation with a dependent which is not a preposition * * @param node * A node in this GrammaticalStructure * @param list * A list of typedDependencies * @return true If node is the governor of a conj relation in the list with * the dep not being a preposition */ private static boolean isConjWithNoPrep(IndexedWord node, Collection<TypedDependency> list) { for (TypedDependency td : list) { if (td.gov().equals(node) && td.reln() == CONJUNCT) { // we have a conjunct // check the POS of the dependent String tdDepPOS = td.dep().tag(); if (!(tdDepPOS.equals("IN") || tdDepPOS.equals("TO"))) { return true; } } } return false; }
prepRels.addAll(EnglishGrammaticalRelations.getPrepsC()); for (TypedDependency td1 : list) { if (prepRels.contains(td1.reln())) { // if we have a prep_ relation IndexedWord gov = td1.gov(); IndexedWord dep = td1.dep(); if (td2.reln() == DEPENDENT && td2.gov().equals(gov) && td2.dep().equals(dep)) { td2.setReln(KILL); if (td.reln() == KILL) { if (DEBUG) { log.info("Removing duplicate relation: " + td);
List<TypedDependency> newDeps = null; for (TypedDependency rcmod : list) { if (rcmod.reln() != RELATIVE_CLAUSE_MODIFIER) { continue; if (connected.gov().equals(rcmod.dep()) && (connected.reln() == XCLAUSAL_COMPLEMENT || connected.reln() == CONJUNCT)) { depNodes.add(connected.dep()); if (!prep.gov().equals(dep) || prep.reln() != PREPOSITIONAL_MODIFIER) { continue; if (other.gov().equals(prep.dep()) && (other.reln() == PREPOSITIONAL_COMPLEMENT || other.reln() == PREPOSITIONAL_OBJECT)) { found = true; break;
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; } }
private static String toStringIndex(TypedDependency td, Map<Integer, Integer> indexToPos) { IndexedWord gov = td.gov(); IndexedWord dep = td.dep(); return td.reln() + "(" + gov.value() + "-" + indexToPos.get(gov.index()) + gov.toPrimes() + ", " + dep.value() + "-" + indexToPos.get(dep.index()) + dep.toPrimes() + ")"; }
private static String toXMLString(Collection<TypedDependency> dependencies, boolean includeTags) { StringBuilder buf = new StringBuilder("<dependencies style=\"typed\">\n"); for (TypedDependency td : dependencies) { String reln = td.reln().toString(); String gov = td.gov().value(); String govTag = td.gov().tag();
String lemma = token.lemma() != null ? token.lemma() : "_"; Integer gov = indexedDeps.containsKey(idx) ? indexedDeps.get(idx).gov().index() : 0; String reln = indexedDeps.containsKey(idx) ? indexedDeps.get(idx).reln().toString() : "erased"; String out = String.format("%d\t%s\t%s\t%s\t%s\t_\t%d\t%s\t_\t_\n", idx, word, lemma, cPos, pos, gov, reln); bf.append(out);
if (aux_pass_poss != null) { for (TypedDependency td_pass : aux_pass_poss) { if (td_pass.reln() == AUX_PASSIVE_MODIFIER) { agent = true;
/** * 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); }
public int compareTo(TypedDependency tdArg) { IndexedWord depArg = tdArg.dep(); IndexedWord depThis = this.dep(); int indexArg = depArg.index(); int indexThis = depThis.index(); if (indexThis > indexArg) { return 1; } else if (indexThis < indexArg) { return -1; } // dependent indices are equal, check governor int govIndexArg = tdArg.gov().index(); int govIndexThis = this.gov().index(); if (govIndexThis > govIndexArg) { return 1; } else if (govIndexThis < govIndexArg) { return -1; } // dependent and governor indices equal, the relation decides return this.reln().compareTo(tdArg.reln()); }
/** * This is the constructor used by the parser. */ public SemanticGraph(Collection<TypedDependency> dependencies) { graph = new DirectedMultiGraph<>(outerMapFactory, innerMapFactory); roots = wordMapFactory.newSet(); for (TypedDependency d : dependencies) { IndexedWord gov = d.gov(); IndexedWord dep = d.dep(); GrammaticalRelation reln = d.reln(); if (reln != ROOT) { // the root relation only points to the root: the governor is a fake node that we don't want to add in the graph // It is unnecessary to call addVertex, since addEdge will // implicitly add vertices if needed //addVertex(gov); //addVertex(dep); addEdge(gov, dep, reln, Double.NEGATIVE_INFINITY, d.extra()); } else { //it's the root and we add it addVertex(dep); roots.add(dep); } } // there used to be an if clause that filtered out the case of empty // dependencies. However, I could not understand (or replicate) the error // it alluded to, and it led to empty dependency graphs for very short // fragments, // which meant they were ignored by the RTE system. Changed. (pado) // See also SemanticGraphFactory.makeGraphFromTree(). }