value = Integer.toString(annotation.getBegin()); } else if (property == CTAKESAnnotationProperty.END) { value = Integer.toString(annotation.getEnd()); } else if (property == CTAKESAnnotationProperty.CONDITIONAL) { value = Boolean.toString(annotation.getConditional());
static private Collection<IdentifiedAnnotation> getEndAnnotations( final Collection<IdentifiedAnnotation> annotations, final int adjustedEnd ) { if ( annotations == null || annotations.isEmpty() ) { return Collections.emptyList(); } return annotations.stream() .filter( a -> a.getEnd() == adjustedEnd ) .collect( Collectors.toSet() ); }
static private Collection<IdentifiedAnnotation> getEndAnnotations( final Collection<IdentifiedAnnotation> annotations, final int adjustedEnd ) { if ( annotations == null || annotations.isEmpty() ) { return Collections.emptyList(); } return annotations.stream() .filter( a -> a.getEnd() == adjustedEnd ) .collect( Collectors.toSet() ); }
/** * I2b2 wants annotation begin and end offsets plus the covered text * @param jcas in case the blob needs to obtain annotation information from the jcas * @param annotation - * @return a blob with encoded text span and covered text of the annotation */ protected String createBlob( final JCas jcas, final IdentifiedAnnotation annotation ) { final StringBuilder sb = new StringBuilder(); sb.append( '<' ).append( SPAN_START_LABEL ).append( '>' ); sb.append( annotation.getBegin() ); sb.append( "</" ).append( SPAN_START_LABEL ).append( '>' ); sb.append( '<' ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getEnd() ); sb.append( "</" ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getCoveredText() ); return sb.toString(); }
/** * I2b2 wants annotation begin and end offsets plus the covered text * @param jcas in case the blob needs to obtain annotation information from the jcas * @param annotation - * @return a blob with encoded text span and covered text of the annotation */ protected String createBlob( final JCas jcas, final IdentifiedAnnotation annotation ) { final StringBuilder sb = new StringBuilder(); sb.append( '<' ).append( SPAN_START_LABEL ).append( '>' ); sb.append( annotation.getBegin() ); sb.append( "</" ).append( SPAN_START_LABEL ).append( '>' ); sb.append( '<' ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getEnd() ); sb.append( "</" ).append( SPAN_END_LABEL ).append( '>' ); sb.append( annotation.getCoveredText() ); return sb.toString(); }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> features = new ArrayList<Feature>(); // entity1 ... entity2 scenario if(arg1.getEnd() < arg2.getBegin()) { features.add(new Feature("arg1_arg2", true)); } // entity2 ... entity1 scenario if(arg2.getEnd() < arg1.getBegin()) { features.add(new Feature("arg2_arg1", true)); } return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> features = new ArrayList<Feature>(); // entity1 ... entity2 scenario if(arg1.getEnd() < arg2.getBegin()) { features.add(new Feature("arg1_arg2", true)); } // entity2 ... entity1 scenario if(arg2.getEnd() < arg1.getBegin()) { features.add(new Feature("arg2_arg1", true)); } return features; }
public static int sentDist(JCas jcas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2){ return JCasUtil.selectCovered(jcas, Sentence.class, arg1.getBegin(), arg2.getEnd()).size(); }
public static int sentDist(JCas jcas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2){ return JCasUtil.selectCovered(jcas, Sentence.class, arg1.getBegin(), arg2.getEnd()).size(); }
private static String formatError(JCas jcas, IdentifiedAnnotation mention){ List<Sentence> context = JCasUtil.selectCovering(jcas, Sentence.class, mention.getBegin(), mention.getEnd()); StringBuffer buff = new StringBuffer(); if(context.size() > 0){ Sentence sent = context.get(0); buff.append(sent.getCoveredText()); long offset = mention.getBegin() - sent.getBegin(); if (offset>=Integer.MAX_VALUE || offset<=Integer.MIN_VALUE) { offset=0; } // for spanless annots buff.insert((int)offset, "***"); offset += (mention.getEnd()-mention.getBegin() + 3); buff.insert((int)offset, "***"); } return buff.toString(); }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> feats = new ArrayList<>(); feats.add(new Feature("TOK_DIST", JCasUtil.selectCovered(jCas, BaseToken.class, arg1.getBegin(), arg2.getEnd()).size() / (double)CorefConsts.TOKDIST)); feats.add(new Feature("SENT_DIST", JCasUtil.selectCovered(jCas, Sentence.class, arg1.getBegin(), arg2.getEnd()).size() / (double) CorefConsts.NEDIST)); return feats; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> feats = new ArrayList<>(); feats.add(new Feature("TOK_DIST", JCasUtil.selectCovered(jCas, BaseToken.class, arg1.getBegin(), arg2.getEnd()).size() / (double)CorefConsts.TOKDIST)); feats.add(new Feature("SENT_DIST", JCasUtil.selectCovered(jCas, Sentence.class, arg1.getBegin(), arg2.getEnd()).size() / (double) CorefConsts.NEDIST)); return feats; }
private static String formatError(JCas jcas, IdentifiedAnnotation mention){ List<Sentence> context = JCasUtil.selectCovering(jcas, Sentence.class, mention.getBegin(), mention.getEnd()); StringBuffer buff = new StringBuffer(); if(context.size() > 0){ Sentence sent = context.get(0); buff.append(sent.getCoveredText()); long offset = mention.getBegin() - sent.getBegin(); if (offset>=Integer.MAX_VALUE || offset<=Integer.MIN_VALUE) { offset=0; } // for spanless annots buff.insert((int)offset, "***"); offset += (mention.getEnd()-mention.getBegin() + 3); buff.insert((int)offset, "***"); } return buff.toString(); }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> features = new ArrayList<Feature>(); features.addAll(this.mention1FeaturesExtractor.extract(jCas, arg1)); features.addAll(this.mention2FeaturesExtractor.extract(jCas, arg2)); features.addAll(this.nEntityMentionsBetween.extract(jCas, arg1, arg2)); // entity type of both mentions, concatenated int type1 = arg1.getTypeID(); int type2 = arg2.getTypeID(); features.add(new Feature("type1type2", String.format("%s_%s", type1, type2))); // is mention1 included in mention2? boolean begins1After2 = arg1.getBegin() >= arg2.getBegin(); boolean ends1Before2 = arg1.getEnd() <= arg2.getEnd(); features.add(new Feature("mention1InMention2", begins1After2 && ends1Before2)); // is mention2 included in mention1? boolean begins2After1 = arg2.getBegin() >= arg1.getBegin(); boolean ends2Before1 = arg2.getEnd() <= arg1.getEnd(); features.add(new Feature("mention2InMention1", begins2After1 && ends2Before1)); return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> features = new ArrayList<Feature>(); // entity1 ... entity2 scenario if(arg1.getEnd() < arg2.getBegin()) { for(PunctuationToken token : JCasUtil.selectCovered(jCas, PunctuationToken.class, arg1.getEnd(), arg2.getBegin())) { features.add(new Feature("arg1_punctuation_arg2", token.getCoveredText())); break; } } // entity2 ... entity1 scenario if(arg2.getEnd() < arg1.getBegin()) { for(PunctuationToken token : JCasUtil.selectCovered(jCas, PunctuationToken.class, arg2.getEnd(), arg1.getBegin())) { features.add(new Feature("arg2_punctuation_arg1", token.getCoveredText())); break; } } return features; }
/** * Return the List of drug IdentifiedAnnotation within the span * @param jcas * @param begin * @param end * @return */ public static List getDrugsInSpan(JCas jcas, int begin, int end) { JFSIndexRepository indexes = jcas.getJFSIndexRepository(); Iterator neItr= indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator(); List l = new ArrayList(); //add drug to List while (neItr.hasNext()) { IdentifiedAnnotation nea = (IdentifiedAnnotation) neItr.next(); if(nea.getTypeID()==1) if(nea.getBegin()>=begin && nea.getEnd()<=end) l.add(nea); } return l; }
/** * Is this pair of entities enclosed inside a noun phrase? */ public static boolean isEnclosed(IdentifiedAnnotationPair pair, TreebankNode np) { IdentifiedAnnotation arg1 = pair.getArg1(); IdentifiedAnnotation arg2 = pair.getArg2(); if((np.getBegin() <= arg1.getBegin()) && (np.getEnd() >= arg1.getEnd()) && (np.getBegin() <= arg2.getBegin()) && (np.getEnd() >= arg2.getEnd())) { return true; } return false; }
/** * Is this pair of entities enclosed inside a noun phrase? */ public static boolean isEnclosed(IdentifiedAnnotationPair pair, TreebankNode np) { IdentifiedAnnotation arg1 = pair.getArg1(); IdentifiedAnnotation arg2 = pair.getArg2(); if((np.getBegin() <= arg1.getBegin()) && (np.getEnd() >= arg1.getEnd()) && (np.getBegin() <= arg2.getBegin()) && (np.getEnd() >= arg2.getEnd())) { return true; } return false; }
private Entity( final IdentifiedAnnotation annotation ) { _begin = annotation.getBegin(); _end = annotation.getEnd(); _coveredText = annotation.getCoveredText(); _polarity = annotation.getPolarity(); _uncertainty = annotation.getUncertainty(); _conditional = annotation.getConditional(); _generic = annotation.getGeneric(); _subject = annotation.getSubject(); _historyOf = annotation.getHistoryOf(); }
private Entity( final IdentifiedAnnotation annotation ) { _begin = annotation.getBegin(); _end = annotation.getEnd(); _coveredText = annotation.getCoveredText(); _polarity = annotation.getPolarity(); _uncertainty = annotation.getUncertainty(); _conditional = annotation.getConditional(); _generic = annotation.getGeneric(); _subject = annotation.getSubject(); _historyOf = annotation.getHistoryOf(); }