/** * Construct a new {@code GrammaticalStructure} from an existing parse * tree. The new {@code GrammaticalStructure} has the same tree structure * and label values as the given tree (but no shared storage). As part of * construction, the parse tree is analyzed using definitions from * {@link GrammaticalRelation {@code GrammaticalRelation}} to populate * the new {@code GrammaticalStructure} with as many labeled grammatical * relations as it can. * * Once upon a time this method had an extra parameter as to whether to operate * in a threadsafe manner. We decided that that was a really bad idea, and this * method now always acts in a threadsafe manner. * This method gets used by GrammaticalStructureFactory (by reflection). DON'T DELETE. * * @param t Parse tree to make grammatical structure from * @param puncFilter Filter for punctuation words * @param hf HeadFinder to use when building it */ public EnglishGrammaticalStructure(Tree t, Predicate<String> puncFilter, HeadFinder hf) { // the tree is normalized (for index and functional tag stripping) inside CoordinationTransformer super(t, EnglishGrammaticalRelations.values(), EnglishGrammaticalRelations.valuesLock(), new CoordinationTransformer(hf), hf, puncFilter, Filters.acceptFilter()); }
GrammaticalRelation rel = EnglishGrammaticalRelations.valueOf(toString()); if (rel == null) { switch (shortName) { case "conj": return EnglishGrammaticalRelations.getConj(specific); case "prep": return EnglishGrammaticalRelations.getPrep(specific); case "prepc": return EnglishGrammaticalRelations.getPrepC(specific); default:
if (EnglishGrammaticalRelations.getConjs().contains(td.reln())) { IndexedWord gov = td.gov(); IndexedWord dep = td.dep();
/** * The "prep" grammatical relation. Used to collapse prepositions.<p> * They will be turned into prep_word, where "word" is a preposition * * @param prepositionString The preposition to make a GrammaticalRelation out of * @return A grammatical relation for this preposition */ public static GrammaticalRelation getPrep(String prepositionString) { GrammaticalRelation result = preps.get(prepositionString); if (result == null) { synchronized(preps) { result = preps.get(prepositionString); if (result == null) { result = new GrammaticalRelation(Language.English, "prep", "prep_collapsed", PREPOSITIONAL_MODIFIER, prepositionString); preps.put(prepositionString, result); threadSafeAddRelation(result); } } } return result; }
/** * Returns an EnglishGrammaticalRelation based on the argument. * It works if passed a GrammaticalRelation or the String * representation of one (e.g., "nsubj"). It returns {@code null} * for other classes or if no string match is found. * * @param o A GrammaticalRelation or String * @return The EnglishGrammaticalRelation with that name */ @SuppressWarnings("unchecked") public static GrammaticalRelation valueOf(Object o) { if (o instanceof GrammaticalRelation) { return (GrammaticalRelation) o; } else if (o instanceof String) { return valueOf((String) o); } else { return null; } }
/** * Does some hard coding to deal with relation in CONJP. For now we deal with: * but not, if not, instead of, rather than, but rather GO TO negcc <br> * as well as, not to mention, but also, & GO TO and. * * @param conj The head dependency of the conjunction marker * @return A GrammaticalRelation made from a normalized form of that * conjunction. */ private static GrammaticalRelation conjValue(String conj) { String newConj = conj.toLowerCase(); if (newConj.equals("not") || newConj.equals("instead") || newConj.equals("rather")) { newConj = "negcc"; } else if (newConj.equals("mention") || newConj.equals("to") || newConj.equals("also") || newConj.contains("well") || newConj.equals("&")) { newConj = "and"; } return EnglishGrammaticalRelations.getConj(newConj); }
public static List<GrammaticalRelation> values() { return values(false); }
/** * Returns the EnglishGrammaticalRelation having the given string * representation (e.g. "nsubj"), or null if no such is found. * * @param s The short name of the GrammaticalRelation * @return The EnglishGrammaticalRelation with that name */ public static GrammaticalRelation valueOf(String s) { return GrammaticalRelation.valueOf(s, synchronizedValues, valuesLock()); // // TODO does this need to be changed? // // modification NOTE: do not commit until go-ahead // // If this is a collapsed relation (indicated by a "_" separating // // the type and the dependent, instantiate a collapsed version. // // Currently handcode against conjunctions and prepositions, but // // should do this in a more robust fashion. // String[] tuples = s.trim().split("_", 2); // if (tuples.length == 2) { // String reln = tuples[0]; // String specific = tuples[1]; // if (reln.equals(PREPOSITIONAL_MODIFIER.getShortName())) { // return getPrep(specific); // } else if (reln.equals(CONJUNCT.getShortName())) { // return getConj(specific); // } // } // // return null; }
pobj = td2; GrammaticalRelation gr = EnglishGrammaticalRelations.getPrep(mwp[0] + '_' + mwp[1]); newTypedDeps.add(new TypedDependency(gr, governor, pobj.dep())); pobj = td2; GrammaticalRelation gr = EnglishGrammaticalRelations.getPrepC(mwp[0] + '_' + mwp[1]); newTypedDeps.add(new TypedDependency(gr, governor, pobj.dep()));
/** * The "prepc" grammatical relation. Used to collapse preposition * complements.<p> * They will be turned into prep_word, where "word" is a preposition * * @param prepositionString The preposition to make a GrammaticalRelation out of * @return A grammatical relation for this preposition */ public static GrammaticalRelation getPrepC(String prepositionString) { GrammaticalRelation result = prepsC.get(prepositionString); if (result == null) { synchronized(prepsC) { result = prepsC.get(prepositionString); if (result == null) { result = new GrammaticalRelation(Language.English, "prepc", "prepc_collapsed", DEPENDENT, prepositionString); prepsC.put(prepositionString, result); threadSafeAddRelation(result); } } } return result; }
public static AddEdge createEngAddEdge(String govName, String depName, String engRelnName) { GrammaticalRelation reln = EnglishGrammaticalRelations.valueOf(engRelnName); return new AddEdge(govName, depName, reln); }
/** * Does some hard coding to deal with relation in CONJP. For now we deal with: * but not, if not, instead of, rather than, but rather GO TO negcc <br> * as well as, not to mention, but also, & GO TO and. * * @param conj The head dependency of the conjunction marker * @return A GrammaticalRelation made from a normalized form of that * conjunction. */ private static GrammaticalRelation conjValue(String conj) { String newConj = conj.toLowerCase(); if (newConj.equals("not") || newConj.equals("instead") || newConj.equals("rather")) { newConj = "negcc"; } else if (newConj.equals("mention") || newConj.equals("to") || newConj.equals("also") || newConj.contains("well") || newConj.equals("&")) { newConj = "and"; } return EnglishGrammaticalRelations.getConj(newConj); }
public static List<GrammaticalRelation> values() { return values(false); }
/** * Returns the EnglishGrammaticalRelation having the given string * representation (e.g. "nsubj"), or null if no such is found. * * @param s The short name of the GrammaticalRelation * @return The EnglishGrammaticalRelation with that name */ public static GrammaticalRelation valueOf(String s) { return GrammaticalRelation.valueOf(s, synchronizedValues, valuesLock()); // // TODO does this need to be changed? // // modification NOTE: do not commit until go-ahead // // If this is a collapsed relation (indicated by a "_" separating // // the type and the dependent, instantiate a collapsed version. // // Currently handcode against conjunctions and prepositions, but // // should do this in a more robust fashion. // String[] tuples = s.trim().split("_", 2); // if (tuples.length == 2) { // String reln = tuples[0]; // String specific = tuples[1]; // if (reln.equals(PREPOSITIONAL_MODIFIER.getShortName())) { // return getPrep(specific); // } else if (reln.equals(CONJUNCT.getShortName())) { // return getConj(specific); // } // } // // return null; }
pobj = td2; GrammaticalRelation gr = EnglishGrammaticalRelations.getPrep(mwp[0] + '_' + mwp[1]); newtd = new TypedDependency(gr, governor, pobj.dep()); pobj = td2; GrammaticalRelation gr = EnglishGrammaticalRelations.getPrepC(mwp[0] + '_' + mwp[1]); newtd = new TypedDependency(gr, governor, pobj.dep());