String value = null; if (property == CTAKESAnnotationProperty.BEGIN) { value = Integer.toString(annotation.getBegin()); } else if (property == CTAKESAnnotationProperty.END) { value = Integer.toString(annotation.getEnd());
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(); }
/** * 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(); }
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(); }
/** * 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(); }
@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; }
static private void processList( final JCas jCas, final AnnotationFS list ) { final java.util.List<ListEntry> listEntries = new ArrayList<>( JCasUtil .selectCovered( jCas, ListEntry.class, list ) ); if ( listEntries.isEmpty() ) { return; } listEntries.sort( ( a1, a2 ) -> a1.getBegin() - a2.getBegin() ); final java.util.List<IdentifiedAnnotation> negatables = new ArrayList<>(); negatables.addAll( JCasUtil.selectCovered( jCas, DiseaseDisorderMention.class, list ) ); negatables.addAll( JCasUtil.selectCovered( jCas, SignSymptomMention.class, list ) ); negatables.sort( ( a1, a2 ) -> a1.getBegin() - a2.getBegin() ); if ( negatables.isEmpty() ) { return; } processNegatables( jCas.getDocumentText(), listEntries, negatables ); }
static private void processList( final JCas jCas, final AnnotationFS list ) { final java.util.List<ListEntry> listEntries = new ArrayList<>( JCasUtil .selectCovered( jCas, ListEntry.class, list ) ); if ( listEntries.isEmpty() ) { return; } listEntries.sort( ( a1, a2 ) -> a1.getBegin() - a2.getBegin() ); final java.util.List<IdentifiedAnnotation> negatables = new ArrayList<>(); negatables.addAll( JCasUtil.selectCovered( jCas, DiseaseDisorderMention.class, list ) ); negatables.addAll( JCasUtil.selectCovered( jCas, SignSymptomMention.class, list ) ); negatables.sort( ( a1, a2 ) -> a1.getBegin() - a2.getBegin() ); if ( negatables.isEmpty() ) { return; } processNegatables( jCas.getDocumentText(), listEntries, negatables ); }
private static String formatRelation(BinaryTextRelation relation) { IdentifiedAnnotation arg1 = (IdentifiedAnnotation) relation.getArg1().getArgument(); IdentifiedAnnotation arg2 = (IdentifiedAnnotation) relation.getArg2().getArgument(); String text = arg1.getCAS().getDocumentText(); int begin = Math.min(arg1.getBegin(), arg2.getBegin()); int end = Math.max(arg1.getBegin(), arg2.getBegin()); begin = Math.max(0, begin - 50); end = Math.min(text.length(), end + 50); return String.format( "%s(%s(type=%d), %s(type=%d)) in ...%s...", relation.getCategory(), arg1.getCoveredText(), arg1.getTypeID(), arg2.getCoveredText(), arg2.getTypeID(), text.substring(begin, end).replaceAll("[\r\n]", " ")); }
private static String formatRelation(BinaryTextRelation relation) { IdentifiedAnnotation arg1 = (IdentifiedAnnotation) relation.getArg1().getArgument(); IdentifiedAnnotation arg2 = (IdentifiedAnnotation) relation.getArg2().getArgument(); String text = arg1.getCAS().getDocumentText(); int begin = Math.min(arg1.getBegin(), arg2.getBegin()); int end = Math.max(arg1.getBegin(), arg2.getBegin()); begin = Math.max(0, begin - 50); end = Math.min(text.length(), end + 50); return String.format( "%s(%s(type=%d), %s(type=%d)) in ...%s...", relation.getCategory(), arg1.getCoveredText(), arg1.getTypeID(), arg2.getCoveredText(), arg2.getTypeID(), text.substring(begin, end).replaceAll("[\r\n]", " ")); }
/** * 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; }
@Override public List<Feature> extract(JCas jCas, CollectionTextRelation cluster, IdentifiedAnnotation mention) throws AnalysisEngineProcessException { List<Feature> feats = new ArrayList<>(); double maxSalience = 0.0; for(Markable member : new ListIterable<Markable>(cluster.getMembers())){ if(mention.getBegin() < member.getEnd()){ // during training this might happen -- see a member of a cluster that // is actually subsequent to the candidate mention break; } if(member.getConfidence() > maxSalience){ maxSalience = member.getConfidence(); } } feats.add(new Feature("MC_MAX_SALIENCE", maxSalience)); return feats; }
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(); }