Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

65
LINES

< > BotCompany Repo | #1005080 // Good Answers Bot [dev.]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (5294L/35K/119K).

!752

/*
First version (simple).
User types a question.
Bot presents an answer.
User says "good", "bad" or "funny", or suggests an answer.
*/

concepts.

concept Weighted {
  S question, answer;
  bool good;
  S comment; // e. g. "good", "bad", "funny"
}

p-substance {
  centerBigConsole();
  loadAndAutoSaveConcepts();
  makeBot();
}

synchronized static S answer(final S question) {
  final S answer = or2((S) nullCall(func { makeAnswer(question) }), "I don't know");
  awt {
    showControls(vgrid(
      jcenteredBoldLabel(answer),
      jcenteredline(
        jbutton("Good", r { feedback(question, answer, true, "good") }),
        jbutton("Bad", r { feedback(question, answer, false, "bad") }),
        jbutton("Funny", r { feedback(question, answer, true, "funny") }),
        jbutton("Answer...", r { suggestForm(question) }))));
  }
  ret answer;
}

svoid feedback(S question, S answer, bool good, S comment) {
  cnew(Weighted.class, "question", question, "answer", answer, "good", good, "comment", comment);
  hideControls();
}

svoid suggestForm(final S question) {
  final new JTextField tf;
  final JComboBox cbComment = jcombobox("good", "bad", "funny");
  Runnable r = r {
    suggestAnswer(question, tf.getText().trim(), getTextFromComboBox(cbComment));
    hideControls();
  };
  onEnter(tf, r);
  showControls(vgrid(
    jlabel("Question: " + question),
    centerAndEast(withLabel("Answer:", tf),
      centerAndEast(cbComment, jbutton("Suggest", r)))));
}

static S makeAnswer(S question) {
  L<Weighted> l = findConceptsWhere(Weighted.class, "question", question, "good", true);
  if (nempty(l)) ret last(l).answer;
  null;
}

static void suggestAnswer(S question, S answer, S comment) {
  cnew(Weighted.class, "question", question, "answer", answer, "good", true, "comment", comment);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005080
Snippet name: Good Answers Bot [dev.]
Eternal ID of this version: #1005080/1
Text MD5: a001f1d41aff27ba6bd4e455c475b9d5
Transpilation MD5: 3deabec167618067a73596e1bb8329ef
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-10 22:03:40
Source code size: 1874 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 459 / 513
Referenced in: [show references]