protected static GrammaticalRelation generalizeRelation(GrammaticalRelation gr) { final GrammaticalRelation[] GENERAL_RELATIONS = { EnglishGrammaticalRelations.SUBJECT, EnglishGrammaticalRelations.COMPLEMENT, EnglishGrammaticalRelations.CONJUNCT, EnglishGrammaticalRelations.MODIFIER, }; for (GrammaticalRelation generalGR : GENERAL_RELATIONS) { if (generalGR.isAncestor(gr)) { return generalGR; } } return gr; }
private static List<GrammaticalRelation> removeGrammaticalRelationAncestors(List<GrammaticalRelation> original) { List<GrammaticalRelation> filtered = Generics.newArrayList(); for (GrammaticalRelation reln : original) { boolean descendantFound = false; for (int index = 0; index < filtered.size(); ++index) { GrammaticalRelation gr = filtered.get(index); //if the element in the list is an ancestor of the current //relation, remove it (we will replace it later) if (gr.isAncestor(reln)) { filtered.remove(index); --index; } else if (reln.isAncestor(gr)) { //if the relation is not an ancestor of an element in the //list, we add the relation descendantFound = true; } } if (!descendantFound) { filtered.add(reln); } } return filtered; }
/** * Returns true if {@code word} has an inflection of "be" as an auxiliary. */ private static boolean hasBeAux(SemanticGraph sg, IndexedWord word) { for (IndexedWord aux : sg.getChildrenWithReln(word, UniversalEnglishGrammaticalRelations.AUX_MODIFIER)) { if (aux.value().matches(BE_REGEX)) { return true; } } /* Check if head of conjunction has an auxiliary in case the word is part of a conjunction */ IndexedWord gov = sg.getParent(word); if (gov != null) { SemanticGraphEdge edge = sg.getEdge(gov, word); if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation())) { return hasBeAux(sg, gov); } } return false; }
if (reln.isAncestor(reln2)) { reln = reln2; } else if (PRINT_DEBUGGING && ! reln2.isAncestor(reln)) { log.info("@@@\t" + reln + "\t" + reln2 + "\t" + govH.get(CoreAnnotations.ValueAnnotation.class) + "\t" + depH.get(CoreAnnotations.ValueAnnotation.class));
/** * Returns true if {@code word} has an auxiliary verb attached to it. * */ @SuppressWarnings("unused") private static boolean hasAux(SemanticGraph sg, IndexedWord word) { if (sg.hasChildWithReln(word, UniversalEnglishGrammaticalRelations.AUX_MODIFIER)) { return true; } IndexedWord gov = sg.getParent(word); if (gov != null) { SemanticGraphEdge edge = sg.getEdge(gov, word); if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation()) || UniversalEnglishGrammaticalRelations.COPULA.equals(edge.getRelation())) { return hasAux(sg, gov); } } return false; }
if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation())) {
/** * Determine the case of the pronoun "you" or "it". */ private static String pronounCase(SemanticGraph sg, IndexedWord word) { word = sg.getNodeByIndex(word.index()); IndexedWord parent = sg.getParent(word); if (parent != null) { SemanticGraphEdge edge = sg.getEdge(parent, word); if (edge != null) { if (edge.getRelation().equals(UniversalEnglishGrammaticalRelations.DIRECT_OBJECT) || edge.getRelation().equals(UniversalEnglishGrammaticalRelations.INDIRECT_OBJECT)) { /* "you" is an object. */ return "Acc"; } else if (UniversalEnglishGrammaticalRelations.NOMINAL_MODIFIER.isAncestor(edge.getRelation()) || edge.getRelation() == GrammaticalRelation.ROOT) { if (sg.hasChildWithReln(word, UniversalEnglishGrammaticalRelations.CASE_MARKER)) { /* "you" is the head of a prepositional phrase. */ return "Acc"; } } } } return "Nom"; }
protected static GrammaticalRelation generalizeRelation(GrammaticalRelation gr) { final GrammaticalRelation[] GENERAL_RELATIONS = { EnglishGrammaticalRelations.SUBJECT, EnglishGrammaticalRelations.COMPLEMENT, EnglishGrammaticalRelations.CONJUNCT, EnglishGrammaticalRelations.MODIFIER, }; for (GrammaticalRelation generalGR : GENERAL_RELATIONS) { if (generalGR.isAncestor(gr)) { return generalGR; } } return gr; }
private static GrammaticalRelation generalizeRelation(GrammaticalRelation gr) { final GrammaticalRelation[] GENERAL_RELATIONS = { EnglishGrammaticalRelations.SUBJECT, EnglishGrammaticalRelations.COMPLEMENT, EnglishGrammaticalRelations.CONJUNCT, EnglishGrammaticalRelations.MODIFIER, }; for (GrammaticalRelation generalGR : GENERAL_RELATIONS) { if (generalGR.isAncestor(gr)) { return generalGR; } } if (gr.equals(EnglishGrammaticalRelations.CONTROLLING_SUBJECT)) { return EnglishGrammaticalRelations.SUBJECT; } return gr; }
private static List<GrammaticalRelation> removeGrammaticalRelationAncestors(List<GrammaticalRelation> original) { List<GrammaticalRelation> filtered = Generics.newArrayList(); for (GrammaticalRelation reln : original) { boolean descendantFound = false; for (int index = 0; index < filtered.size(); ++index) { GrammaticalRelation gr = filtered.get(index); //if the element in the list is an ancestor of the current //relation, remove it (we will replace it later) if (gr.isAncestor(reln)) { filtered.remove(index); --index; } else if (reln.isAncestor(gr)) { //if the relation is not an ancestor of an element in the //list, we add the relation descendantFound = true; } } if (!descendantFound) { filtered.add(reln); } } return filtered; }
private static List<GrammaticalRelation> removeGrammaticalRelationAncestors(List<GrammaticalRelation> original) { List<GrammaticalRelation> filtered = Generics.newArrayList(); for (GrammaticalRelation reln : original) { boolean descendantFound = false; for (int index = 0; index < filtered.size(); ++index) { GrammaticalRelation gr = filtered.get(index); //if the element in the list is an ancestor of the current //relation, remove it (we will replace it later) if (gr.isAncestor(reln)) { filtered.remove(index); --index; } else if (reln.isAncestor(gr)) { //if the relation is not an ancestor of an element in the //list, we add the relation descendantFound = true; } } if (!descendantFound) { filtered.add(reln); } } return filtered; }
GrammaticalRelation gr = list.get(i); if (gr.isAncestor(reln2)) { int index = list.indexOf(gr); list.set(index, reln2); else if (!reln2.isAncestor(gr)) { list.add(reln2);
if (gr.isAncestor(reln)) { list.remove(index); --index; } else if (reln.isAncestor(gr)) {
if (reln.isAncestor(reln2)) { reln = reln2; } else if (PRINT_DEBUGGING && ! reln2.isAncestor(reln)) { System.err.println("@@@\t" + reln + "\t" + reln2 + "\t" + govH.label().get(CoreAnnotations.ValueAnnotation.class) + "\t" + depH.label().get(CoreAnnotations.ValueAnnotation.class));
/** * Determine the case of the pronoun "you" or "it". */ private static String pronounCase(SemanticGraph sg, IndexedWord word) { word = sg.getNodeByIndex(word.index()); IndexedWord parent = sg.getParent(word); if (parent != null) { SemanticGraphEdge edge = sg.getEdge(parent, word); if (edge != null) { if (UniversalEnglishGrammaticalRelations.OBJECT.isAncestor(edge.getRelation())) { /* "you" is an object. */ return "Acc"; } else if (UniversalEnglishGrammaticalRelations.NOMINAL_MODIFIER.isAncestor(edge.getRelation()) || edge.getRelation() == GrammaticalRelation.ROOT) { if (sg.hasChildWithReln(word, UniversalEnglishGrammaticalRelations.CASE_MARKER)) { /* "you" is the head of a prepositional phrase. */ return "Acc"; } } } } return "Nom"; }
/** * Returns true if {@code word} has an inflection of "be" as an auxiliary. */ private static boolean hasBeAux(SemanticGraph sg, IndexedWord word) { for (IndexedWord aux : sg.getChildrenWithReln(word, UniversalEnglishGrammaticalRelations.AUX_MODIFIER)) { if (aux.value().matches(BE_REGEX)) { return true; } } /* Check if head of conjunction has an auxiliary in case the word is part of a conjunction */ IndexedWord gov = sg.getParent(word); if (gov != null) { SemanticGraphEdge edge = sg.getEdge(gov, word); if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation())) { return hasBeAux(sg, gov); } } return false; }
if (reln.isAncestor(reln2)) { reln = reln2; } else if (PRINT_DEBUGGING && ! reln2.isAncestor(reln)) { log.info("@@@\t" + reln + "\t" + reln2 + "\t" + govH.get(CoreAnnotations.ValueAnnotation.class) + "\t" + depH.get(CoreAnnotations.ValueAnnotation.class));
if (reln.isAncestor(reln2)) { reln = reln2; } else if (PRINT_DEBUGGING && ! reln2.isAncestor(reln)) { log.info("@@@\t" + reln + "\t" + reln2 + "\t" + govH.get(CoreAnnotations.ValueAnnotation.class) + "\t" + depH.get(CoreAnnotations.ValueAnnotation.class));
/** * Returns true if {@code word} has an auxiliary verb attached to it. * */ @SuppressWarnings("unused") private static boolean hasAux(SemanticGraph sg, IndexedWord word) { if (sg.hasChildWithReln(word, UniversalEnglishGrammaticalRelations.AUX_MODIFIER)) { return true; } IndexedWord gov = sg.getParent(word); if (gov != null) { SemanticGraphEdge edge = sg.getEdge(gov, word); if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation()) || UniversalEnglishGrammaticalRelations.COPULA.equals(edge.getRelation())) { return hasAux(sg, gov); } } return false; }
if (UniversalEnglishGrammaticalRelations.CONJUNCT.isAncestor(edge.getRelation())) {