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

115
LINES

< > BotCompany Repo | #1014703 // VisualKatze 4 [Association Machine, Forward+Backward, ignoring stuff, OK, run with #1013936]

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

Download Jar. Uses 4487K of libraries. Click here for Pure Java version (14503L/113K).

1  
!7
2  
3  
static JLabel l;
4  
static Map<S> consequentsMap = synchroCIMap(), precedentsMap = synchroCIMap();
5  
static Set<S> ignoreSet = asCISet(splitAtVerticalBar("english|englisch|german|deutsch|foreground|fairground|background|Vordergrund|Hintergrund"));
6  
sS answer;
7  
static L<VF1<S>> receivers;
8  
static JTextField tfInput, tfSay, tfNote;
9  
static JButton btnSay;
10  
static TailFile logTail;
11  
12  
p-noconsole-autoupdate {
13  
  startBotInSeparateVM("Katze.", #1013936);
14  
  hideVMRunningBot("Katze.");
15  
  
16  
  final JFrame frame = frameIcon(#1101166, showMaximizedFrame(jscroll_verticalExtend_trackWidth(
17  
    //jTiledBackground(#1007195, setForeground(Color.white,
18  
    jCenteredBackgroundImage(#1101166, setBackground(awtColor("e4e4e4"), setForeground(Color.black,
19  
    setFontSize(60, l = jcenteredlabel_noToolTip())))))));
20  
  addToWindowWithMargin(frame, jcenteredline(btnSay = jbutton("Say", f sayIt)));
21  
  
22  
  // bottom to top
23  
  addToWindowNorth(frame, withMargin(10, 1, withLabel("Add a note:", tfNote = jcenteredtextfield())));
24  
  addToWindowNorth(frame, withMargin(10, 1, withLabel("Make me say something:", tfSay = jcenteredtextfield())));
25  
  addToWindowNorth(frame, withMargin(10, 1, withLabel("Type here instead of speaking:", tfInput = jcenteredtextfield())));
26  
  
27  
  onEnter(tfInput, r-thread { send("Chrome Speech.", "User typed *", getTextTrim(tfInput)) });
28  
  onEnter(tfSay, r-thread { speakInRecognizerLanguage(getTextTrim(tfSay)) });
29  
  onEnter(tfNote, r {
30  
    mechAppendQueue().add(r {
31  
      appendToMechList_noUniq("Today's Notes", "[" + localDateWithMilliseconds() + "] " + getTextTrim(tfNote)) })
32  
  });
33  
  focusOnFrameActivationAndNow(frame, btnSay);
34  
    
35  
  receivers = ll(
36  
    consequentsMap_receiver(consequentsMap), precedentsMap_receiver(precedentsMap));
37  
  time "Loading" { loading {
38  
    mapVoidMulti(receivers, notNulls(map prepLine(dropLast(linesOfFile(speechRecognitionLog())))));
39  
  } }
40  
  
41  
  logTail = tailFileLinewisePlusLastLine(speechRecognitionLog(), 100, vf1(f onUtteranceFromLog));
42  
  //makeAndCall_warmUp("mL_anInstanceOfA");
43  
}
44  
45  
sS prepLine(S s) {
46  
  s = unquoteAndDropAngleBracketStuff(s);
47  
  
48  
  // don't react on older messages
49  
  if (logTail != null && logTail.started())
50  
    printIndentUnlessEmpty(">> ", pcallAnswerMethod(s));
51  
    
52  
  ret nullIfInSet(ignoreSet, s);
53  
}
54  
55  
svoid onUtteranceFromLog(S utterance) {
56  
  if (empty(utterance = prepLine(trimLastLine(utterance)))) ret;
57  
  print(">>  " + utterance);
58  
  onUtterance(utterance);
59  
}
60  
61  
svoid onUtterance(S utterance) {
62  
  mapVoidMulti(receivers, ll(utterance));
63  
  answer = guessAnswer(utterance);
64  
  S both = utterance;
65  
  setTextAndEnabled(btnSay, empty(answer) ? pair("Say", false) : pair("Say " + quote(answer), true));
66  
  if (nempty(answer)) {
67  
    both += "\n\n" + answer;
68  
    logQuotedWithTime("guessLog", both);
69  
  }
70  
  
71  
  setFrameTitle(l, both.replaceAll("\n+", " > ");
72  
  setText(l, jlabel_textAsHTML_center(both));
73  
}
74  
75  
answer {
76  
  s = lookupOrKeep(mechMapCI("Mishearing corrections"), s);
77  
  
78  
  if "higher"
79  
    infoBox("Get higher?");
80  
  if "font size *"
81  
    ret "OK" with revalidate(setFontSize(parseInt($1), l));
82  
  if "foreground|fairground|vordergrund"
83  
    ret "OK" with activateFrame(l);
84  
  if "background|hintergrund"
85  
    ret "OK" with minimizeFrame(l);
86  
  if "standard function|standard functions|steroid function|standard fashion" // Google keeps misunderstanding
87  
    ret "OK" with sfBot_doIt();
88  
  if "move mouse away"
89  
    ret "OK" with moveMouseToTopRightCorner();
90  
  if "mouse to center|mouse to centre|most two centre"
91  
    ret "OK" with moveMouseToScreenCenter();
92  
}
93  
94  
svoid sayIt {
95  
  fS a = answer;
96  
  if (empty(a)) ret;
97  
  print("Saying: " + a);
98  
  thread { speakInRecognizerLanguage(a); }
99  
  onUtterance(a);
100  
}
101  
102  
sS guessAnswer(S s) {
103  
  new Matches m;
104  
  if (find3plusRestsOneOf(s, m, "Ich heiße", "Ich bin", "Mein Name ist", "Man nennt mich", "Ich werde * genannt", "nennen mich", "nennt mich", "nenne mich"))
105  
    if (eqic($2, "Stefan"))
106  
      ret gudrun_later("Stefan ist ein Programmierer");
107  
    else
108  
      ret gudrun_later("Hallo " + $2);
109  
110  
  try answer mL_answerWithCodeFragments("Witty Answers", s);
111  
  try answer mL_answerWithCodeFragments(s);
112  
  try answer consequentsMap.get(s);
113  
  try answer precedentsMap.get(s);
114  
  null;
115  
}

Author comment

Began life as a copy of #1014135

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014703
Snippet name: VisualKatze 4 [Association Machine, Forward+Backward, ignoring stuff, OK, run with #1013936]
Eternal ID of this version: #1014703/1
Text MD5: 5626d28c717b37889880315518e5af23
Transpilation MD5: ea7a62d2bf39797fba3dabc22ba13d2d
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-30 17:40:52
Source code size: 4284 bytes / 115 lines
Pitched / IR pitched: No / No
Views / Downloads: 401 / 912
Referenced in: [show references]