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

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


        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){
View Full Code Here


    //if(obj == null)
    //  System.err.println("object is null");
    StringBuffer buff = new StringBuffer();
    if(obj instanceof Concept){
      String clr = " bgcolor=\"#EEEEEE\"";
      Concept c = (Concept) obj;
      buff.append("<table border=0>");
      buff.append("<tr valign=top><td"+clr+">code</td><td>"+c.getCode()+"</td></tr>");
      buff.append("<tr valign=top><td"+clr+">name</td><td>"+c.getName()+"</td></tr>");
      SemanticType [] sem = c.getSemanticTypes();
      StringBuffer sembuff = new StringBuffer();
      if(sem != null && sem.length >0){
        for(int j=0;j<sem.length;j++)
          sembuff.append(sem[j].getName()+" ");
      }
      buff.append("<tr valign=top><td"+clr+">semantic types</td><td>"+sembuff+"</td></tr>");
      buff.append("<tr valign=top><td"+clr+">definitions</td><td><ul>");
      Definition [] def = c.getDefinitions();
      if(def != null)
        for(int j=0;j<def.length;j++)
          buff.append("<li>"+def[j].getDefinition()+" ["+def[j].getSource()+"]</li>");
      buff.append("</ul></td></tr>");
      buff.append("<tr valign=top><td"+clr+">synonyms</td><td>");
      String [] syn = c.getSynonyms();
      if(syn != null)
        for(int j=0;j<syn.length;j++)
          buff.append(syn[j]+", ");
      buff.append("</td></tr>");
      buff.append("<tr valign=top><td"+clr+">sources</td><td>");
      Source [] src = c.getSources();
      if(src != null)
        for(int j=0;j<src.length;j++)
          buff.append(src[j]+", ");
      buff.append("</td></tr>");
      buff.append("<tr valign=top><td"+clr+">relations</td><td>");
      Relation [] rs = c.getRelations();
      if(rs != null)
        for(int j=0;j<rs.length;j++){
          String code = c.getCode();
          try{
            code = URLEncoder.encode(c.getCode(),"utf-8");
          }catch(Exception ex){}
          String url = servletName+"?action=get_related_concepts&relation="+rs[j].getName()+"&code="+code;
          buff.append("<a href=\""+url+"\">"+rs[j].getName()+"</a>, ");
        }
      buff.append("</td></tr>");
      buff.append("<tr valign=top><td"+clr+">codes</td><td>");
      Map mp = c.getCodes();
      if(mp != null)
        for(Object o: mp.keySet())
          buff.append(o+" = "+mp.get(o)+", ");
      buff.append("</td></tr>");
      buff.append("</table>");
View Full Code Here

        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){
View Full Code Here

    nf.setMaximumFractionDigits(3);
    BufferedWriter writer = getCSVWriter(outputFile);
   
    // go over all of the mentions
    for(Mention m: doc.getMentions()){
      Concept c = m.getConcept();
      String s = Arrays.toString(c.getSemanticTypes());
      StringBuffer a = new StringBuffer();
      for(Annotation an : m.getAnnotations()){
        a.append(an.getText()+"/"+(+an.getOffset())+", ");
      }
      if(a.length()> 0){
        a = new StringBuffer(a.substring(0,a.length()-2));
      }
      writer.write(doc.getTitle()+S+m.getText()+S+c.getCode()+S+c.getName()+S+s.substring(1,s.length()-1)+S+m.getModality()+S+a+"\n");
    }
    writer.flush();
  }
View Full Code Here

      String expanded = m.group(1);
      String acronym  = m.group(m.groupCount());
      expanded = getAcronymExapndedForm(expanded,acronym);
      // don't match to single words acronyms and don't match digits
      if(expanded != null && acronym.length() > 1 && !acronym.matches("\\d+")){
        Concept exp = null;
        List<Concept> acr = new ArrayList<Concept>();
        // find annotations assigned to expanded part of the acronym
        for(Concept c: r){
          if(matches(c,expanded))
            exp = c;
          else if(matches(c,acronym))
            acr.add(c);
        }
        // if expanded form was matched as a single concept
        if(exp != null){
          // fix annotations
          exp.addMatchedTerm(acronym);
          exp.setAnnotations(null);
          exp.setText(null);
          // save acronym with expanded form code
          getAcronyms().put(acronym,exp.getCode());
          // if there was a different acronym selected, then remove them
          for(Concept a: acr){
            if(!a.getCode().equals(exp.getCode()))
              concepts.remove(a);
          }
        }
      }
    }else{
      // check if acronyms exist
      for(String acronym: getAcronyms().keySet()){
        m = Pattern.compile("\\b"+acronym+"\\b").matcher(phrase);
        while(m.find()){
          // remove an already matched one
          for(Concept c: concepts){
            if(c.getMatchedTerm().equals(acronym)){
              concepts.remove(c);
              break;
            }
          }
         
          // add new concept for this acronym
          Concept c = new Concept(getAcronyms().get(acronym),acronym);
          c.setTerminology(terminology);
          c.setSearchString(phrase);
          c.setMatchedTerm(acronym);
          concepts.add(c);
        }
      }
    }
    return concepts.toArray(new Concept [0]);
