1 | !include #1007689 // Web v2 |
2 | |
3 | static int saveInterval = 60000; |
4 | sbool clearWeb = true; // clear every time? |
5 | static volatile new Web web; |
6 | static L<Lisp> facts; |
7 | static L<S> vars; |
8 | static long lastSave, sizeSaved; |
9 | |
10 | extend Web { |
11 | volatile transient bool cancelled, calculating; |
12 | } |
13 | |
14 | svoid pConsoleThoughtMachine { |
15 | tt(); |
16 | setConsoleTitle(programTitle()); |
17 | load("web"); lastSave = sysNow(); |
18 | setFrameHeight(consoleFrame(), 400); |
19 | centerConsole(); |
20 | //magellan(); |
21 | //graphite(); |
22 | //mistAqua(); |
23 | //moderateTheme(); |
24 | sahara(); |
25 | swing { |
26 | if (!englishToConceptLanguage_xyz_debug) clearConsole(); |
27 | consoleAddAskButton(); |
28 | focusConsole(); |
29 | final JLabel lblBrainSize = jRightAlignedLabel(); |
30 | addToConsole2(withMargin(centerAndEast(lblBrainSize, |
31 | withLeftMargin(jbutton("Reset", "reset"))))); |
32 | awtEvery(lblBrainSize, 1000, r { |
33 | lblBrainSize.setText("Brain Size: " + toM(fileSize(programFile("web.structure")), 1) + " MB"); |
34 | }); |
35 | awtCalcEvery(lblBrainSize, 1000, 1000, r { |
36 | if (web.calculating) ret; |
37 | int webSize = web.count(); |
38 | if (shouldSave(webSize, false)) saveWeb(webSize); |
39 | }); |
40 | } |
41 | |
42 | aiEnhancements(); |
43 | aiConcepts_noAutoClear(); |
44 | useConceptsDump(concepts); |
45 | set englishToConceptLanguage_useBrackets; |
46 | vars = ll(); |
47 | facts = clParse(linesToCLWithVars(theFacts, vars)); |
48 | print(theFacts); |
49 | useFacts_cl(clUnparse(facts)); |
50 | //printNumberedLines(facts); |
51 | |
52 | firstRiddle(); |
53 | |
54 | makeBotQuietly(); |
55 | //print("Type more questions if you like.\n"); |
56 | notDoneQuietly(); |
57 | } |
58 | |
59 | svoid firstRiddle { |
60 | print(); |
61 | for (S rid : toLinesFullTrim(theRiddle)) { |
62 | print("? " + rid); |
63 | print(" " + answer(rid)); |
64 | } |
65 | print(); |
66 | } |
67 | |
68 | static int webSize() { ret web.count(); } |
69 | |
70 | sbool shouldSave(int webSize, bool checkInterval) { |
71 | ret webSize != sizeSaved && |
72 | (!checkInterval || sysNow() >= lastSave+saveInterval); |
73 | } |
74 | |
75 | svoid saveWeb(int webSize) { |
76 | save("web"); |
77 | sizeSaved = webSize; |
78 | lastSave = sysNow(); |
79 | } |
80 | |
81 | static S answer(S rid) { |
82 | web.calculating = true; |
83 | try { |
84 | ret answerImpl(rid); |
85 | } finally { |
86 | web.calculating = false; |
87 | } |
88 | } |
89 | |
90 | static S answerImpl(S rid) { |
91 | if (match("facts", rid)) { printNumberedLines(facts); ret "OK"; } |
92 | if (match("web", rid)) { print(web); ret "OK"; } |
93 | if (match("visualize", rid)) { webToCAL(web).show(); ret "OK"; } |
94 | Web web = main.web; |
95 | rid = addPrefix("Q: ", rid); |
96 | Lisp riddle = clParse(englishToConceptLanguage(rid)); |
97 | //print("# " + riddle); |
98 | |
99 | // Create web |
100 | if (clearWeb) web = new Web; |
101 | createWeb(web, riddle); |
102 | web.relations(facts); |
103 | |
104 | int webSize = web.count(); |
105 | int cursor = 0; |
106 | while licensed { |
107 | if (web.cancelled) ret "cancelled"; |
108 | //print("Web size: " + webSize); |
109 | if (shouldSave(webSize, true)) { |
110 | printWithoutNL("S"); |
111 | saveWeb(webSize); |
112 | } else |
113 | printWithoutNL("."); |
114 | if ((++cursor % 60) == 0) print(); |
115 | |
116 | CriticalAction action = beginCriticalAction("Web Update"); |
117 | try { |
118 | calc(web, riddle); |
119 | } finally { |
120 | action.done(); |
121 | } |
122 | |
123 | int n = web.count(); |
124 | if (n == webSize) break; |
125 | webSize = n; |
126 | } |
127 | print(); |
128 | |
129 | // print question again |
130 | if (cursor / 60 >= 10) |
131 | print("? " + rid); |
132 | |
133 | // Answer question |
134 | S s = getAnswer(web); |
135 | s = or2(s, "I don't know"); |
136 | ret s; |
137 | } |
138 | |
139 | svoid cleanMeUp { |
140 | while (criticalActionsInFlight()) sleep(5); |
141 | if (sizeSaved != web.count()) |
142 | save("web"); |
143 | } |
144 | |
145 | svoid reset { |
146 | if (!confirmOKCancel("Really clear the brain?")) ret; |
147 | web.cancelled = true; |
148 | CriticalAction action = beginCriticalAction("Resetting Brain"); |
149 | try { |
150 | web = new Web; |
151 | sizeSaved = 0; |
152 | save("web"); |
153 | } finally { |
154 | action.done(); |
155 | } |
156 | clearConsole(); |
157 | firstRiddle(); |
158 | } |
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: | #1007815 |
Snippet name: | Console Thought Machine [Include] |
Eternal ID of this version: | #1007815/22 |
Text MD5: | 7f16bf5e608ceda3a3a247ee19bbfc76 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-04-13 17:27:27 |
Source code size: | 3816 bytes / 158 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 540 / 1137 |
Version history: | 21 change(s) |
Referenced in: | [show references] |