private static Constituent getConstituent(String label, Pair<Integer, Integer> tokenSpan, CoreMap sentence, TextAnnotation ta) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); int extentCharStart = tokens.get(tokenSpan.first()).beginPosition(); int extentCharEnd = tokens.get(tokenSpan.second()).endPosition() - 1; List<Constituent> extentCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(extentCharStart, extentCharEnd); int startIndex = extentCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get().getStartSpan(); int endIndex = extentCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); return new Constituent(label, viewName, ta, startIndex, endIndex); } }
/** * It gets the Stanford EntityMEntion and finds its equivalent CogComp Consittuent. * This mapping is done by comparing char offsets. */ private static Constituent createConstituentGivenMention(EntityMention rm, TextAnnotation ta) { List<CoreLabel> tokens = rm.getSentence().get(CoreAnnotations.TokensAnnotation.class); int extentCharStart = tokens.get(rm.getExtentTokenStart()).beginPosition(); int extentCharEnd = tokens.get(rm.getExtentTokenEnd()).endPosition(); int headCharStart = tokens.get(rm.getHeadTokenStart()).beginPosition(); int headCharEnd = tokens.get(rm.getHeadTokenEnd()).endPosition(); List<Constituent> extentCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(extentCharStart, extentCharEnd); int startIndex = extentCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get().getStartSpan(); int endIndex = extentCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); List<Constituent> headCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(headCharStart, headCharEnd); int startIndexHead = headCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get().getStartSpan(); int endIndexHead = headCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(rm.getType(), viewName, ta, startIndex, endIndex); c.addAttribute("startIndexHead", String.valueOf(startIndexHead)); c.addAttribute("endIndexHead", String.valueOf(endIndexHead)); return c; } }
private static Constituent createConstituentGivenMention(Annotation document, CorefChain chain, CorefChain.CorefMention m, TextAnnotation ta) { Pair<Integer, Integer> mentionCharSpan = getCharIntervalFromCorefMention(document, m.sentNum, m.startIndex, m.endIndex); List<Constituent> overlappingCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(mentionCharSpan.getFirst(), mentionCharSpan.getSecond()); int startIndex = overlappingCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get().getStartSpan(); int endIndex = overlappingCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(String.valueOf(chain.getChainID()), viewName, ta, startIndex, endIndex); c.addAttribute("animacy", m.animacy.toString()); c.addAttribute("number", m.number.toString()); c.addAttribute("gender", m.gender.toString()); c.addAttribute("mentionType", m.mentionType.toString()); return c; } }
@Override public void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); TokenLabelView vu = new TokenLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String trueCase = token.get(CoreAnnotations.TrueCaseTextAnnotation.class); int beginCharOffsetS = token.beginPosition(); int endCharOffset = token.endPosition() - 1; List<Constituent> overlappingCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(beginCharOffsetS, endCharOffset); int endIndex = overlappingCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(trueCase, viewName, ta, endIndex - 1, endIndex); vu.addConstituent(c); } } ta.addView(viewName, vu); } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); TokenLabelView vu = new TokenLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String trueCase = token.get(CoreAnnotations.TrueCaseTextAnnotation.class); int beginCharOffsetS = token.beginPosition(); int endCharOffset = token.endPosition() - 1; List<Constituent> overlappingCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(beginCharOffsetS, endCharOffset); int endIndex = overlappingCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(trueCase, viewName, ta, endIndex - 1, endIndex); vu.addConstituent(c); } } ta.addView(viewName, vu); } }
@Override public void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); TokenLabelView vu = new TokenLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String trueCase = token.get(CoreAnnotations.TrueCaseTextAnnotation.class); int beginCharOffsetS = token.beginPosition(); int endCharOffset = token.endPosition() - 1; List<Constituent> overlappingCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(beginCharOffsetS, endCharOffset); int endIndex = overlappingCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(trueCase, viewName, ta, endIndex - 1, endIndex); vu.addConstituent(c); } } ta.addView(viewName, vu); } }
@Override public void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); TokenLabelView vu = new TokenLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String trueCase = token.get(CoreAnnotations.TrueCaseTextAnnotation.class); int beginCharOffsetS = token.beginPosition(); int endCharOffset = token.endPosition() - 1; List<Constituent> overlappingCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(beginCharOffsetS, endCharOffset); int endIndex = overlappingCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan(); Constituent c = new Constituent(trueCase, viewName, ta, endIndex - 1, endIndex); vu.addConstituent(c); } } ta.addView(viewName, vu); } }