コード例 #1
0
ファイル: DiagnosisState.java プロジェクト: brij-lab/vaidya
  @Override
  public void onEntry() {
    System.out.println("+++++++++++++++++ Diagnosis state entered +++++++++++++++++++++");
    app.speakOut("I have initial symptoms to start diagnosis.");

    // Set appropriate grammar
    current_grammar = app.BINARY_RESPONSE;
    entered = true;
    next_state = "diagnosis";
    // expect_binary = false;
    Integer[] final_symp_vec = new Integer[((HealthDomain) domain).SYMPTOM_VEC_DIM];
    Arrays.fill(final_symp_vec, 1);
    Map<String, Boolean> ack_symptoms = ((HealthDomain) domain).getSymptoms();
    for (Map.Entry<String, Boolean> e : ack_symptoms.entrySet()) {
      Integer[] symp_vector =
          ((HealthDomain) domain).SYMPTOM_VECTOR.get(e.getKey().replaceAll(" ", "_"));
      System.out.println("Vector for =========> " + e.getKey());
      printIntArray(symp_vector);
      System.out.println("Final vector : before =========> ");
      printIntArray(final_symp_vec);
      final_symp_vec = intersect(final_symp_vec, symp_vector);
      System.out.println("Final vector : after =========> ");
      printIntArray(final_symp_vec);
    }
    possible_diseases = new HashSet<>();
    for (Integer idx : getOneIndices(final_symp_vec)) {
      possible_diseases.add(((HealthDomain) domain).DISEASE_IDX.get(idx));
    }
    app.speakOut(
        "There are " + possible_diseases.size() + " diseases found matching your symptoms");
    // Speak out if there are less than 5 diseases
    if (possible_diseases.size() < 5) {
      for (String dis : possible_diseases) {
        app.speakOut(dis.replaceAll("_", " "));
      }
    }
    // If there are more than one possible disease then ask for more symptoms to resolve
    if (possible_diseases.size() > 1) {
      for (String dis : possible_diseases) {
        System.out.println(dis.replaceAll("_", " "));
      }
      getPossibleSymptoms();
    }
    if (possible_diseases.size() == 0) {
      conclude = true;
      next_state = "greet";
      current_grammar = app.GREET_RESPONSE;
    }
  }
コード例 #2
0
ファイル: DiagnosisState.java プロジェクト: brij-lab/vaidya
 @Override
 public void onRecognize(String hyp) {
   sym_Expain_Flag = false;
   if (expect_binary) {
     System.out.println("Resolving symtom =========> " + symptom_toask);
     if (nlu.resolveSymptomQueryHyp(hyp).equalsIgnoreCase("yes")) {
       possible_diseases = possible_symptoms.get(symptom_toask);
       System.out.println("Remaining diseases ============>>>>");
       for (String rdis : possible_diseases) {
         System.out.println(rdis);
       }
     } else if (nlu.resolveSymptomQueryHyp(hyp).equalsIgnoreCase("no")) {
       possible_diseases.removeAll(possible_symptoms.get(symptom_toask));
       System.out.println("Remaining diseases ============>>>>");
       for (String rdis : possible_diseases) {
         System.out.println(rdis);
       }
     } else {
       ((HealthDomain) domain).symptom_explain = symptom_toask;
       conclude = true;
       sym_Expain_Flag = true;
     }
     already_asked_symptoms.add(symptom_toask);
   }
   if (!sym_Expain_Flag) {
     app.sendChatMessage(true, "Disease count = " + possible_diseases.size(), null);
     if (possible_diseases.size() > 1) {
       getPossibleSymptoms();
     } else {
       for (String d : possible_diseases) {
         d = d.replaceAll("_", " ");
         app.speakOut("your most probable diagnosis is " + d);
         app.appendColoredText(app.result_text, "Diagnosis = " + d, Color.WHITE);
         ((HealthDomain) domain).setDisease(d);
         conclude = true;
         break;
       }
     }
   }
 }
コード例 #3
0
ファイル: DiagnosisState.java プロジェクト: brij-lab/vaidya
  private void getPossibleSymptoms() {
    Integer[] dis_vec;
    String poss_sym;
    possible_symptoms = new HashMap<>();
    Set<String> dis_list;
    for (String dis : possible_diseases) {
      dis_vec = ((HealthDomain) domain).DISEASE_VECTOR.get(dis);
      System.out.println("Vector for disease====================>" + dis);
      printIntArray(dis_vec);
      for (Integer idx : getOneIndices(dis_vec)) {
        poss_sym = ((HealthDomain) domain).SYMPTOM_IDX.get(idx);
        System.out.println("Poss Sym===================>" + poss_sym);
        if (poss_sym != null) {
          dis_list = possible_symptoms.get(poss_sym);
          if (dis_list == null) {
            dis_list = new HashSet<>();
            possible_symptoms.put(poss_sym, dis_list);
          }
          dis_list.add(dis);
        }
      }
    }

    int Dc = possible_diseases.size() / 2;
    symptom_toask = null;
    int min_dif = 9999;
    for (Map.Entry<String, Set<String>> e : possible_symptoms.entrySet()) {
      if (!already_asked_symptoms.contains(e.getKey())) {
        System.out.println(
            "Symptom ==> " + e.getKey() + "  ; disease count ==>" + e.getValue().size());
        for (String cdis : e.getValue()) {
          System.out.println(cdis);
        }

        if (Math.abs(Dc - e.getValue().size()) < min_dif) {
          symptom_toask = e.getKey();
          min_dif = Math.abs(Dc - e.getValue().size());
        }
      }
    }
    app.speakOut("Do you have " + symptom_toask.replaceAll("_", " "));
    current_grammar = app.SYMPTOM_QUERY_RESPONSE;
    expect_binary = true;
  }