View Full Code Here

        // until other negation or stop word (retroactively)
        else if(token.isPostNegation() || token.isIndeterminate()){
          for(int j=0;j<negatableConcepts.size();j++){
            SentenceElement cns = negatableConcepts.get(j);
            if(cns.isConcept()){
              Concept lex = cns.getConcept();
              if(token.isPostNegation()){
                negatedConcepts.add(lex);
                Concept c = new Concept("ABSENT","Absent");
                //c.setText(token.getText());
                //c.setOffset(token.getOffset());
                Annotation.addAnnotation(c,token.getText(),token.getOffset());
                negations.add(c);
              }else{
                indeterminateConcepts.add(lex);
                Concept c = new Concept("INDETERMINATE","Indeterminate");
                //c.setText(token.getText());
                //c.setOffset(token.getOffset());
                Annotation.addAnnotation(c,token.getText(),token.getOffset());
                indeterminates.add(c);
              }
            }
          }
        }
       
        // clear retro concepts
        negatableConcepts.clear();
       
      // if token is stop word then stop the negation process
      }else if (token.isStopWord()){
        negationConcept = null;
        negatableConcepts.clear();
        window = 0;
      // do the actual negation here
      }else if (token.isConcept()){
        if(negationConcept != null){
          Concept lex = token.getConcept();
          negatedConcepts.add(lex);
          Concept c = new Concept("ABSENT","Absent");
          //c.setText(negationConcept.getText());
          //c.setOffset(negationConcept.getOffset());
          Annotation.addAnnotation(c,negationConcept.getText(),negationConcept.getOffset());
          negations.add(c);
        }else{
View Full Code Here

      // check if it is a recognized concept
      Object key = findConceptMatch(tmp,conceptKeys);
      //System.err.println(tmp+" "+conceptKeys+" "+key);
      if(key != null){
        String ctext = null;
        Concept concept = null;
        Mention mention = null;
       
        if(key instanceof Concept){
          concept = (Concept) key;
          ctext = concept.getText();
        }else if(key instanceof  Mention){
          mention = (Mention)key;
          concept = mention.getConcept();
          ctext = mention.getText();
        }
View Full Code Here

    String lid = ""+l.getOffset();
    String word = l.getText();
    List<String> codes = new ArrayList<String>();
    StringBuffer tip = new StringBuffer();
    for(Mention m: mentions){
      Concept c = m.getConcept();
      String p = (m.isNegated())?"N":(m.isUncertain()?"U":"");
      codes.add("'"+p+m.getConcept().getCode()+"'");
      tip.append(c.getName()+" ("+c.getCode()+") "+Arrays.toString(c.getSemanticTypes())+"\n");
    }
    return "<label id=\""+lid+"\" style=\"color:green;\" onmouseover=\"h("+codes+");\" onmouseout=\"u("+codes+
        ");\" title=\""+TextTools.escapeHTML(tip.toString())+"\">"+word+"</label>";
  }
View Full Code Here

          ex.printStackTrace();
          //NOOP, just do default
        }
      }
    }
    return new Concept(cls);
  }
View Full Code Here

  public List<ItemInstance> process(TemplateDocument doc) throws TerminologyException{
    List<ItemInstance> items = new ArrayList<ItemInstance>();
    PathHelper paths = getPathHelper();
    // first pass
    for(Mention m: doc.getMentions()){
      Concept c = m.getConcept();
      if(paths.hasAncestor(c,getConcept())){
        ItemInstance item =  new ItemInstance(this,m);
        item.process(doc);
        if(item.isSatisfied()){
          addInstance(paths, items, item);
        }
      }else if(concept.getCodes() != null && !concept.getCodes().isEmpty() && c.getSources().length > 0){
        // what if there is a linkage code
        String code = concept.getCode(c.getSources()[0]);
        if(code != null){
          Concept cc = (code.equals(c.getSources()[0].getName()))?c.getTerminology().getRootConcepts()[0]:c.getTerminology().lookupConcept(code);
          if(cc != null){
            if(paths.hasAncestor(c,cc)){
              ItemInstance item = new ItemInstance(this,m);
              item.process(doc);
              if(item.isSatisfied())
                addInstance(paths, items, item);
            }
          }
        }
      }
    }
   
    // second pass, if nothing was found and there is a more general feature available
    if(items.isEmpty() && feature != null){
      for(Mention m: doc.getMentions()){
        Concept c = m.getConcept();
        if(paths.hasAncestor(c,getFeature().getConcept())){
          // process this template with feature concept
          ItemInstance item = new ItemInstance(this,m);
          item.process(doc);
         
View Full Code Here

TOP

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

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.