@SuppressWarnings("RedundantIfStatement") public boolean isCopy(IndexedWord otherWord) { Integer myInd = get(CoreAnnotations.IndexAnnotation.class); Integer otherInd = otherWord.get(CoreAnnotations.IndexAnnotation.class); if ( ! Objects.equals(myInd, otherInd)) { return false; } Integer mySentInd = get(CoreAnnotations.SentenceIndexAnnotation.class); Integer otherSentInd = otherWord.get(CoreAnnotations.SentenceIndexAnnotation.class); if ( ! Objects.equals(mySentInd, otherSentInd)) { return false; } String myDocID = getString(CoreAnnotations.DocIDAnnotation.class); String otherDocID = otherWord.getString(CoreAnnotations.DocIDAnnotation.class); if ( ! Objects.equals(myDocID, otherDocID)) { return false; } if (copyCount() == 0 || otherWord.copyCount() != 0) { return false; } return true; }
/** * This hashCode uses only the docID, sentenceIndex, and index. * See compareTo for more info. */ @Override public int hashCode() { if (cachedHashCode != 0) { return cachedHashCode; } boolean sensible = false; int result = 0; if (get(CoreAnnotations.DocIDAnnotation.class) != null) { result = get(CoreAnnotations.DocIDAnnotation.class).hashCode(); sensible = true; } if (containsKey(CoreAnnotations.SentenceIndexAnnotation.class)) { result = 29 * result + get(CoreAnnotations.SentenceIndexAnnotation.class).hashCode(); sensible = true; } if (containsKey(CoreAnnotations.IndexAnnotation.class)) { result = 29 * result + get(CoreAnnotations.IndexAnnotation.class).hashCode(); sensible = true; } if ( ! sensible) { log.info("WARNING!!! You have hashed an IndexedWord with no docID, sentIndex or wordIndex. You will almost certainly lose"); } cachedHashCode = result; return result; }
Integer myInd = get(CoreAnnotations.IndexAnnotation.class); Integer otherInd = otherWord.get(CoreAnnotations.IndexAnnotation.class); if ( ! Objects.equals(myInd, otherInd)) { return false; Integer mySentInd = get(CoreAnnotations.SentenceIndexAnnotation.class); Integer otherSentInd = otherWord.get(CoreAnnotations.SentenceIndexAnnotation.class); if ( ! Objects.equals(mySentInd, otherSentInd)) { return false;
/** Check one mention is the speaker of the other mention */ public static boolean isSpeaker(Mention m, Mention ant, Dictionaries dict) { if(!dict.firstPersonPronouns.contains(ant.spanToString().toLowerCase()) || ant.number==Number.PLURAL || ant.sentNum!=m.sentNum) return false; int countQuotationMark = 0; for(int i = Math.min(m.headIndex, ant.headIndex)+1 ; i < Math.max(m.headIndex, ant.headIndex) ; i++) { String word = m.sentenceWords.get(i).get(CoreAnnotations.TextAnnotation.class); if(word.equals("``") || word.equals("''")) countQuotationMark++; } if(countQuotationMark!=1) return false; IndexedWord w = m.dependency.getNodeByWordPattern(m.sentenceWords.get(m.headIndex).get(CoreAnnotations.TextAnnotation.class)); if(w== null) return false; for(Pair<GrammaticalRelation,IndexedWord> parent : m.dependency.parentPairs(w)){ if(parent.first().getShortName().equals("nsubj") && dict.reportVerb.contains(parent.second().get(CoreAnnotations.LemmaAnnotation.class))) { return true; } } return false; }
/** Check one mention is the speaker of the other mention */ public static boolean isSpeaker(Mention m, Mention ant, Dictionaries dict) { if(!dict.firstPersonPronouns.contains(ant.spanToString().toLowerCase()) || ant.number==Number.PLURAL || ant.sentNum!=m.sentNum) return false; int countQuotationMark = 0; for(int i = Math.min(m.headIndex, ant.headIndex)+1 ; i < Math.max(m.headIndex, ant.headIndex) ; i++) { String word = m.sentenceWords.get(i).get(CoreAnnotations.TextAnnotation.class); if(word.equals("``") || word.equals("''")) countQuotationMark++; } if(countQuotationMark!=1) return false; IndexedWord w = m.enhancedDependency.getNodeByWordPattern(m.sentenceWords.get(m.headIndex).get(CoreAnnotations.TextAnnotation.class)); if(w== null) return false; for(Pair<GrammaticalRelation,IndexedWord> parent : m.enhancedDependency.parentPairs(w)){ if(parent.first().getShortName().equals("nsubj") && dict.reportVerb.contains(parent.second().get(CoreAnnotations.LemmaAnnotation.class))) { return true; } } return false; }
Object value = node.get(c); if (value == null) nodeValue = null;
String posTag = word.get(CoreAnnotations.PartOfSpeechAnnotation.class); String token = word.get(CoreAnnotations.TextAnnotation.class); Integer index = word.get(CoreAnnotations.IndexAnnotation.class); HashMap<String, String> wordFeatures = word.get(CoreAnnotations.CoNLLUFeats.class); String lemma = word.get(CoreAnnotations.LemmaAnnotation.class); if (addLemma && (lemma == null || lemma.equals("_"))) { word.set(CoreAnnotations.LemmaAnnotation.class, morphology.lemma(token, posTag));
/** * Does the given {@code vertex} have at least one child with the given {@code reln} and the lemma {@code childLemma}? */ public boolean hasChild(IndexedWord vertex, GrammaticalRelation reln, String childLemma) { if (!containsVertex(vertex)) { throw new IllegalArgumentException(); } for (SemanticGraphEdge edge : outgoingEdgeIterable(vertex)) { if (edge.getRelation().equals(reln)) { if (edge.getTarget().get(CoreAnnotations.LemmaAnnotation.class).equals(childLemma)) { return true; } } } return false; }
String lemma = parent.get(CoreAnnotations.LemmaAnnotation.class); if (lemma.equals(word)) { match = true; boolean match = false; for (IndexedWord child : children) { String lemma = child.get(CoreAnnotations.LemmaAnnotation.class); if (lemma.isEmpty()) { lemma = child.word().toLowerCase(); continue; IndexedWord child = pair.second(); String lemma = child.get(CoreAnnotations.LemmaAnnotation.class); if (lemma.isEmpty()) { lemma = child.word().toLowerCase();
public CoreNLPProtos.IndexedWord createIndexedWordProtoFromIW(IndexedWord iw) { CoreNLPProtos.IndexedWord.Builder builder = CoreNLPProtos.IndexedWord.newBuilder(); if (iw == null) { builder.setSentenceNum(-1); builder.setTokenIndex(-1); } else { builder.setSentenceNum(iw.get(SentenceIndexAnnotation.class) - 1); builder.setTokenIndex(iw.get(IndexAnnotation.class) - 1); builder.setCopyCount(iw.copyCount()); } return builder.build(); }
sentenceSb.append(word.get(CoreAnnotations.TextAnnotation.class)); sentenceSb.append(' ');
private static Object getNodes(SemanticGraph graph) { if(graph != null) { List<IndexedWord> vertexList = graph.vertexListSorted(); int maxIndex = vertexList.get(vertexList.size() - 1).index(); return vertexList.stream().map( (IndexedWord token) -> (Consumer<Writer>) node -> { if (token.copyCount() == 0) { node.set("id", getNodeIndex(token, maxIndex)); node.set("start", token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class)); node.set("end", token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class)); } else { node.set("id", getNodeIndex(token, maxIndex)); node.set("source", token.index()); } node.set("form", token.word()); if (graph.getRoots().contains(token)) node.set("top", true); node.set("properties", (Consumer<Writer>) propertiesWriter -> { propertiesWriter.set("xpos", token.tag()); propertiesWriter.set("upos", token.get(CoreAnnotations.CoarseTagAnnotation.class)); propertiesWriter.set("lemma", token.lemma()); }); node.set("edges", graph.getOutEdgesSorted(token).stream().map( (SemanticGraphEdge dep) -> (Consumer<Writer>) edge -> { edge.set("target", getNodeIndex(dep.getDependent(), maxIndex)); edge.set("label", dep.getRelation().toString()); })); } ); } else { return null; } }
private void finishSentence(CoreMap sentence, List<Tree> trees) { if (treeMap != null) { List<Tree> mappedTrees = Generics.newLinkedList(); for (Tree tree : trees) { Tree mappedTree = treeMap.apply(tree); mappedTrees.add(mappedTree); } trees = mappedTrees; } ParserAnnotatorUtils.fillInParseAnnotations(VERBOSE, BUILD_GRAPHS, gsf, sentence, trees, extraDependencies); if (saveBinaryTrees) { TreeBinarizer binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack()); Tree binarized = binarizer.transformTree(trees.get(0)); Trees.convertToCoreLabels(binarized); sentence.set(TreeCoreAnnotations.BinarizedTreeAnnotation.class, binarized); } // for some reason in some corner cases nodes aren't having sentenceIndex set // do a pass and make sure all nodes have sentenceIndex set SemanticGraph sg = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); if (sg != null) { for (IndexedWord iw : sg.vertexSet()) { if (iw.get(CoreAnnotations.SentenceIndexAnnotation.class) == null && sentence.get(CoreAnnotations.SentenceIndexAnnotation.class) != null) { iw.setSentIndex(sentence.get(CoreAnnotations.SentenceIndexAnnotation.class)); } } } }
newNode.set(key, rootNode.get(key));
if (modifier.get(CoreAnnotations.CoarseTagAnnotation.class).equalsIgnoreCase("PART")) { continue;
.setSentenceIndex(node.get(SentenceIndexAnnotation.class)) .setIndex(node.index()); if (node.copyCount() > 0) {