ctakes-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Finan, Sean" <Sean.Fi...@childrens.harvard.edu>
Subject RE: BagOfCuisGenerator.java, same idea for getConceptText()
Date Thu, 12 Feb 2015 20:21:20 GMT
Try something like the following for output:

   private int extractFeatures( final IdentifiedAnnotation annotation )  {
      // Extract the IdentifiedAnnotation itself
      final Collection<String> umlsInfos = getUmlsInfos( annotation, _printSnomed );
      if ( umlsInfos  == null ) {
         return 0;
      }
      final int begin = annotation.getBegin();
      final int end = annotation.getEnd();
      final String annotationText = annotation.getCoveredText();
      final int polarity = annotation.getPolarity();
      int count = 0;
      for ( String umlsInfo : umlsInfos ) {
         saveAnnotation( annotationText, umlsInfo, polarity, begin, end );
         count++;
      }
      return count;
   }

   static private Collection<String> getUmlsInfos( final IdentifiedAnnotation identifiedAnnotation
) {
      final FSArray fsArray = identifiedAnnotation.getOntologyConceptArr();
      if ( fsArray == null ) {
         return Collections.emptySet();
      }
      final FeatureStructure[] featureStructures = fsArray.toArray();
      final Set<String> umlsInfos = new HashSet<String>( featureStructures.length
);
      for ( FeatureStructure featureStructure : featureStructures ) {
         final OntologyConcept ontologyConcept = (OntologyConcept) featureStructure;
         String info = null;
         if ( ontologyConcept instanceof UmlsConcept ) {
            final UmlsConcept umlsConcept = (UmlsConcept) ontologyConcept;
            info = umlsConcept.getCui();
            final String tui = umlsConcept.getTui();
            if ( tui != null && !tui.isEmpty() ) {
               info += "_" + tui;
            }
            final String preferredText = umlsConcept.getPreferredText();
            if ( preferredText != null && !preferredText.isEmpty() ) {
               info += " = \"" + preferredText + "\"";
            }
            umlsInfos.add( info );
         }
      }
      return umlsInfos;
   }

   public void saveAnnotation( final String spannedText, final String umlsInfo, final int
polarity,
                               final int begin, final int end  )  {
      final String text = begin + "," + end + " " + (polarity < 0 ? "-" : " ") + umlsInfo
+ " " + spannedText;
      if ( _writer == null ) {
         System.out.println( text );
         return;
      }
      try {
         _writer.write( text );
         _writer.newLine();
      } catch ( IOException ioE ) {
         logger.error( ioE.getMessage() );
      }
   }
-----Original Message-----
From: Maite Meseure Hugues [mailto:meseure.maite@gmail.com] 
Sent: Thursday, February 12, 2015 2:46 PM
To: dev@ctakes.apache.org
Subject: BagOfCuisGenerator.java, same idea for getConceptText()

Hi everyone,

I am currently working on BagOfCuisGenerator, and I would like to add the concept text to
the output.
I 've seen some discussions about getting the original text and UMLS preferred text in addition
to the cui. Can someone give me pointers to do that?
Thanks in advance for your time.

Maite

--
--
 Maïté Meseure Hugues
Mime
View raw message