parent.addChild(this); stringsToRelations.put(language, sToR); previous = sToR.put(toString(), this); if (!previous.isFromString() && !isFromString()) { throw new IllegalArgumentException("There is already a relation named " + toString() + '!'); } else {
public static void main(String[] args) { final String[] names = {"dep", "pred", "prep_to","rcmod"}; for (String name : names) { GrammaticalRelation reln = valueOf(Language.English, name); System.out.println("Data for GrammaticalRelation loaded as valueOf(\"" + name + "\"):"); System.out.println("\tShort name: " + reln.getShortName()); System.out.println("\tLong name: " + reln.getLongName()); System.out.println("\tSpecific name: " + reln.getSpecific()); } }
private static final GrammaticalRelation getSpecificReln(HashMap<String,GrammaticalRelation> existingRelations, String subtype, GrammaticalRelation parentRelation) { if ( ! existingRelations.containsKey(subtype)) { GrammaticalRelation reln = new GrammaticalRelation(Language.Any, parentRelation.getShortName(), "subtyped " + parentRelation.getLongName(), parentRelation, subtype); existingRelations.put(subtype, reln); } return existingRelations.get(subtype); }
static boolean checkIfSatisfiesRelConstrains(SemanticGraph g, IndexedWord curr, IndexedWord child, List<String> allCutOffRels, GrammaticalRelation rel) { String relName = rel.getShortName(); String relSpecificName = rel.toString(); String relFullName = rel.getLongName(); if(allCutOffRels!=null) for (String check : allCutOffRels) { if (relName.matches(check) || (relSpecificName != null && relSpecificName.matches(check)) || (relFullName != null && relFullName.matches(check))) { return true; } } return false; }
if (typedDep.reln().equals(AUX_PASSIVE_MODIFIER)) { withPassiveAuxiliary.add(typedDep.gov()); if (typedDep.reln().getParent() == NOMINAL_SUBJECT || typedDep.reln().getParent() == SUBJECT || typedDep.reln().getParent() == CLAUSAL_SUBJECT) { if (!subjectMap.containsKey(typedDep.gov())) { subjectMap.put(typedDep.gov(), typedDep); if (typedDep.reln().toString().startsWith("prepc")) { prepcDep.add(typedDep.dep());
String rel = GrammaticalRelation.ROOT.getLongName(); rel = rel.replaceAll("\\s+", ""); // future proofing int source = 0; String rel = edge.getRelation().toString(); rel = rel.replaceAll("\\s+", ""); int source = edge.getSource().index();
@Override public boolean equals(Object o) { if (o instanceof GrammaticalRelation) { return this.getShortName().equals(((GrammaticalRelation)o).getShortName()); } return false; }
private static final boolean isArgument(SemanticGraph sg, SemanticGraphEdge edge) { boolean matches = ARGUMENT_PATTERN.matcher(edge.getRelation().toString()).matches(); if (matches) { for (SemanticGraphEdge edge2 : sg.outgoingEdgeIterable(edge.getDependent())) { if (edge2.getRelation().equals(UniversalEnglishGrammaticalRelations.ORPHAN)) { return false; } } return true; } else { return false; } }
public static GrammaticalRelation valueOf(String s) { return valueOf(Language.Any, s); }
/** Returns whether this is equal to or an ancestor of gr in the grammatical relations hierarchy. */ public boolean isAncestor(GrammaticalRelation gr) { while (gr != null) { // Changed this test from this == gr (mrsmith) if (this.equals(gr)) { return true; } gr = gr.parent; } return false; }
private GrammaticalRelation makeGrammaticalRelation(String label) { GrammaticalRelation stored; switch (language) { case English: stored = EnglishGrammaticalRelations.shortNameToGRel.get(label); if (stored != null) return stored; break; case UniversalEnglish: stored = UniversalEnglishGrammaticalRelations.shortNameToGRel.get(label); if (stored != null) return stored; break; case Chinese: stored = ChineseGrammaticalRelations.shortNameToGRel.get(label); if (stored != null) return stored; break; } return new GrammaticalRelation(language, label, null, GrammaticalRelation.DEPENDENT); }
/** * * Returns a GrammaticalRelation which combines the original relation and * the preposition. * */ private static GrammaticalRelation getCaseMarkedRelation(GrammaticalRelation reln, String relationName) { GrammaticalRelation newReln = reln; if (reln.getSpecific() != null) { reln = reln.getParent(); } if (reln == NOMINAL_MODIFIER) { newReln = UniversalEnglishGrammaticalRelations.getNmod(relationName); } else if (reln == OBLIQUE_MODIFIER) { newReln = UniversalEnglishGrammaticalRelations.getObl(relationName); } else if (reln == ADV_CLAUSE_MODIFIER) { newReln = UniversalEnglishGrammaticalRelations.getAdvcl(relationName); } else if (reln == CLAUSAL_MODIFIER) { newReln = UniversalEnglishGrammaticalRelations.getAcl(relationName); } return newReln; }
GrammaticalRelation reln; synchronized (stringsToRelations) { reln = (stringsToRelations.get(language) != null ? valueOf(s, stringsToRelations.get(language)) : null); specific = null; reln = new GrammaticalRelation(language, name, null, null, specific);
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()); }
if (edge.getRelation().equals(AUX_PASSIVE_MODIFIER)) { withPassiveAuxiliary.add(edge.getGovernor()); if (edge.getRelation().getParent() == NOMINAL_SUBJECT || edge.getRelation().getParent() == SUBJECT || edge.getRelation().getParent() == CLAUSAL_SUBJECT) { if (!subjectMap.containsKey(edge.getGovernor())) { subjectMap.put(edge.getGovernor(), edge); if (edge.getRelation().toString().startsWith("acl:") || edge.getRelation().toString().startsWith("advcl:")) { prepcDep.add(edge.getDependent());
@Override public String toEditString() { StringWriter buf = new StringWriter(); buf.write(LABEL); buf.write("\t"); buf.write(Ssurgeon.RELN_ARG);buf.write(" "); buf.write(relation.toString()); buf.write("\t"); buf.write(Ssurgeon.GOV_NODENAME_ARG);buf.write(" "); buf.write(govName); buf.write("\t"); buf.write(Ssurgeon.DEP_NODENAME_ARG);buf.write(" "); buf.write(depName); return buf.toString(); }
static boolean checkIfSatisfiesRelConstrains(SemanticGraph g, IndexedWord curr, IndexedWord child, List<String> allCutOffRels, GrammaticalRelation rel) { String relName = rel.getShortName(); String relSpecificName = rel.toString(); String relFullName = rel.getLongName(); if(allCutOffRels!=null) for (String check : allCutOffRels) { if (relName.matches(check) || (relSpecificName != null && relSpecificName.matches(check)) || (relFullName != null && relFullName.matches(check))) { return true; } } return false; }
String rel = GrammaticalRelation.ROOT.getLongName(); rel = rel.replaceAll("\\s+", ""); // future proofing int source = 0; String rel = edge.getRelation().toString(); rel = rel.replaceAll("\\s+", ""); int source = edge.getSource().index();
/** * * Returns a GrammaticalRelation which combines the original relation and * the preposition. * */ private static GrammaticalRelation getCaseMarkedRelation(GrammaticalRelation reln, String relationName) { GrammaticalRelation newReln = reln; if (reln.getShortName().equals("nmod")) { newReln = UniversalGrammaticalRelations.getNmod(relationName); } else if (reln.getShortName().equals("obl")) { newReln = UniversalGrammaticalRelations.getObl(relationName); } else if (reln.getShortName().equals("advcl")) { newReln = UniversalGrammaticalRelations.getAdvcl(relationName); } else if (reln.getShortName().equals("acl")) { newReln = UniversalGrammaticalRelations.getAcl(relationName); } return newReln; }