CLEiM
Cross Lingual Education in Medicine
 All Classes Namespaces Files Functions Variables
NCBOAnnot.java
Go to the documentation of this file.
00001 package com.uem.gsi.cleim.nlp;
00002 import java.util.List;
00003 import java.util.ArrayList;
00004 import java.util.Vector;
00005 
00006 import org.w3c.dom.Node;
00007 import org.w3c.dom.NodeList;
00008 
00009 import com.uem.gsi.cleim.util.MyDOMParser;
00010 
00011 
00012 public class NCBOAnnot {
00016         //private List<String> lOntoAnnot;
00017         private List<String> lConcept;
00018         private List<String> lGroup;
00019         private List<String> lLocalOntologyId;
00020         private List<String> lFullId;
00021         private List<String> lIsDirect;
00022         private List<String> lFrom;
00023         private List<String> lTo;
00024         private List<String> lPreferredName;
00025         private List<String> lContextName;
00026 
00027         public NCBOAnnot(){
00028         //List of anotations
00029         //lOntoAnnot = new ArrayList<String>();
00030                 lConcept = new ArrayList<String>();
00031                 lGroup = new ArrayList<String>();
00032         lLocalOntologyId = new ArrayList<String>();
00033         lFullId = new ArrayList<String>();
00034         lIsDirect = new ArrayList<String>();
00035         lFrom = new ArrayList<String>();
00036         lTo = new ArrayList<String>();
00037         lPreferredName = new ArrayList<String>();
00038         lContextName = new ArrayList<String>();
00039   }
00040   public void runNCBOAnnot(String text,String onts,String lev) throws Exception{
00041         CallNCBO oNCBO=new CallNCBO();
00042                 oNCBO.setText(text);
00043                 oNCBO.setOntInRes(onts);
00044                 oNCBO.setLevelMax(lev);
00045                 String xml=oNCBO.doRESTQuery();
00046                 //System.out.println(xml);
00047                 org.w3c.dom.Document doc = MyDOMParser.getDocument(xml);
00048                 NodeList listAnnot=doc.getElementsByTagName("annotationBean");
00049                 for (int i=0;i<listAnnot.getLength();i++){
00050                         String from="",to="";
00051                   Node annotNode=listAnnot.item(i);
00052                   NodeList listChildAnnot=annotNode.getChildNodes();
00053                   for (int j=0;j<listChildAnnot.getLength();j++){
00054                     Node nodeTemp1=listChildAnnot.item(j);
00055                     //Concept
00056                     if (nodeTemp1.getNodeName().equals("concept")){
00057                       NodeList listChildRes=nodeTemp1.getChildNodes();
00058                       for (int k=0;k<listChildRes.getLength();k++){
00059                         Node node1=listChildRes.item(k);
00060                         String node1name=node1.getNodeName();
00061                         //Elements selection
00062                         if (node1name.equals("localOntologyId"))
00063                           lLocalOntologyId.add(node1.getFirstChild().getNodeValue().trim());
00064                         else if (node1name.equals("fullId"))
00065                           lFullId.add(node1.getFirstChild().getNodeValue().trim());
00066                         else if (node1name.equals("preferredName"))
00067                           lPreferredName.add(node1.getFirstChild().getNodeValue().trim().toUpperCase());
00068                         else if (node1name.equals("semanticTypes")){
00069                                 NodeList lsemantictypes=node1.getChildNodes();
00070                                 for (int m=0;m<lsemantictypes.getLength();m++){
00071                                         if (lsemantictypes.item(m).getNodeType()==1){
00072                                                 NodeList lsemanticDesc=lsemantictypes.item(m).getChildNodes();
00073                                                 for (int n=0;n<lsemanticDesc.getLength();n++){
00074                                                         if (lsemanticDesc.item(n).getNodeName().equals("description"))
00075                                                                 lGroup.add(lsemanticDesc.item(n).getTextContent());
00076                                                 }
00077                                         }
00078                                 }
00079                         }
00080                       }
00081                          
00082                     }//Context
00083                     else if (nodeTemp1.getNodeName().equals("context")){
00084                       NodeList listChildRes=nodeTemp1.getChildNodes();
00085                       for (int k=0;k<listChildRes.getLength();k++){
00086                         Node node1=listChildRes.item(k);
00087                         String node1name=node1.getNodeName();
00088                         //Elements
00089                         if (node1name.equals("contextName"))
00090                           lContextName.add(node1.getFirstChild().getNodeValue().trim());
00091                         else if (node1name.equals("isDirect"))
00092                           lIsDirect.add(node1.getFirstChild().getNodeValue().trim());
00093                         else if (node1name.equals("from"))
00094                                 from=node1.getFirstChild().getNodeValue().trim();
00095                         else if (node1name.equals("to"))
00096                                 to=node1.getFirstChild().getNodeValue().trim();
00097                           
00098                        }
00099                      }
00100                   }
00101                   int iFrom=new Integer(from)-1;
00102                   //lConcept.add(text.substring(iFrom,new Integer(to)).toUpperCase());
00103                   lConcept.add(text.substring(iFrom,new Integer(to)).toUpperCase());
00104                   lFrom.add(""+iFrom);
00105                   lTo.add(to);
00106                 }
00107         }
00108   /*public List<String> getAnnots(){
00109         return this.lOntoAnnot;
00110   }*/
00111   public List<String> getConcept(){
00112         return this.lConcept;
00113   }
00114   public List<String> getGroup(){
00115         return this.lGroup;
00116   }
00117   public List<String> getLocalOntologyId(){
00118         return this.lLocalOntologyId;
00119   }
00120   public List<String> getFullId(){
00121         return this.lFullId;
00122   }
00123   public List<String> getIsDirect(){
00124         return this.lIsDirect;
00125   }
00126   public List<String> getFrom(){
00127         return this.lFrom;
00128   }
00129   public List<String> getTo(){
00130         return this.lTo;
00131   }
00132   public List<String> getPreferredName(){
00133         return this.lPreferredName;
00134   }
00135   public List<String> getContextName(){
00136         return this.lContextName;
00137   }
00138         public static void main(String args[]) {
00139                 String onts="40397,46116";
00140                 String lev="";
00141                 String text= "UNDERLYING MEDICAL CONDITION: "+
00142     " 56 year old man with history of colon and testicular cancer, pons glioma now"+  
00143     " with significant hilar lymphadeonpathry, pulmonary pathology on CXR."+
00144     " REASON FOR THIS EXAMINATION: extracto de genciana colirio/gotas óticas"+
00145     " vagina no hiperestésica  56 year old man with history of colon and testicular cancer, pons glioma now"+  
00146     " Salmonella Irumu SIDA con visión deficiente with significant hilar lymphadeonpathry, pulmonary pathology on CXR."+
00147     " Suture of wound of forelimb Lumbar chemical sympathectomy"+
00148     " vía fístula mucosa No contraindications for IV contrast  pain back pain aspirin cáncer de próstata";
00149                 NCBOAnnot oNcbo=new NCBOAnnot();
00150                 try {
00151                         oNcbo.runNCBOAnnot(text, onts, lev);
00152                         List<String> lConcept=oNcbo.getConcept();
00153                         List<String> lGroup=oNcbo.getGroup();
00154                         List<String> lLocalOntologyId=oNcbo.getLocalOntologyId();
00155                         List<String> lFullId=oNcbo.getFullId();
00156                         List<String> lIsDirect=oNcbo.getIsDirect();
00157                         List<String> lFrom=oNcbo.getFrom();
00158                         List<String> lTo=oNcbo.getTo();
00159                         List<String> lPreferredName=oNcbo.getPreferredName();
00160                         List<String> lContextName=oNcbo.getContextName();
00161                         
00162                         for (int i=0;i<lConcept.size();i++){
00163                                 System.out.println("->Concept: "+lConcept.get(i));
00164                                 System.out.println("->Group: "+lGroup.get(i));
00165                                 System.out.println("->LocalOntologyId: "+lLocalOntologyId.get(i));
00166                                 System.out.println("->FullId: "+lFullId.get(i));
00167                                 System.out.println("->IsDirect: "+lIsDirect.get(i));
00168                                 System.out.println("->From: "+lFrom.get(i));
00169                                 System.out.println("->To: "+lTo.get(i));
00170                                 System.out.println("->PreferredName: "+lPreferredName.get(i));
00171                                 System.out.println("->ContextName: "+lContextName.get(i));
00172                         }
00173                 } catch (Exception e) {
00174                         // TODO Auto-generated catch block
00175                         e.printStackTrace();
00176                 }
00177         }
00178 }