private static void addPassiveAgentToReln(SemanticGraph sg, IndexedWord gov, IndexedWord mod, IndexedWord caseMarker) { SemanticGraphEdge edge = sg.getEdge(gov, mod); GrammaticalRelation reln = UniversalEnglishGrammaticalRelations.AGENT; edge.setRelation(reln); }
private static void addCaseMarkersToReln(SemanticGraph sg, IndexedWord gov, IndexedWord mod, IndexedWord caseMarker) { SemanticGraphEdge edge = sg.getEdge(gov, mod); List<IndexedWord> caseMarkers = new ArrayList<>(); caseMarkers.add(caseMarker); sg.getChildrenWithReln(caseMarker, FIXED).stream().forEach(iw -> caseMarkers.add(iw)); Collections.sort(caseMarkers); String relnName = StringUtils.join(caseMarkers.stream().map(iw->iw.lemma()), "_"); if (relnName.matches("[^a-zA-Z_]")) { return; } //for Joakim //GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), relnName.toLowerCase() + ":ENH_CASE"); GrammaticalRelation reln = getCaseMarkedRelation(edge.getRelation(), relnName.toLowerCase()); edge.setRelation(reln); }
/** * Extracts features from relative and interrogative pronouns. */ private static HashMap<String, String> getRelAndIntPronFeatures(SemanticGraph sg, IndexedWord word) { HashMap<String, String> features = new HashMap<>(); if (word.tag().startsWith("W")) { boolean isRel = false; IndexedWord parent = sg.getParent(word); if (parent != null) { IndexedWord parentParent = sg.getParent(parent); if (parentParent != null) { SemanticGraphEdge edge = sg.getEdge(parentParent, parent); isRel = edge.getRelation().equals(UniversalEnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER); } } if (isRel) { features.put("PronType", "Rel"); } else { if (word.value().equalsIgnoreCase("that")) { features.put("PronType", "Dem"); } else { features.put("PronType", "Int"); } } } return features; }
SemanticGraphEdge edge = dep.getEdge(headword, child); if(edge.getRelation().getShortName().matches("dep|discourse|punct")) { continue; // skip
private static void addConjToReln(SemanticGraph sg, IndexedWord gov, List<IndexedWord> conjDeps, IndexedWord ccDep) { for (IndexedWord conjDep : conjDeps) { SemanticGraphEdge edge = sg.getEdge(gov, conjDep); if (edge.getRelation().toString().equals("conj") || conjDep.index() > ccDep.index()) { //for Joakim //edge.setRelation(UniversalGrammaticalRelations.getConj(conjValue(ccDep, sg) + ":ENH_CONJ")); String relnName = conjValue(ccDep, sg); if (relnName.matches("[^a-zA-Z_]")) { continue; } edge.setRelation(UniversalGrammaticalRelations.getConj(relnName)); } } }
private static void demoteQmodParentHelper(SemanticGraph sg, IndexedWord gov, IndexedWord oldHead) { if (!sg.getRoots().contains(oldHead)) { IndexedWord parent = sg.getParent(oldHead); if (parent == null) { return; } SemanticGraphEdge edge = sg.getEdge(parent, oldHead); sg.addEdge(parent, gov, edge.getRelation(), edge.getWeight(), edge.isExtra()); sg.removeEdge(edge); } else { sg.getRoots().remove(oldHead); sg.addRoot(gov); } //temporary relation to keep the graph connected sg.addEdge(gov, oldHead, DEPENDENT, Double.NEGATIVE_INFINITY, false); sg.removeEdge(sg.getEdge(oldHead, gov)); }
private static void addConjToReln(SemanticGraph sg, IndexedWord gov, List<IndexedWord> conjDeps, IndexedWord ccDep) { for (IndexedWord conjDep : conjDeps) { SemanticGraphEdge edge = sg.getEdge(gov, conjDep); if (edge.getRelation() == CONJUNCT || conjDep.index() > ccDep.index()) { edge.setRelation(conjValue(ccDep, sg)); } } }
@Override public void evaluate(SemanticGraph sg, SemgrexMatcher sm) { String relation = sm.getRelnString(edgeName); IndexedWord govNode = getNamedNode(govName, sm); IndexedWord depNode = getNamedNode(depName, sm); SemanticGraphEdge edge = sg.getEdge(govNode, depNode, GrammaticalRelation.valueOf(relation)); if (edge != null) { sg.removeEdge(edge); } }
private static void createMultiWordExpression(SemanticGraph sg, IndexedWord gov, GrammaticalRelation reln, IndexedWord... words) { if (sg.getRoots().isEmpty() || gov == null || words.length < 1) { return; } boolean first = true; IndexedWord mweHead = null; for (IndexedWord word : words) { IndexedWord wordGov = sg.getParent(word); if (wordGov != null) { SemanticGraphEdge edge = sg.getEdge(wordGov, word); if (edge != null) { sg.removeEdge(edge); } } if (first) { sg.addEdge(gov, word, reln, Double.NEGATIVE_INFINITY, false); mweHead = word; first = false; } else { sg.addEdge(mweHead, word, MULTI_WORD_EXPRESSION, Double.NEGATIVE_INFINITY, false); } } }
/** * 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; }
SemanticGraphEdge edge = dep.getEdge(headword, c); if(edge!=null) endIdx++;
@Override public void evaluate(SemanticGraph sg, SemgrexMatcher sm) { IndexedWord govNode = getNamedNode(govName, sm); IndexedWord depNode = getNamedNode(depName, sm); SemanticGraphEdge existingEdge = sg.getEdge(govNode, depNode, relation); if (existingEdge == null) { // When adding the edge, check to see if the gov/dep nodes are presently in the graph. // if (!sg.containsVertex(govNode)) sg.addVertex(govNode); if (!sg.containsVertex(depNode)) sg.addVertex(depNode); sg.addEdge(govNode, depNode, relation, weight,false ); } }
/** * Post-process graph and copy over case markers in case the PP-complement * is conjoined. * @param sg */ public static void addCaseMarkerForConjunctions(SemanticGraph sg) { SemanticGraph sgCopy = sg.makeSoftCopy(); for (SemanticGraphEdge edge : sgCopy.edgeIterable()) { String relnName = edge.getRelation().toString(); if (relnName.equals("nmod") || relnName.equals("obl") || relnName.equals("acl") || relnName.equals("advcl")) { Set<IndexedWord> conjParents = sg.getParentsWithReln(edge.getDependent(), "conj"); for (IndexedWord conjParent : conjParents) { List<SemanticGraphEdge> conjParentIncomingEdges = sg.getIncomingEdgesSorted(conjParent); boolean changed = false; for (SemanticGraphEdge edge1: conjParentIncomingEdges) { if (edge1.getRelation().toString().startsWith(relnName) && edge1.getRelation().getSpecific() != null) { changed = true; sg.getEdge(edge.getGovernor(), edge.getDependent(), edge.getRelation()).setRelation(edge1.getRelation()); break; } } if (changed) { break; } } } } }
/** * 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; }
SemanticGraphEdge edge = basic.getEdge(basic.getParent(w), w); GrammaticalRelation rel = null; String shortname = "root"; // if edge is null, it's root
@Override public void evaluate(SemanticGraph sg, SemgrexMatcher sm) { boolean govWild = govName.equals(WILDCARD_NODE); boolean depWild = depName.equals(WILDCARD_NODE); IndexedWord govNode = getNamedNode(govName, sm); IndexedWord depNode =getNamedNode(depName, sm); if (govNode != null && depNode != null) { SemanticGraphEdge edge = sg.getEdge(govNode, depNode, relation); if (edge != null) { @SuppressWarnings("unused") boolean successFlag = sg.removeEdge(edge); } } else if (depNode != null && govWild) { // dep known, wildcard gov for (SemanticGraphEdge edge : sg.incomingEdgeIterable(depNode)) { if (edge.getRelation().equals(relation) && sg.containsEdge(edge) ) { sg.removeEdge(edge); } } } else if (govNode != null && depWild) { // gov known, wildcard dep for (SemanticGraphEdge edge : sg.outgoingEdgeIterable(govNode)) { if (edge.getRelation().equals(relation) && sg.containsEdge(edge) ) { sg.removeEdge(edge); } } } }
SemanticGraphEdge edge = sg.getEdge(parent, word); if (edge == null) { return subj != null ? "3" : null;
IndexedWord gov = matcher.getNode("gov"); IndexedWord subj = matcher.getNode("subj"); SemanticGraphEdge edge = sg.getEdge(gov, subj);
/** * 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"; }