Package edu.pitt.dbmi.nlp.noble.terminology

Examples of edu.pitt.dbmi.nlp.noble.terminology.Source


  }
 
  public Source[] getSources() {
    if(storage != null && !storage.getSourceMap().isEmpty())
      return storage.getSourceMap().values().toArray(new Source [0]);
    return new Source[]{new Source(getName(),getDescription(),""+getURI())};
  }
View Full Code Here


   
    // get child element
    for(Element e: XMLUtils.getChildElements(element)){
      if("Sources".equals(e.getTagName())){
        for(Element cc: XMLUtils.getElementsByTagName(e,"Source")){
          Source c = new Source("");
          c.fromElement(cc);
          storage.getSourceMap().put(c.getName(),c);
        }
      }else if("Relations".equals(e.getTagName())){
        //NOOP
      }else if("Languages".equals(e.getTagName())){
        storage.getInfoMap().put("languages",e.getTextContent().trim());
      }else if("Roots".equals(e.getTagName())){
        for(String r: e.getTextContent().trim().split(",")){
          storage.getRootMap().put(r.trim(),"");
        }
      }else if("Description".equals(e.getTagName())){
        storage.getInfoMap().put("description",e.getTextContent().trim());
      }else if("Concepts".equals(e.getTagName())){
        for(Element cc: XMLUtils.getElementsByTagName(e,"Concept")){
          Concept c = new Concept("");
          c.fromElement(cc);
          addConcept(c);
        }
      }else if("Options".equals(e.getTagName())){
        Properties p = new Properties();
        for(Element op: XMLUtils.getElementsByTagName(e,"Option")){
View Full Code Here

  private Source[] iOntologiesToSource(IOntology[] iontologies) {
    Source[] sources = new Source[iontologies.length];

    for (int i = 0; i < iontologies.length; i++)
      sources[i] = new Source(iontologies[i].getName());

    return sources;
  }
View Full Code Here

      if(properties.containsKey(CODE)){
        Object val = properties.get(CODE);
        int i = 0;
        if(val instanceof Collection){
          for(Object o :(Collection) val)
            concept.addCode(""+o,new Source("SOURCE"+(i++)));
        }else
          concept.addCode(""+val,new Source("SOURCE"+i));
      }
     
      // add semantic types
      if(properties.containsKey(SEMANTIC_TYPE)){
        Object val = properties.get(SEMANTIC_TYPE);
View Full Code Here

  public Map<String,Concept> loadOBO(File file) throws IOException, TerminologyException {
    Map<String,Concept> list = new LinkedHashMap<String,Concept>();
    String name = file.getName();
    if(name.endsWith(".obo"))
      name = name.substring(0,name.length()-4);
    Source src = Source.getSource(name);
   
    BufferedReader r = null;
    try{
      r = new BufferedReader(new FileReader(file));
      Concept c = null;
      Pattern p = Pattern.compile("\"(.*)\"\\s*([A-Z_]*)\\s*(.*)?\\[.*\\]");
      for(String l=r.readLine();l != null;l=r.readLine()){
        if("[Term]".equals(l.trim())){
          addConcept(list,c);
          c = new Concept("X");
          c.addSource(src);
        }else if(c != null){
          int i = l.indexOf(':');
          if(i > -1){
            String key = l.substring(0,i).trim();
            String val = l.substring(i+1).trim();
           
            // fill in values
            if("id".equals(key)){
              c.setCode(val);
            }else if("name".equals(key)){
              c.setSynonyms(new String [0]);
              c.setName(val);
              Term t = Term.getTerm(val);
              t.setPreferred(true);
              c.addTerm(t);
            }else if("namespace".equals(key)){
              c.addSemanticType(SemanticType.getSemanticType(val));
            }else if("def".equals(key)){
              Matcher m = p.matcher(val);
              if(m.matches())
                val = m.group(1);
              c.addDefinition(Definition.getDefinition(val));
            }else if(key != null && key.matches("(exact_|narrow_|broad_)?synonym")){
              Matcher m = p.matcher(val);
              String form = null;
              if(m.matches()){
                val = m.group(1);
                form = m.group(2);
              }
              Term t = Term.getTerm(val);
              if(form != null)
                t.setForm(form);
              c.addTerm(t);
            }else if("is_a".equals(key)){
              int j = val.indexOf("!");
              if(j > -1)
                val = val.substring(0,j).trim();
              c.addRelatedConcept(Relation.BROADER,val);
              Concept pr = list.get(val);
              if(pr != null)
                pr.addRelatedConcept(Relation.NARROWER,c.getCode());
            }else if("relationship".equals(key)){
              int j = val.indexOf("!");
              int k = val.indexOf(" ");
              if(k > -1){
                String rel = val.substring(0,k).trim();
                if(j > -1)
                  val = val.substring(k,j).trim();
                c.addRelatedConcept(Relation.getRelation(rel),val);
              }
            }else if("is_obsolete".equals(key)){
              if(Boolean.parseBoolean(val)){
                c = null;
              }
            }else if("consider".equals(key)){
              // NOOP only relevant when term is obsolete
            }else if("comment".equals(key)){
              // NOOP only relevant when term is obsolete
            }else if("alt_id".equals(key)){
              c.addCode(val,Source.getSource(""));
            }else if("subset".equals(key)){
              // NOOP, don't know what to do with that
            }else if("xref".equals(key)){
              // NOOP, handle external references
            }
          }
        }else if(l.startsWith("default-namespace:")){
          src.setDescription(l.substring("default-namespace:".length()+1).trim());
        }
      }
      addConcept(list,c);
    }catch(IOException ex){
      throw ex;
View Full Code Here

    // save meta information
    storage.getInfoMap().put("name",""+ontology.getName());
    storage.getInfoMap().put("description",""+ontology.getDescription());
    storage.getInfoMap().put("version",""+ontology.getVersion());
    storage.getInfoMap().put("uri",""+ontology.getURI().toASCIIString());
    Source src = Source.getSource(""+ontology.getName());
    src.setDescription(ontology.getDescription());
    storage.getSourceMap().put(ontology.getName(),src);
   
    // get all classes
    pcs.firePropertyChange(LOADING_MESSAGE,null,"Iterating Over Ontology Classes ...");
    pcs.firePropertyChange(LOADING_TOTAL,null,0);
View Full Code Here

          i++;
          continue;
        }
        //http://www.ncbi.nlm.nih.gov/books/NBK9685/table/ch03.T.source_information_file__mrsabrrf/?report=objectonly
        String [] fields = line.split("\\|");
        Source src = new Source(fields[3].trim());
        src.setDescription(fields[4]); // fields.length-1
        if(filterSources != null && filterSources.contains(src.getName())){
          storage.getSourceMap().put(src.getName(),src);
        }
        i++;
        storage.getInfoMap().put(RRFile,""+i);
      }
      r.close();
    }else{
      pcs.firePropertyChange(LOADING_MESSAGE,null,"Skipping "+RRFile+" file ...");
    }
     
   
    // save meta information
    pcs.firePropertyChange(LOADING_MESSAGE,null,"Saving Meta Information ...");
    storage.commit(storage.getInfoMap());
    storage.commit(storage.getSourceMap());
   
    // lets first build a map of concepts using existing concept map
    storage.useTempWordFolder = true;
    String prefNameSource = null;
    offset = 0;
    RRFile = "MRCONSO.RRF";
    if(!new File(dir,RRFile).exists())
      throw new TerminologyException("RRF file "+(new File(dir,RRFile).getAbsolutePath()+" does not exist!"));
   
    if(storage.getInfoMap().containsKey(RRFile)){
      offset = Integer.parseInt(storage.getInfoMap().get(RRFile));
    }
    // if offset is smaller then total, read file
    if(offset < rowCount.get(RRFile)){
      i = 0;
      pcs.firePropertyChange(LOADING_MESSAGE,null,"Loading "+RRFile+" file ...");
      pcs.firePropertyChange(LOADING_TOTAL,null,rowCount.get(RRFile));
      r = new BufferedReader(new FileReader(new File(dir,RRFile)));
      Concept previousConcept = null;
      //boolean crash = false;
      for(String line = r.readLine(); line != null; line = r.readLine()){
        if(i < offset){
          i++;
          continue;
        }
        // parse each line ref: http://www.ncbi.nlm.nih.gov/books/NBK9685/table/ch03.T.concept_names_and_sources_file__m/?report=objectonly
        String [] fields = line.split("\\|");
        if(fields.length >= 14 ){
          String cui = fields[0].trim();
          String ts =  fields[2].trim();
          String src  = fields[11].trim();
          String text = fields[14].trim();
          String lang = fields[1].trim();
          String form = fields[12].trim();
          String code = fields[13].trim();
          String pref = fields[6].trim();
          String sup  = fields[16].trim();
         
          Source source = Source.getSource(src);
         
          // display progress bar
          if((i % 10000) == 0){
            pcs.firePropertyChange(LOADING_PROGRESS,null,i);
            storage.commit(storage.getInfoMap());
View Full Code Here

              if("org.LexGrid.concepts.Presentation".equals(m.get("name"))){
                String pt = ""+m.get("_isPreferred");
                String text = null;
                String lang = (String) m.get("_language");
                String form = (String) m.get("_representationalForm");
                Source src = null;
               
                // get content
                Map tm = ((List<Map>) m.get("_value")).get(0);
                if("org.LexGrid.commonTypes.Text".equals(tm.get("name"))){
                  text = ""+tm.get("_content");
                  synonyms.add(text.trim());
                }
               
                // get source
                List<Map> sl = (List<Map>) m.get("_sourceList");
                if(sl != null && !sl.isEmpty()){
                  Map sm = sl.get(0);
                  if("org.LexGrid.commonTypes.Source".equals(sm.get("name"))){
                    String s = (String) sm.get("_content");
                    if(s != null){
                      src = new Source(s);
                      sources.add(src);
                    }
                  }
                }
               
                if(text != null){
                  Term term = new Term(text);
                  term.setPreferred(Boolean.parseBoolean(pt));
                  term.setLanguage(lang);
                  term.setForm(form);
                  if(src != null)
                    term.setSource(src);
                  terms.add(term);
                }
              }
            }
          }
         
          // set definitions and terms
          List<Definition> defs = new ArrayList<Definition>();
          if(content.containsKey("_definitionList")){
            for(Map m: (List<Map>) content.get("_definitionList")){
              if("org.LexGrid.concepts.Definition".equals(m.get("name"))){
                String text = null;
                Source src = null;
               
                Map tm = ((List<Map>) m.get("_value")).get(0);
                if("org.LexGrid.commonTypes.Text".equals(tm.get("name"))){
                  text = ""+tm.get("_content");
                }
                // get source
                List<Map> sl = (List<Map>) m.get("_sourceList");
                if(sl != null && !sl.isEmpty()){
                  Map sm = sl.get(0);
                  if("org.LexGrid.commonTypes.Source".equals(sm.get("name"))){
                    String s = (String) sm.get("_content");
                    if(s != null){
                      src = new Source(s);
                    }
                  }
                }
               
                if(text != null){
View Full Code Here

        ResultSet result =  st.executeQuery();
        while(result.next()){
          String src  = result.getString("rsab");
          String text = result.getString("son");
         
          Source source = Source.getSource(src);
          source.setDescription(text);
         
          srcs.add(source);

        }
        result.close();
View Full Code Here

        String text = result.getString("str");
        String lang = result.getString("lat");
        String form = result.getString("tty");
        String code = result.getString("code");
        String pref = result.getString("ispref");
        Source source = Source.getSource(src);
       
        Term term = new Term(text);
        term.setForm(form);
        term.setLanguage(lang);
        term.setSource(source);
View Full Code Here

TOP

Related Classes of edu.pitt.dbmi.nlp.noble.terminology.Source

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.