public static Set getContext(DataInstance sent, int i, Set<CandidatePhrase> stopWords) { SemanticGraph graph = ((DataInstanceDep)sent).getGraph(); //nodes are indexed from 1 -- so wrong!! try{ IndexedWord w = graph.getNodeByIndex(i+1); return getContext(w, graph, stopWords, sent);}catch(IllegalArgumentException e){ return Collections.emptySet(); } } }
Generics.newHashMap(); for (int i = 0; i < indexes.length; i++) { IndexedWord hypNode = hypGraph.getNodeByIndex(i); IndexedWord txtNode = IndexedWord.NO_WORD; if (indexes[i] >= 0) txtNode = txtGraph.getNodeByIndex(indexes[i]); map.put(hypNode, txtNode);
if(!acceptWord.test(l)) continue; IndexedWord w = g.getNodeByIndex(l.index()); List<String> outputPhrases = new ArrayList<>(); List<ExtractedPhrase> extractedPhrases = new ArrayList<>();
IndexedWord c = dep.getNodeByIndex(headword.index()+1); SemanticGraphEdge edge = dep.getEdge(headword, c); if(edge!=null) endIdx++;
GetPatternsFromDataMultiClass.getFeatures(graph, graph.getNodeByIndex(index + 1), true, features, null); GetPatternsFromDataMultiClass.getFeatures(graph, graph.getNodeByIndex(index+ i + 1), false, features, null); } catch(Exception e) { log.warn(e); }
private static void fixCCAttachment(SemanticGraph sg) { HashMap<SemanticGraphEdge, Integer> newHeads = new HashMap<>(); for (SemanticGraphEdge edge : sg.edgeIterable()) { if (edge.getRelation().equals(UniversalEnglishGrammaticalRelations.COORDINATION)) { // check if "cc" is attached to previous conjunct if (edge.getGovernor().index() < edge.getDependent().index()) { Set<IndexedWord> conjuncts = sg.getChildrenWithReln(edge.getGovernor(), UniversalEnglishGrammaticalRelations.CONJUNCT); int newHead = Integer.MAX_VALUE; for (IndexedWord conjunct : conjuncts) { if (conjunct.index() < newHead && conjunct.index() > edge.getDependent().index()) { newHead = conjunct.index(); } } if (newHead < Integer.MAX_VALUE) { newHeads.put(edge, newHead); } } } } for (SemanticGraphEdge edge : newHeads.keySet()) { IndexedWord newGovernor = sg.getNodeByIndex(newHeads.get(edge)); sg.removeEdge(edge); sg.addEdge(newGovernor, edge.getDependent(), edge.getRelation(), edge.getWeight(), edge.isExtra()); } }
/** * 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"; }
public static Set getContext(DataInstance sent, int i, Set<CandidatePhrase> stopWords) { SemanticGraph graph = ((DataInstanceDep)sent).getGraph(); //nodes are indexed from 1 -- so wrong!! try{ IndexedWord w = graph.getNodeByIndex(i+1); return getContext(w, graph, stopWords, sent);}catch(IllegalArgumentException e){ return Collections.emptySet(); } } }
Generics.newHashMap(); for (int i = 0; i < indexes.length; i++) { IndexedWord hypNode = hypGraph.getNodeByIndex(i); IndexedWord txtNode = IndexedWord.NO_WORD; if (indexes[i] >= 0) txtNode = txtGraph.getNodeByIndex(indexes[i]); map.put(hypNode, txtNode);
Generics.newHashMap(); for (int i = 0; i < indexes.length; i++) { IndexedWord hypNode = hypGraph.getNodeByIndex(i); IndexedWord txtNode = IndexedWord.NO_WORD; if (indexes[i] >= 0) txtNode = txtGraph.getNodeByIndex(indexes[i]); map.put(hypNode, txtNode);
public static Map<Integer, String> getParent(VerbMultiToken verb, SemanticGraph semanticGraph) { Map<Integer, String> parents = new HashMap<>(); Set<Integer> removeIndexes = new HashSet<>(); for (CoreLabel token : verb.getTokens()) { int index = token.index(); removeIndexes.add(index); try { IndexedWord node = semanticGraph.getNodeByIndex(index); List<SemanticGraphEdge> incomingEdgesSorted = semanticGraph .getIncomingEdgesSorted(node); // System.out.println(token + " --- " + incomingEdgesSorted); for (SemanticGraphEdge edge : incomingEdgesSorted) { int parentIndex = edge.getGovernor().index(); parents.put(parentIndex, edge.getRelation().getShortName()); } } catch (Exception e) { // ignored // System.out.println("ERR: no node for index " + index); // System.out.println(token); } } for (Integer removeIndex : removeIndexes) { parents.remove(removeIndex); } return parents; } }
public static Map<Integer, String> getParent(VerbMultiToken verb, SemanticGraph semanticGraph) { Map<Integer, String> parents = new HashMap<>(); Set<Integer> removeIndexes = new HashSet<>(); for (CoreLabel token : verb.getTokens()) { int index = token.index(); removeIndexes.add(index); try { IndexedWord node = semanticGraph.getNodeByIndex(index); List<SemanticGraphEdge> incomingEdgesSorted = semanticGraph .getIncomingEdgesSorted(node); // System.out.println(token + " --- " + incomingEdgesSorted); for (SemanticGraphEdge edge : incomingEdgesSorted) { int parentIndex = edge.getGovernor().index(); parents.put(parentIndex, edge.getRelation().getShortName()); } } catch (Exception e) { // ignored // System.out.println("ERR: no node for index " + index); // System.out.println(token); } } for (Integer removeIndex : removeIndexes) { parents.remove(removeIndex); } return parents; } }
.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); IndexedWord node = semanticGraph.getNodeByIndex(conj + 1); List<IndexedWord> history = getHistory(semanticGraph, node); if (history.size() == 1) {
Set<IndexedWord> children = new HashSet<>(); for (int i = comma1 + 1; i < comma2; i++) { IndexedWord node = semanticGraph.getNodeByIndex(i); parents.addAll(getParents(semanticGraph, node)); children.addAll(getChildren(semanticGraph, node)); IndexedWord node = semanticGraph.getNodeByIndex(i); children.remove(node); parents.remove(node);
indexes.add(index); try { IndexedWord node = semanticGraph.getNodeByIndex(index); frequencies.add(index); List<IndexedWord> pathToRoot = semanticGraph.getPathToRoot(node);
indexes.add(index); try { IndexedWord node = semanticGraph.getNodeByIndex(index); frequencies.add(index); List<IndexedWord> pathToRoot = semanticGraph.getPathToRoot(node);
IndexedWord c = dep.getNodeByIndex(headword.index()+1); SemanticGraphEdge edge = dep.getEdge(headword, c); if(edge!=null) endIdx++;
GetPatternsFromDataMultiClass.getFeatures(graph, graph.getNodeByIndex(index + 1), true, features, null); GetPatternsFromDataMultiClass.getFeatures(graph, graph.getNodeByIndex(index+ i + 1), false, features, null); } catch(Exception e) { log.warn(e); }
private static Pair<IndexedWord, String> findDependentVerb(Mention m) { Pair<IndexedWord, String> ret = new Pair<IndexedWord, String>(); int headIndex = m.headIndex+1; try { IndexedWord w = m.dependency.getNodeByIndex(headIndex); if(w==null) return ret; while (true) { IndexedWord p = null; for(Pair<GrammaticalRelation,IndexedWord> parent : m.dependency.parentPairs(w)){ if(ret.second()==null) { String relation = parent.first().getShortName(); ret.setSecond(relation); } p = parent.second(); } if(p==null || p.get(CoreAnnotations.PartOfSpeechAnnotation.class).startsWith("V")) { ret.setFirst(p); break; } if(w==p) return ret; w = p; } } catch (Exception e) { return ret; } return ret; }
/** * 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"; }