Package edu.pitt.terminology

Examples of edu.pitt.terminology.Terminology


  /**
   * @param args
   */
  public static void main(String[] args) throws Exception {
    IndexFinderTerminology.setPersistenceDirectory(new File("/home/tseytlin/Data/Terminologies/IndexFinder"));
    Terminology terminology = new IndexFinderTerminology("TIES_Pathology");
    //Terminology terminology = new IndexFinderTerminology("NCI_Thesaurus");
    PathHelper ph = new PathHelper(terminology);
    //ph.createAncestryCache();
    for(String text: Arrays.asList("melanoma","nevus","skin","margin")){
      for(Concept c: terminology.search(text)){
        long t = System.currentTimeMillis();
        // lookup paths
       
        List<ConceptPath> path = ph.getPaths(c);
        t = System.currentTimeMillis()-t;
View Full Code Here


    BufferedWriter mrsab = new BufferedWriter(new FileWriter(new File(dir,"MRSAB"),append));
    BufferedWriter mrdef = new BufferedWriter(new FileWriter(new File(dir,"MRDEF"),append));
    BufferedWriter codes = new BufferedWriter(new FileWriter(new File(dir,"CUI2CODE"),append));

    Set<Source> sources = new TreeSet<Source>();
    Terminology term = null;
   
    // iterate over all concepts
    for(Concept c: concepts){
      String cui = getCUI(c.getCode());
      String code = c.getCode();
     
      for(Term t: c.getTerms()){
        // save term information in MRCON
        // C0002871|ENG|P|L0002871|VC|S0352787|ANEMIA|0|
        String lat = t.getLanguage() == null?"ENG":t.getLanguage();
        String ts =  t.isPreferred()?"P":"S";
        String lui = getLUI(t.getText());
        String stt = t.isPreferred()?"PF":"VO";
        String sui = getSUI(t.getText());
        String str = t.getText();
        String lrl = "0";
       
        // write out
        mrcon.write(cui+I+lat+I+ts+I+lui+I+stt+I+sui+I+str+I+lrl+I+"\n");
        mrcon.flush();
       
        // save term information in MRSO
        // C0002871|L0002871|S0013742|SNOMEDCT|OP|154786001|9|
        Source src = t.getSource();
        if(src == null && c.getSources().length > 0)
          src = c.getSources()[0];
        String sab  = src != null?src.getName():"";
        String tty = t.isPreferred()?"PT":"NP";
        //String tty = t.getForm() != null && !compat?t.getForm():"SY";
        String scode = (c.getCodes() != null && src != null && c.getCodes().containsKey(src))?""+c.getCodes().get(src):cui;
       
        mrso.write(cui+I+lui+I+sui+I+sab+I+tty+I+scode+I+lrl+I+"\n");
        mrso.flush();
      }
     
      // save MRDEF information in MRDEF
      // C0002871|CSP|subnormal levels or function of erythrocytes, resulting in symptoms of tissue hypoxia.|
      for(Definition d: c.getDefinitions()){
        Source src = d.getSource();
        if(src == null && c.getSources().length > 0)
          src = c.getSources()[0];
        String sab = src != null?src.getName():"";
        String def = d.getDefinition();
        mrdef.write(cui+I+sab+I+def+I+"\n");
        mrdef.flush();
      }
      // save MRSTY information
      // C0000005|T121|Pharmacologic Substance||
      if(compat){
        String tui = "T071";
        String sty = "Entity";
        mrsty.write(cui+I+tui+I+sty+I+"\n");
        mrsty.flush();
      }else{
        for(SemanticType st: c.getSemanticTypes()){
          String tui = getTUI(st);
          String sty = st.getName();
          mrsty.write(cui+I+tui+I+sty+I+"\n");
          mrsty.flush();
        }
      }
      // add to sources
      Collections.addAll(sources,c.getSources())
     
      // save terminology
      if(term == null && c.getTerminology() != null)
        term = c.getTerminology();
     
      // keep track of translation
      codes.write(cui+"="+code+"\n");
      codes.flush();
    }
   
    // if possible use sources from terminology, cuase they have more data
    if(term != null && term.getSources().length > 0){
      Set<Source> tsources = new TreeSet<Source>();
      for(Source s: term.getSources()){
        if(sources.contains(s)){
          tsources.add(s);
        }
      }
      sources = tsources;
View Full Code Here

    BufferedWriter mrdef = new BufferedWriter(new FileWriter(new File(dir,"MRDEF.RRF"),append));
    BufferedWriter mrsab = new BufferedWriter(new FileWriter(new File(dir,"MRSAB.RRF"),append));
    BufferedWriter codes = new BufferedWriter(new FileWriter(new File(dir,"CUI2CODE"),append));

    Set<Source> sources = new TreeSet<Source>();
    Terminology term = null;
   
    // iterate over all concepts
    for(Concept c: concepts){
      String cui = getCUI(c.getCode());
      String code = c.getCode();
     
      // save term information in MRCONSO
      // C0000005|ENG|P|L0187013|PF|S2192303|Y|A4332670||M0019694|D012711|MSH|EN|D012711|(131)I-MAA|0|N||
      for(Term t: c.getTerms()){
        Source src = t.getSource();
        if(src == null && c.getSources().length > 0)
          src = c.getSources()[0];
        String lat = t.getLanguage() == null?"ENG":t.getLanguage();
        String ts =  t.isPreferred()?"P":"S";
        String lui = getLUI(t.getText());
        String stt = t.isPreferred()?"PF":"VO";
        String sui = getSUI(t.getText());
        String pref = t.isPreferred()?"Y":"N";
        String aui = String.format("A%07d",atomCount);
        String saui = "";
        String scui = "";
        String sdui = "";
        String sab  = src != null?src.getName():"";
        String tty = t.getForm() != null?t.getForm():"SY";
        String scode = (c.getCodes() != null && src != null && c.getCodes().containsKey(src))?""+c.getCodes().get(src):cui;
        String str = t.getText();
        String srl = "0";
        String sup  = "N";
        String cvf = "";
       
        // write out
        mrconso.write(cui+I+lat+I+ts+I+lui+I+stt+I+sui+I+pref+I+aui+I+saui+I+scui+I+sdui+I+sab+I+tty+I+scode+I+str+I+srl+I+sup+I+cvf+"\n");
        mrconso.flush();
        atomCount ++;
      }
      // save MRDEF information in MRDEF
      // C0000107|A3857241|AT22515555||MSH|An ANGIOTENSIN II analog which acts as a highly specific inhibitor of ANGIOTENSIN TYPE 1 RECEPTOR.|N||
      for(Definition d: c.getDefinitions()){
        Source src = d.getSource();
        if(src == null && c.getSources().length > 0)
          src = c.getSources()[0];
        String aui = "";
        String atui = "";
        String satui = "";
        String sab = src != null?src.getName():"";
        String def = d.getDefinition();
        String sup = "N";
        String cvf = "";
        mrdef.write(cui+I+aui+I+atui+I+satui+I+sab+I+def+I+sup+I+cvf+"\n");
        mrdef.flush();
      }
      // save MRSTY information
      // C0000005|T121|A1.4.1.1.1|Pharmacologic Substance|AT16627324||
      for(SemanticType st: c.getSemanticTypes()){
        String tui = getTUI(st);
        String stn = "";
        String sty = st.getName();
        String atui = "";
        String cvf = "";
        mrsty.write(cui+I+tui+I+stn+I+sty+I+atui+I+cvf+"\n");
        mrsty.flush();
      }
      // add to sources
      Collections.addAll(sources,c.getSources())
     
      // save terminology
      if(term == null && c.getTerminology() != null)
        term = c.getTerminology();
     
      // keep track of translation
      codes.write(cui+"="+code+"\n");
      codes.flush();
    }
   
    // if possible use sources from terminology, cuase they have more data
    if(term != null && term.getSources().length > 0){
      Set<Source> tsources = new TreeSet<Source>();
      for(Source s: term.getSources()){
        if(sources.contains(s)){
          tsources.add(s);
        }
      }
      sources = tsources;
View Full Code Here

  /**
   * create a template from terminology where each root is a template item
   * @param url
   */
  private void addTerminologyTemplate(String url) throws Exception {
    Terminology terminology = new IndexFinderTerminology(url);
   
    // setup template
    Template template = new Template();
    template.setName(terminology.getName()+" Template");
    template.setDescription(terminology.getDescription());
    template.setTerminology(terminology);
    template.getFilters().add(new DocumentFilter("(?s)^BACKGROUND:$.*^$",true));
   
    for(Concept c: terminology.getRootConcepts()){
      TemplateItem item = new TemplateItem();
      /*     
      {
        //TODO: this is a hack for BRAF, let it stay for now?
        public List<ItemInstance> process(AnnotatedDocument doc) throws TerminologyException {
View Full Code Here

    // now that we have the type
    if(terminologies.containsKey(type))
      return terminologies.get(type);
   
    // else init terminology
    Terminology term = null;
    try{
      if("umls".equalsIgnoreCase(type)){
        String [] p = terminologyParams.get(type).split("\\|");
        if(p.length == 4)
          term = new UMLSTerminology(p[0].trim(),p[1].trim(),p[2].trim(),p[3].trim());
View Full Code Here

    servletName = req.getContextPath()+"/"+req.getServletPath();
    String response = "";
    String action = req.getParameter("action");
   
    try{
      Terminology terminology = getTerminology(req.getParameter("term"));
      if ( action == null ) {
        response = "Unrecognized parameter"
      }else if (action.equals("set_sources")){
        String src  = req.getParameter("src");
        Source [] srcs = (src != null)?terminology.getSources(src):null;
        terminology.setFilterSources(srcs);
      }else if (action.equals("get_terminologies")){
        response = processOutput(terminologyParams.keySet());
      }else if ( action.equals("search")){
        String text = req.getParameter("text");
        //check if in fact we want to lookup concept
        Object c = null;
        if(text.matches("CL?\\d+") || text.startsWith("http://")){
          c = terminology.lookupConcept(text.trim());
        }else if("ROOT".equals(text)){
          c = terminology.getRootConcepts();
        }else{
          c = terminology.search(text);
        }
        response = processOutput(c);
      }else if ( action.equals("get_roots")){
        response = processOutput(terminology.getRootConcepts());
      }else if ( action.equals("lookup_concept")){
        String text = req.getParameter("code");
        Concept c = terminology.lookupConcept(text.trim());
        response = processOutput(c);
      }else if ( action.equals("get_sources")){
        Source [] src = terminology.getSources();
        response = processOutput(src);
      }else if ( action.equals("get_related_concepts")){
        String code = req.getParameter("code");
        String rel  = req.getParameter("relation");
        Concept c = terminology.lookupConcept(code.trim());
       
        /*
        try{
          code = URLDecoder.decode(code,"utf-8");
        }catch(Exception ex){}
        */
       
        // find relationship
        if(c != null){
          Relation r = Relation.BROADER; // default
          rel = rel.toLowerCase();
          Relation [] rs = c.getRelations();
          for(int i=0;i<rs.length;i++){
            if(rs[i].getName().toLowerCase().contains(rel) ||
               rs[i].getCode().toLowerCase().contains(rel)){
              r = rs[i];
              break;
            }
          }
          Concept [] cs = terminology.getRelatedConcepts(c, r);
          response = processOutput(cs);
        }else{
          response = processOutput(new Concept [0]);
        }
      }else if ( action.equals("get_related_concept_map")){
        String code = req.getParameter("code");
        Concept c = terminology.lookupConcept(code);
        // find relationship
        Map cs = terminology.getRelatedConcepts(c);
        response = processOutput(cs);
      }
    }catch(TerminologyException ex){
      response = "Terminology Error: "+ex.getMessage();
      ex.printStackTrace();
View Full Code Here

   * @param t
   * @return
   */
  private String getTerminologyCode(Terminology t){
    for(String key: terminologies.keySet()){
      Terminology val = terminologies.get(key);
      if(t.equals(val))
        return key;
    }
    return null;
  }
View Full Code Here

    String action = parcel.getAction();
    Object tosend = null;

    // perform appropriate action
    try{
      Terminology terminology = getTerminology(parcel.getProperties().getProperty("term"));
      if ( action == null ) {
        // do nothing
      }else if ( action.equals("set_sources")){
        Source [] src = (Source []) parcel.getPayload();
        terminology.setFilterSources(src);
      }else if ( action.equals("search")){
        String txt = (String) parcel.getPayload();
        tosend = terminology.search(txt);
      }else if ( action.equals("lookup_concept")){
        tosend = terminology.lookupConcept((String) parcel.getPayload());
      }else if ( action.equals("get_sources")){
        tosend = terminology.getSources();
      }else if ( action.equals("get_related_concepts")){
        Object [] p = (Object []) parcel.getPayload();
        Concept c = (Concept) p[0];
        Relation r = (Relation) p[1];
        tosend = terminology.getRelatedConcepts(c, r);
      }else if ( action.equals("get_related_concept_map")){
        Concept c = (Concept) parcel.getPayload();
        tosend = terminology.getRelatedConcepts(c);
      }else if ( action.equals("get_terminologies")){
        tosend = terminologyParams.keySet();
      }
    }catch(TerminologyException ex){
      ex.printStackTrace();
View Full Code Here

    }

    sb.append("searchString: " + c.getSearchString() + "\n");
    c.getProperties();

    Terminology term = c.getTerminology();
    sb.append("terminology name: " + term.getName() + "\n");
    c.getTerms();
    c.getText();
    c.getWordMap();

    c.getRelatedConcepts();
View Full Code Here

   */
  public static void main(String[] args) throws Exception{
    //String server = "http://lexevsapi.nci.nih.gov/lexevsapi50/";
    String server = "http://lexevsapi60.nci.nih.gov/lexevsapi60/";
    //String server = "http://lexevsapi51.nci.nih.gov/lexevsapi51#NCI MetaThesaurus";
    Terminology term = new LexEVSRestTerminology(server);
    long time = System.currentTimeMillis();
    // ZFA_0001234 | C0025202
    System.out.println("--- lookup ---");
    Concept c = term.lookupConcept("C0025202");
    if(c != null){
      c.printInfo(System.out);
    }
    System.out.println("lookup time "+(System.currentTimeMillis()-time));
   
    System.out.println("--- search ---");
   
    time = System.currentTimeMillis();
    Concept [] cs = term.search("melanoma");
    for(Concept i: cs){
      i.printInfo(System.out);
    }
    System.out.println("lookup time "+(System.currentTimeMillis()-time));
  }
View Full Code Here

TOP

Related Classes of edu.pitt.terminology.Terminology

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.