con.addAttribute(CHAR_START, new Integer(start + textOffset).toString()); con.addAttribute(CHAR_END, new Integer(end + textOffset).toString()); offsetView.addConstituent(con); pointer = end;
/** * Adds a new span to this view with a given label and score and returns the newly created * constituent. * <p> * If this {@code SpanLabelView} was defined not to accept overlapping spans (in the * constructor), then this function will throw an {@link IllegalArgumentException} when an * attempt is made to label an already existing span. * * @param start the start of the span * @param end the end of the span * @param label the label of the span * @param score the score assigned to this label * @return the newly created constituent that labels the given span. */ public Constituent addSpanLabel(int start, int end, String label, double score) { Constituent c = new Constituent(label, score, this.getViewName(), this.getTextAnnotation(), start, end); if (!allowOverlappingSpans && this.getConstituentsCoveringSpan(start, end).size() != 0) throw new IllegalArgumentException("Span [" + start + ", " + end + "] already labeled."); this.addConstituent(c); return c; }
/** * Adds a new span to this view with a given label and score and returns the newly created * constituent. * <p> * If this {@code SpanLabelView} was defined not to accept overlapping spans (in the * constructor), then this function will throw an {@link IllegalArgumentException} when an * attempt is made to label an already existing span. * * @param start the start of the span * @param end the end of the span * @param label the label of the span * @param score the score assigned to this label * @return the newly created constituent that labels the given span. */ public Constituent addSpanLabel(int start, int end, String label, double score) { Constituent c = new Constituent(label, score, this.getViewName(), this.getTextAnnotation(), start, end); if (!allowOverlappingSpans && this.getConstituentsCoveringSpan(start, end).size() != 0) throw new IllegalArgumentException("Span [" + start + ", " + end + "] already labeled."); this.addConstituent(c); return c; }
constituent.addAttribute("EntityMentionType", "NAM"); mentionView.addConstituent(constituent);
c.addAttribute(QuestionTyperConfigurator.goldCoarseLabelAttributeName, splitLabel[0]); c.addAttribute(QuestionTyperConfigurator.goldFineLabelAttributeName, split[0]); view.addConstituent(c); ta.addView(QuestionTyperConfigurator.questionTypeViewName, view); try {
c.addAttribute(QuestionTyperConfigurator.goldCoarseLabelAttributeName, splitLabel[0]); c.addAttribute(QuestionTyperConfigurator.goldFineLabelAttributeName, split[0]); view.addConstituent(c); ta.addView(QuestionTyperConfigurator.questionTypeViewName, view); try {
constituent.addAttribute("EntityMentionType", "NAM"); mentionView.addConstituent(constituent);
new Constituent(label, ViewNames.NER_CONLL, ta, span.getFirst(), span.getSecond()); emptyview.addConstituent(c);
new Constituent(label, ViewNames.NER_CONLL, ta, span.getFirst(), span.getSecond()); emptyview.addConstituent(c);
constituent.addAttribute("EntityMentionType", "NAM"); mentionView.addConstituent(constituent);
new Constituent(label, ViewNames.NER_CONLL, ta, span.getFirst(), span.getSecond()); emptyview.addConstituent(c);
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { SpanLabelView view = new SpanLabelView(ViewNames.QUESTION_TYPE, ViewNames.QUESTION_TYPE, ta, 1.0); assert ta.getAvailableViews().contains(ViewNames.SHALLOW_PARSE) && ta.getAvailableViews().contains(ViewNames.NER_CONLL) && ta.getAvailableViews().contains(ViewNames.NER_ONTONOTES): "the annotator does not have the required views "; String fineLabel = fine.discreteValue(ta); Double fineLabelScore = fine.scores(ta).getScore(fineLabel).score; String coarseLabel = coarse.discreteValue(ta); Double coarseLabelScore = coarse.scores(ta).getScore(coarseLabel).score; Constituent cFine = new Constituent(fineLabel, fineLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); Constituent cCoarse = new Constituent(coarseLabel, coarseLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); view.addConstituent(cCoarse); view.addConstituent(cFine); ta.addView(ViewNames.QUESTION_TYPE, view); } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { SpanLabelView view = new SpanLabelView(ViewNames.QUESTION_TYPE, ViewNames.QUESTION_TYPE, ta, 1.0); assert ta.getAvailableViews().contains(ViewNames.SHALLOW_PARSE) && ta.getAvailableViews().contains(ViewNames.NER_CONLL) && ta.getAvailableViews().contains(ViewNames.NER_ONTONOTES): "the annotator does not have the required views "; String fineLabel = fine.discreteValue(ta); Double fineLabelScore = fine.scores(ta).getScore(fineLabel).score; String coarseLabel = coarse.discreteValue(ta); Double coarseLabelScore = coarse.scores(ta).getScore(coarseLabel).score; Constituent cFine = new Constituent(fineLabel, fineLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); Constituent cCoarse = new Constituent(coarseLabel, coarseLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); view.addConstituent(cCoarse); view.addConstituent(cFine); ta.addView(ViewNames.QUESTION_TYPE, view); } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); SpanLabelView vu = new SpanLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for(RelationMention rm : sentence.get(MachineReadingAnnotations.RelationMentionsAnnotation.class)) { if(rm.getType().equals("_NR")) continue; Map<String, Double> scores = new HashMap<>(); for(String label : rm.getTypeProbabilities().keySet()) scores.put(label, rm.getTypeProbabilities().getCount(label)); Constituent c1 = createConstituentGivenMention(rm.getEntityMentionArgs().get(0), ta); Constituent c2 = createConstituentGivenMention(rm.getEntityMentionArgs().get(1), ta); Relation r = new Relation(scores, c1, c2); vu.addRelation(r); if(!vu.containsConstituent(c1)) vu.addConstituent(c1); if(!vu.containsConstituent(c2)) vu.addConstituent(c2); } } for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { for (EntityMention rm : sentence.get(MachineReadingAnnotations.EntityMentionsAnnotation.class)) { Constituent c = createConstituentGivenMention(rm, ta); if(!vu.containsConstituent(c)) vu.addConstituent(c); } } ta.addView(viewName, vu); }
extentConstituent.addAttribute(EntityHeadEndCharOffset, entityMention.headEnd + 1 + ""); entityView.addConstituent(extentConstituent);
extentConstituent.addAttribute(EntityHeadEndCharOffset, entityMention.headEnd + 1 + ""); entityView.addConstituent(extentConstituent);
extentConstituent.addAttribute(EntityHeadEndCharOffset, entityMention.headEnd + 1 + ""); entityView.addConstituent(extentConstituent);
continue; wikiView.addConstituent(c);
if (tokenEnd > tokenStart){ Constituent c = new Constituent(href.link, ViewNames.WIKIFIER, ta, tokenStart, tokenEnd); wikiView.addConstituent(c);
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { Annotation document = new Annotation(ta.text); pipeline.annotate(document); SpanLabelView vu = new SpanLabelView(viewName, ta); for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class); for (RelationTriple triple : triples) { Constituent subject = getConstituent(triple.subjectGloss(), triple.subjectTokenSpan(), sentence, ta); subject.addAttribute("subjectGloss", triple.subjectGloss()); subject.addAttribute("subjectLemmaGloss", triple.subjectLemmaGloss()); subject.addAttribute("subjectLink", triple.subjectLink()); Constituent object = getConstituent(triple.objectGloss(), triple.objectTokenSpan(), sentence, ta); object.addAttribute("objectGloss", triple.objectGloss()); object.addAttribute("objectLemmaGloss", triple.objectLemmaGloss()); object.addAttribute("objectLink", triple.objectLink()); Constituent relation = getConstituent(triple.relationGloss(), triple.relationTokenSpan(), sentence, ta); relation.addAttribute("relationGloss", triple.relationGloss()); relation.addAttribute("relationLemmaGloss", triple.relationLemmaGloss()); Relation subj = new Relation("subj", relation, subject, triple.confidence); Relation obj = new Relation("obj", relation, object, triple.confidence); vu.addRelation(subj); vu.addRelation(obj); vu.addConstituent(subject); vu.addConstituent(object); vu.addConstituent(relation); } } ta.addView(viewName, vu); }