예제 #1
0
  /**
   * This method adds a new Mention and associated concepts to a SofaText, there can be overlap
   * between concept names and multiple concepts can match a string, instead of choosing one
   * concept, we record them all.
   *
   * @param m
   * @param concepts
   */
  public void addMentionAndConcepts(Mention m, List<Concept> concepts) {
    // System.out.println("Mention Text: " + m.getText());
    ArrayList<SofaTextMention> toRemove = new ArrayList<SofaTextMention>();

    // check all SofaTextMentions
    for (SofaTextMention stm : sofaTextMention) {

      // if new mention is subsumed by existing mention, add associated concepts to subsuming
      // mention
      // and then return

      // test for overlap
      if (isOverlapping(stm, m)) { // there is overlap, keep the larger of the two mentions

        if (stm.getMentionEnd() - stm.getMentionStart()
            < m.getEnd() - m.getStart()) // mention is larger
        {
          System.out.println("1");
          concepts.addAll(stm.getConcepts());
          toRemove.add(stm);
        } else {
          System.out.println("2");
          stm.addConcepts(concepts);
          return;
        }
      }
    }
    // remove mentions from remove list
    sofaTextMention.removeAll(toRemove);
    // add new mention to sofatext
    sofaTextMention.add(new SofaTextMention(this, m, concepts));
  }
예제 #2
0
 private boolean isOverlapping(SofaTextMention stm, Mention m) {
   if (stm.getMentionStart() == m.getStart() // same start token
       || stm.getMentionEnd() == m.getEnd() // same end token
       || (stm.getMentionStart() <= m.getStart() && stm.getMentionEnd() >= m.getStart())
       || (stm.getMentionStart() >= m.getStart() && stm.getMentionStart() <= m.getEnd())) {
     return true;
   }
   return false;
 }
예제 #3
0
  /**
   * returns all SofaTextMention objects with type "treatment" in this SofaText object
   *
   * @return
   */
  public Collection<? extends SofaTextMention> getTreatments() {
    List<SofaTextMention> treatments = new ArrayList<SofaTextMention>();

    for (SofaTextMention stm : sofaTextMention) {
      if (stm.getMentionType().equals("treatment")) treatments.add(stm);
    }

    return treatments;
  }
예제 #4
0
  /**
   * returns all SofaTextMention objects with type "problem" in this SofaText object
   *
   * @return
   */
  public Collection<? extends SofaTextMention> getProblems() {
    List<SofaTextMention> problems = new ArrayList<SofaTextMention>();

    for (SofaTextMention stm : sofaTextMention) {
      if (stm.getMentionType().equals("problem")) problems.add(stm);
    }

    return problems;
  }
예제 #5
0
  /**
   * Helper method to generate HTML, will be moved to controller in future, the html contains the
   * text of the SofaText object with each mention wrapped in a span tag
   *
   * @return
   */
  public String getAnnotatedHTML() {
    String html = new String(text);
    String tagged;
    for (SofaTextMention m : sofaTextMention) {
      tagged = wrapInMentionTypeTag(m.getMentionText(), m.getMentionType());
      // System.out.println(tagged);

      if (!m.getSofaTextMentionConcept().isEmpty()) tagged = wrapInConceptTag(tagged, m);

      html = html.replace(m.getMentionText(), tagged);
      // html = html.replaceAll("\\n", "<br/>");
    }
    return html;
  }
예제 #6
0
 private String wrapInConceptTag(String tagged, SofaTextMention m) {
   SofaTextMentionConcept c = (SofaTextMentionConcept) m.getSofaTextMentionConcept().toArray()[0];
   return String.format(
       "<a href=/openmrs/dictionary/concept.htm?conceptId=%d>%s</a>",
       c.getConcept().getConceptId(), tagged);
 }