!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 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); }