/** * Return the second element of the pair */ public int getTarget() { return get(1); }
/** * Return the first element of the pair */ public int getSource() { return get(0); }
int getXInstance(int index) { IntPair iP = getPair(index); return iP.get(0); }
private static void findQuotationSpeaker(Document doc, int utterNum, List<CoreMap> sentences, IntPair beginQuotation, IntPair endQuotation, Dictionaries dict) { if(findSpeaker(doc, utterNum, beginQuotation.get(0), sentences, 0, beginQuotation.get(1), dict)) return ; if(findSpeaker(doc, utterNum, endQuotation.get(0), sentences, endQuotation.get(1), sentences.get(endQuotation.get(0)).get(CoreAnnotations.TokensAnnotation.class).size(), dict)) return; if(beginQuotation.get(1) <= 1 && beginQuotation.get(0) > 0) { if(findSpeaker(doc, utterNum, beginQuotation.get(0)-1, sentences, 0, sentences.get(beginQuotation.get(0)-1).get(CoreAnnotations.TokensAnnotation.class).size(), dict)) return; } if(endQuotation.get(1) >= sentences.get(endQuotation.get(0)).size()-2 && sentences.size() > endQuotation.get(0)+1) { if(findSpeaker(doc, utterNum, endQuotation.get(0)+1, sentences, 0, sentences.get(endQuotation.get(0)+1).get(CoreAnnotations.TokensAnnotation.class).size(), dict)) return; } }
protected static void addNamedEntityStrings(CoreMap s, Set<String> neStrings, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> tokens = s.get(TokensAnnotation.class); for(IntPair p : namedEntitySpanSet) { StringBuilder sb = new StringBuilder(); for(int idx=p.get(0) ; idx < p.get(1) ; idx++) { sb.append(tokens.get(idx).word()).append(" "); } String str = sb.toString().trim(); if(str.endsWith(" 's")) { str = str.substring(0, str.length()-3); } neStrings.add(str); } }
int getYInstance(int index) { IntPair iP = getPair(index); return iP.get(1); }
private boolean checkIfSatisfiedMaxDepth(SemanticGraph g, IndexedWord parent, IndexedWord child, IntPair depths) { if (depths.get(0) == Integer.MAX_VALUE) return true; if (parent.equals(child)) return true; boolean foundInMaxDepth = false; for (IndexedWord c : g.getChildren(parent)) { if (c.equals(child)) { return true; } } depths.set(1, depths.get(1) + 1); if (depths.get(1) >= depths.get(0)) return false; for (IndexedWord c : g.getChildren(parent)) { foundInMaxDepth = checkIfSatisfiedMaxDepth(g, c, child, depths); if (foundInMaxDepth == true) return foundInMaxDepth; } return false; }
protected static void extractEnumerations(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) { List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class); Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class); SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); TregexPattern tgrepPattern = enumerationsMentionPattern; TregexMatcher matcher = tgrepPattern.matcher(tree); Map<IntPair, Tree> spanToMentionSubTree = Generics.newHashMap(); while (matcher.find()) { matcher.getMatch(); Tree m1 = matcher.getNode("m1"); Tree m2 = matcher.getNode("m2"); List<Tree> mLeaves = m1.getLeaves(); int beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1; int endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class); spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m1); mLeaves = m2.getLeaves(); beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1; endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class); spanToMentionSubTree.put(new IntPair(beginIdx, endIdx), m2); } for(IntPair mSpan : spanToMentionSubTree.keySet()){ if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) { int dummyMentionId = -1; Mention m = new Mention(dummyMentionId, mSpan.get(0), mSpan.get(1), dependency, new ArrayList<>(sent.subList(mSpan.get(0), mSpan.get(1))), spanToMentionSubTree.get(mSpan)); mentions.add(m); mentionSpanSet.add(mSpan); } } }
if (!mentionSpanSet.contains(span) && !insideNE(span, namedEntitySpanSet)) { int dummyMentionId = -1; Mention m = new Mention(dummyMentionId, span.get(0), span.get(1), sent, basicDependency, enhancedDependency, new ArrayList<>(sent.subList(span.get(0), span.get(1))), spanMention.getValue()); mentions.add(m); mentionSpanSet.add(span);
if(conjChildren.size() > 0) { IntPair npSpan = getNPSpan(headword, dep, sent); beginIdx = npSpan.get(0); endIdx = npSpan.get(1)+1; if (",".equals(sent.get(endIdx-1).word())) { endIdx--; } // try not to have span that ends with , addMention(beginIdx, endIdx, headword, mentions, mentionSpanSet, namedEntitySpanSet, sent, basic, enhanced);
/** * Return the first element of the pair */ public int getSource() { return get(0); }
/** * Return the second element of the pair */ public int getTarget() { return get(1); }