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).

1  
!752
2  
3  
/*
4  
First version (simple).
5  
User types a question.
6  
Bot presents an answer.
7  
User says "good", "bad" or "funny", or suggests an answer.
8  
*/
9  
10  
concepts.
11  
12  
concept Weighted {
13  
  S question, answer;
14  
  bool good;
15  
  S comment; // e. g. "good", "bad", "funny"
16  
}
17  
18  
p-substance {
19  
  centerBigConsole();
20  
  loadAndAutoSaveConcepts();
21  
  makeBot();
22  
}
23  
24  
synchronized static S answer(final S question) {
25  
  final S answer = or2((S) nullCall(func { makeAnswer(question) }), "I don't know");
26  
  awt {
27  
    showControls(vgrid(
28  
      jcenteredBoldLabel(answer),
29  
      jcenteredline(
30  
        jbutton("Good", r { feedback(question, answer, true, "good") }),
31  
        jbutton("Bad", r { feedback(question, answer, false, "bad") }),
32  
        jbutton("Funny", r { feedback(question, answer, true, "funny") }),
33  
        jbutton("Answer...", r { suggestForm(question) }))));
34  
  }
35  
  ret answer;
36  
}
37  
38  
svoid feedback(S question, S answer, bool good, S comment) {
39  
  cnew(Weighted.class, "question", question, "answer", answer, "good", good, "comment", comment);
40  
  hideControls();
41  
}
42  
43  
svoid suggestForm(final S question) {
44  
  final new JTextField tf;
45  
  final JComboBox cbComment = jcombobox("good", "bad", "funny");
46  
  Runnable r = r {
47  
    suggestAnswer(question, tf.getText().trim(), getTextFromComboBox(cbComment));
48  
    hideControls();
49  
  };
50  
  onEnter(tf, r);
51  
  showControls(vgrid(
52  
    jlabel("Question: " + question),
53  
    centerAndEast(withLabel("Answer:", tf),
54  
      centerAndEast(cbComment, jbutton("Suggest", r)))));
55  
}
56  
57  
static S makeAnswer(S question) {
58  
  L<Weighted> l = findConceptsWhere(Weighted.class, "question", question, "good", true);
59  
  if (nempty(l)) ret last(l).answer;
60  
  null;
61  
}
62  
63  
static void suggestAnswer(S question, S answer, S comment) {
64  
  cnew(Weighted.class, "question", question, "answer", answer, "good", true, "comment", comment);
65  
}

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: 524 / 602
Referenced in: [show references]