Package edu.pitt.terminology.lexicon

Examples of edu.pitt.terminology.lexicon.Concept$Content


    infoMap.put("name",name);
    infoMap.put("location",file.getAbsolutePath());
    infoMap.put("stem.words",""+stemWords);
   
    BufferedReader reader = new BufferedReader(new FileReader(file));
    Concept c = new Concept("_");
    List<String> synonyms = new ArrayList<String>();
    int code = 0;
    for(String line=reader.readLine();line != null; line=reader.readLine()){
      line = line.trim();
     
      // junk is a concept delimeter
      if(line.length() == 0 || line.matches("_+") || line.matches("\\d+")){
        // add previous concept
        if(c != null && synonyms != null && synonyms.size() > 0){
          c.setName(synonyms.get(0));
          c.setCode(""+(++code));
          c.setSynonyms(synonyms.toArray(new String [0]));
          addConcept(c);
        }
        // start new concept
        c = new Concept("_");
        synonyms = new ArrayList<String>();
      }else{
        synonyms.add(line);
      }
    }
    reader.close();
   
    // handle last concept
    if(c != null && synonyms != null && synonyms.size() > 0){
      c.setName(synonyms.get(0));
      c.setCode(""+(++code));
      c.setSynonyms(synonyms.toArray(new String [0]));
      addConcept(c);
    }
   
    // save terminology
    pcs.firePropertyChange(LOADING_MESSAGE,null,"Saving Concept Information ...");
View Full Code Here


           
      // create
      List<Concept> termConcepts = new ArrayList<Concept>();
      double score = getDefaultScore(term,oterm,resultTerms);
      for(String code: codes){
        Concept c = convertConcept(code);
        if(c != null){
          c.setInitialized(true);
        }else{
          c = new Concept(code,term);
        }
        // clone
        c = c.clone();
        c.setTerminology(this);
        c.setMatchedTerm(oterm);
        c.setSearchString(text);
       
        if(ignoreAcronyms && isAcronym(c))
          continue;
     
        scoreConcept(c,term,score);
       
        // filter out really bad ones
        if(!scoreConcepts || c.getScore() >= 0.5)
          termConcepts.add(c);
      }
      // add to results
      for(Concept c: getBestCandidates(termConcepts)){
        if(!isFilteredOut(c)){
          // if we have multipe annotations, deal with it better
          if(result.containsKey(c)){
            Concept oc = result.get(c);
            for(String ot: c.getMatchedTerms())
              oc.addMatchedTerm(ot);
            for(Annotation a: c.getAnnotations())
              oc.addAnnotation(a);
          }else
            result.put(c,c);
        }
      }
    }
View Full Code Here

          return concepts;
        else
          return Collections.EMPTY_LIST;
      }
      // now find best
      Concept best = null;
      for(Concept c: concepts){
        if(best == null || best.getScore() < c.getScore())
          best = c;
      }
      return Collections.singletonList(best);
    }
    return concepts;
View Full Code Here

       
        String cls_str = regexMap.get(re);
        String txt = m.group(1);    // THIS BETTER BE THERE,
        //System.out.println(cls_str+" "+txt+" for re: "+re); 
        // create concept from class
        Concept c = convertConcept(conceptMap.get(cls_str));
        c = c.clone();
        c.setSearchString(term);
        Annotation.addAnnotation(c, txt,m.start());
       
        // check if results already have similar entry
        // if new entry is better replace the old one
        for(ListIterator<Concept> it = result.listIterator();it.hasNext();){
          Concept b = it.next();
         
          // get offsets of concepts
          int st = c.getOffset();
          int en = c.getOffset()+c.getText().length();
         
          int stb = b.getOffset();
          int enb = b.getOffset()+b.getText().length();
         
          // if concept b (previous concept) is within concept c (new concept)
          if(st <=  stb && enb <= en)
            it.remove();
         
View Full Code Here

   * @return
   */
  public Concept[] getRootConcepts() throws TerminologyException {
    List<Concept> roots = new ArrayList<Concept>();
    for(String code: rootMap.keySet()){
      Concept c = lookupConcept(code);
      if(c != null)
        roots.add(c);
    }
    return roots.toArray(new Concept [0]);
  }
View Full Code Here

      if(relationMap != null){
        Map<Relation,Concept []> map = new HashMap<Relation,Concept []>();
        for(String key: relationMap.keySet()){
          List<Concept> list = new ArrayList<Concept>();
          for(String cui: relationMap.get(key)){
            Concept con = lookupConcept(cui);
            if(con != null)
              list.add(con);
          }
          map.put(Relation.getRelation(key),list.toArray(new Concept [0]));
        }
View Full Code Here

  protected Concept convertConcept(Object obj) {
    if(obj instanceof Concept)
      return (Concept) obj;
    if(obj instanceof Concept.Content){
      Concept.Content c = (Concept.Content)obj;
      return (c.concept == null)?new Concept(c):c.concept;
    }
    if(obj instanceof String || obj instanceof URI){
      try{
        return lookupConcept(""+obj);
      }catch(Exception ex){
View Full Code Here

    }
    return null;
  }
 
  public Concept lookupConcept(String cui) throws TerminologyException {
    Concept c =  convertConcept(conceptMap.get(cui));
    if(c != null){
      c.setTerminology(this);
      c.setInitialized(true);
    }
    return c;
  }
View Full Code Here

        }
      }else if("Description".equals(e.getTagName())){
        infoMap.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

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

TOP

Related Classes of edu.pitt.terminology.lexicon.Concept$Content

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.