Exemplo n.º 1
1
  public static void main(String[] args) {
    TestUser user = null;
    try {
      user = new TestUser(2899, 5213);
      user.getLogger().setEnabled(false);

      DrugDescriptionMatcher matcher = new DrugDescriptionMatcher(user);

      ArrayList descriptions = getTestDescriptions(user);
      Iterator iter = descriptions.iterator();
      while (iter.hasNext()) {
        String desc = (String) iter.next();

        // ArrayList drugs = matcher.match("Amoxicillin 250 mg cap",1);
        ArrayList drugs = matcher.match(desc);

        if (Lists.isEmpty(drugs)) {
          System.out.println(desc + ":\n--> No drugs found.");
        } else {
          System.out.println(desc + ":\n--> Found " + drugs.size() + " drugs:");

          Iterator drugIter = drugs.iterator();
          while (drugIter.hasNext()) {
            Drug drug = (Drug) drugIter.next();
            System.out.println(
                "--> ID " + drug.getID() + ": " + drug.getName() + " " + drug.getFormula());
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      user.finish();
    }
  }
Exemplo n.º 2
0
  private int matches(Drug drug, String field, String text) {
    String val = drug.getString(field);
    // Debug.println("matching drug " + field
    // + " '" + val + "' against '" + text + "'");

    if (Str.isEmpty(val)) {
      // Debug.println("returning 0");
      return 0;
    }

    val = Str.removeNonAlphanumeric(val);
    text = Str.removeNonAlphanumeric(text).toLowerCase();

    ArrayList aliases = getAliases(val);
    Iterator iter = aliases.iterator();
    while (iter.hasNext()) {
      String alias = (String) iter.next();

      if (Str.isNumber(alias)) {
        if (containsDiscrete(text, alias)) return 1;
      } else {
        int pos = Str.indexOfIgnoreCase(text, alias);
        if (pos != -1) {
          // Debug.println("returning 1");
          return 1;
        }
      }
    }

    // match failed.
    if (field.equals(ROUTE)) {
      // Debug.println("route mismatch, returning 0");
      return 0;
    }

    // Debug.println("returning -100");
    return -100;
  }