IdentifiedAnnotation annotation = iterator.next(); StringBuilder annotationBuilder = new StringBuilder(); annotationBuilder.append(annotation.getCoveredText()); if (annotationPros != null) { for (CTAKESAnnotationProperty property : annotationPros) {
/** * @param annotation - * @return the covered text */ static private String getCoveredText( final IdentifiedAnnotation annotation ) { return annotation.getCoveredText() .replace( '\r', ' ' ) .replace( '\n', ' ' ); }
/** * @param annotation - * @return the covered text */ static private String getCoveredText( final IdentifiedAnnotation annotation ) { return annotation.getCoveredText().replace( '\r', ' ' ).replace( '\n', ' ' ); }
/** * Return true if pse belongs to side effects in the side-effect dictionary * * @param jcas * @param pse potential side effect * @return true if satisfies given conditions, else false */ private boolean isInDictionary(JCas jcas, PotentialSideEffect pse) { String drug = pse.drug.getCoveredText().toLowerCase().trim(); if(keyDrugMap.containsKey(drug)) { Set<String> seSet = sideEffectMap.get(keyDrugMap.get(drug)); String pseStr = pse.ne.getCoveredText().toLowerCase().trim(); //exact matching if(seSet.contains(pseStr)) return true; } return false; }
/** * Return true if pse belongs to side effects in the side-effect dictionary * * @param jcas * @param pse potential side effect * @return true if satisfies given conditions, else false */ private boolean isInDictionary(JCas jcas, PotentialSideEffect pse) { String drug = pse.drug.getCoveredText().toLowerCase().trim(); if(keyDrugMap.containsKey(drug)) { Set<String> seSet = sideEffectMap.get(keyDrugMap.get(drug)); String pseStr = pse.ne.getCoveredText().toLowerCase().trim(); //exact matching if(seSet.contains(pseStr)) return true; } return false; }
static String format(IdentifiedAnnotation a) { return a == null ? null : String.format("\"%s\"(type=%d)", a.getCoveredText(), a.getTypeID()); }
static String format(IdentifiedAnnotation a) { return a == null ? null : String.format("\"%s\"(type=%d)", a.getCoveredText(), a.getTypeID()); }
/** * Return true if pse is sideEffectWord and there is no other pse(s) in the pse.sentence * but if the pse sentence contains certain word, return false * - this is a naive rule * - sideEffectWord must not be negated * * @param jcas * @param pse potential side effect * @param input modified SE sentence used for regular expression match * @return true if finds a given pattern, else false */ private boolean hasSideEffectAsPse(JCas jcas, PotentialSideEffect pse, String input) { //if the pse sentence contains certain word, return false if(input.matches(".*(dicussed|concerned).*")) return false; //if pse!=sideEffectWord, return false String str = pse.ne.getCoveredText().replace('-', ' ').toLowerCase().trim(); if(!sideEffectWord.contains(str)) return false; //if there is PSE, return false if(input.matches(".*(<PSE>).*")) return false; return true; }
/** * 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(); }
static private String createBsvLine( final IdentifiedAnnotation annotation, final UmlsConcept concept, final String locationCuis ) { final StringBuilder sb = new StringBuilder(); sb.append( concept.getCode() ).append( '|' ) .append( concept.getPreferredText() ).append( '|' ) .append( SemanticTui.getTuiFromCode( concept.getTui() ).getGroupName() ).append( '|' ) .append( annotation.getPolarity() == CONST.NE_POLARITY_NEGATION_PRESENT ? "true" : "false" ).append( '|' ) .append( annotation.getSubject().equals( CONST.ATTR_SUBJECT_FAMILY_MEMBER ) ? "true" : "false" ).append( '|' ) .append( locationCuis ).append( '|' ) .append( annotation.getCoveredText() ); return sb.toString(); }
@Override public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs( JCas identifiedAnnotationView, Annotation sentence) { List<IdentifiedAnnotationPair> pairs = super.getCandidateRelationArgumentPairs(identifiedAnnotationView, sentence); // look for sentences with one entity and one modifier List<IdentifiedAnnotationPair> result = new ArrayList<IdentifiedAnnotationPair>(); if (pairs.size() == 1) { IdentifiedAnnotationPair pair = pairs.get(0); if(Utils.validateDegreeOfArgumentTypes(pair)) { System.out.println(sentence.getCoveredText()); System.out.println("arg1: " + pair.getArg1().getCoveredText()); System.out.println("arg2: " + pair.getArg2().getCoveredText()); System.out.println(); result.add(pair); } } return result; }
private List<CollectionTextRelationIdentifiedAnnotationPair> getExactStringMatchPairs( JCas jcas, IdentifiedAnnotation mention, int sentDist) { List<CollectionTextRelationIdentifiedAnnotationPair> pairs = new ArrayList<>(); if(markableStrings.contains(mention.getCoveredText().toLowerCase())){ for(CollectionTextRelation cluster : JCasUtil.select(jcas, CollectionTextRelation.class)){ Annotation mostRecent = ClusterUtils.getMostRecent((NonEmptyFSList)cluster.getMembers(), mention); if(mostRecent == null) continue; for(Markable m : JCasUtil.select(cluster.getMembers(), Markable.class)){ if(m == mostRecent) break; // see if any of the members of the cluster have the exact same string as this if(m.getCoveredText().toLowerCase().equals(mention.getCoveredText().toLowerCase())){ pairs.add(new CollectionTextRelationIdentifiedAnnotationPair(cluster, mention)); break; } } } } return pairs; }
@Override public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs( JCas identifiedAnnotationView, Annotation sentence) { List<IdentifiedAnnotationPair> pairs = super.getCandidateRelationArgumentPairs(identifiedAnnotationView, sentence); // look for sentences with one entity and one modifier List<IdentifiedAnnotationPair> result = new ArrayList<IdentifiedAnnotationPair>(); if (pairs.size() == 1) { IdentifiedAnnotationPair pair = pairs.get(0); if(Utils.validateDegreeOfArgumentTypes(pair)) { System.out.println(sentence.getCoveredText()); System.out.println("arg1: " + pair.getArg1().getCoveredText()); System.out.println("arg2: " + pair.getArg2().getCoveredText()); System.out.println(); result.add(pair); } } return result; }
private List<CollectionTextRelationIdentifiedAnnotationPair> getExactStringMatchPairs( JCas jcas, IdentifiedAnnotation mention, int sentDist) { List<CollectionTextRelationIdentifiedAnnotationPair> pairs = new ArrayList<>(); if(markableStrings.contains(mention.getCoveredText().toLowerCase())){ for(CollectionTextRelation cluster : JCasUtil.select(jcas, CollectionTextRelation.class)){ Annotation mostRecent = ClusterUtils.getMostRecent((NonEmptyFSList)cluster.getMembers(), mention); if(mostRecent == null) continue; for(Markable m : JCasUtil.select(cluster.getMembers(), Markable.class)){ if(m == mostRecent) break; // see if any of the members of the cluster have the exact same string as this if(m.getCoveredText().toLowerCase().equals(mention.getCoveredText().toLowerCase())){ pairs.add(new CollectionTextRelationIdentifiedAnnotationPair(cluster, mention)); break; } } } } return pairs; }
private void printContext(String text, IdentifiedAnnotation mention, int radius) { int mentionBegin = mention.getBegin(); int mentionEnd = mention.getEnd(); StringBuilder sb = new StringBuilder(); int snipBegin; int snipEnd; snipBegin = (mentionBegin-radius<0)? 0 : mentionBegin-radius; snipEnd = (mentionEnd+radius>text.length()-1)? text.length()-1 : mentionEnd+radius; String[] tmp = mention.getClass().getName().split("\\."); String semGroup = tmp[tmp.length-1]; sb.append(text.substring(snipBegin, mentionBegin)); sb.append("[[["+mention.getCoveredText()+"]]]"); sb.append(text.substring(mentionEnd, snipEnd)); // sb.toString().replaceAll("\\n", "\\n| "); System.out.println("| "+ sb.toString().replaceAll("\\n", "\n| ")); System.out.println(": "+ semGroup + " : beg=" + mention.getBegin() + " : end=" + mention.getEnd() + " : c=" + mention.getConditional() + " : g=" + mention.getGeneric() + " : h=" + mention.getHistoryOf() + " : p=" + mention.getPolarity() + " : s=" + mention.getSubject() + " : u=" + mention.getUncertainty()); }
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]", " ")); }
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(); }