ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1561107 - /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java
Date Fri, 24 Jan 2014 18:39:08 GMT
Author: dligach
Date: Fri Jan 24 18:39:08 2014
New Revision: 1561107

URL: http://svn.apache.org/r1561107
Log:
added code to retrieve UMLS info (like CUIs)

Modified:
    ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java

Modified: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java?rev=1561107&r1=1561106&r2=1561107&view=diff
==============================================================================
--- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java (original)
+++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/wsd/pipelines/Analyze.java Fri
Jan 24 18:39:08 2014
@@ -2,14 +2,23 @@ package org.apache.ctakes.wsd.pipelines;
 
 import java.io.File;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.ctakes.core.cr.XMIReader;
-import org.apache.ctakes.typesystem.type.textsem.EntityMention;
+import org.apache.ctakes.typesystem.type.refsem.OntologyConcept;
+import org.apache.ctakes.typesystem.type.refsem.UmlsConcept;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.ctakes.typesystem.type.textsem.MedicationMention;
 import org.apache.uima.analysis_engine.AnalysisEngine;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.cas.FSArray;
 import org.cleartk.util.Options_ImplBase;
 import org.kohsuke.args4j.Option;
 import org.uimafit.component.JCasAnnotator_ImplBase;
@@ -29,6 +38,8 @@ import com.google.common.collect.Lists;
  */
 public class Analyze {
 
+  public static final String GOLD_VIEW_NAME = "GoldView";
+  
   public static class Options extends Options_ImplBase {
 
     @Option(
@@ -69,10 +80,54 @@ public class Analyze {
 
     @Override
     public void process(JCas jCas) throws AnalysisEngineProcessException {
-      for (EntityMention mention : Lists.newArrayList(JCasUtil.select(jCas, EntityMention.class)))
{
-        System.out.println(mention.getCoveredText());
+      
+      JCas goldView;                                                                    
                                      
+      try {                                                                             
                                      
+        goldView = jCas.getView(GOLD_VIEW_NAME);                                        
                                      
+      } catch (CASException e) {                                                        
                                      
+        throw new AnalysisEngineProcessException(e);                                    
                                      
+      }   
+      
+      for (EventMention mention : Lists.newArrayList(JCasUtil.select(jCas, MedicationMention.class)))
{
+        
+        // avoid weird crashes
+        if(mention.getBegin() == 2147483647) {
+          continue;
+        }
+        
+        Set<String> codes = getOntologyConceptCodes(mention);
+        if(codes.size() != 1) {
+          System.out.println(mention.getCoveredText() + " - " + codes);
+        }
       }
     }
     
+    /**
+     * Get the CUIs, RxNorm codes, etc.
+     */
+    public static Set<String> getOntologyConceptCodes(IdentifiedAnnotation identifiedAnnotation)
{
+      
+      Set<String> codes = new HashSet<String>();
+      
+      FSArray fsArray = identifiedAnnotation.getOntologyConceptArr();
+      if(fsArray == null) {
+        return codes;
+      }
+      
+      for(FeatureStructure featureStructure : fsArray.toArray()) {
+        OntologyConcept ontologyConcept = (OntologyConcept) featureStructure;
+        
+        if(ontologyConcept instanceof UmlsConcept) {
+          UmlsConcept umlsConcept = (UmlsConcept) ontologyConcept;
+          String code = umlsConcept.getCui();
+          codes.add(code);
+        } else { // SNOMED or RxNorm
+          String code = ontologyConcept.getCodingScheme() + ontologyConcept.getCode();
+          codes.add(code);
+        }
+      }
+      
+      return codes;
+    }
   }
 }



Mime
View raw message