Download Jar. Uses 3874K of libraries. Click here for Pure Java version (14880L/108K).
1 | !7 |
2 | |
3 | static JTextField tf; |
4 | static SingleComponentPanel scp; |
5 | static Canvas canvas; |
6 | static Q q; // action queue |
7 | static volatile bool boss; // boss mode (after pressing Escape) |
8 | static L<AIConcept> aiConcepts; |
9 | |
10 | !include #1007377 // traits for CirclesAndLines |
11 | |
12 | p-subst {
|
13 | aiEnhancements(); |
14 | aiConcepts = loadAIConcepts(); |
15 | //final S word = getString(random(aiConcepts), /*"name"*/"globalID"); |
16 | final S word = "yorqibybrndchtxr"; |
17 | swing {
|
18 | q = new Q(true); |
19 | tf = setTextFieldFontSize(jCenteredTextField(word), 20); |
20 | final ForwardAndBackButtons fb = new ForwardAndBackButtons(tf, f go); |
21 | JFrame frame = showFrame(northAndCenter( |
22 | westAndCenter(fb.buttons(), withLeftMargin(tf)), |
23 | scp = new SingleComponentPanel)); |
24 | registerEscape(frame, r { boss = true; tf.setText(""); scp.noComponent(); });
|
25 | centerFrame(frameInnerSize(frame, 800, 600)); |
26 | addMenu(frame, "Menu!", |
27 | "Clear Cache", r { clearAICaches() });
|
28 | addAISuiteMenu(frame); |
29 | |
30 | onEnterAndNow(tf, r {
|
31 | fb.submitted(); |
32 | go(); |
33 | }); |
34 | hideConsole(); |
35 | } |
36 | } |
37 | |
38 | svoid go {
|
39 | boss = false; |
40 | awt { tf.selectAll(); }
|
41 | final S text = getTextTrim(tf); |
42 | q.add(r {
|
43 | if (boss) ret; |
44 | long time = sysNow(); |
45 | loading {
|
46 | final CirclesAndLines cal = render(text); |
47 | if (boss) ret; |
48 | awt {
|
49 | Canvas canvas = cal.makeCanvas(); |
50 | new CircleDoubleClicker(cal, canvas, voidfunc(Circle c) {
|
51 | S s = firstGlobalID(c.traits()); |
52 | if (empty(s)) s = first(c.traits()); |
53 | tf.setText(s); |
54 | simulateEnter(tf); |
55 | }); |
56 | |
57 | scp.setComponent(centerAndSouth( |
58 | /*jscroll_centered*/(canvas), |
59 | setFont(sansSerifBold(20), jcenteredlabel(text)))); |
60 | } |
61 | } |
62 | sleepUntilSys(time+1000); // min display time |
63 | }); |
64 | } |
65 | |
66 | static CirclesAndLines render(S text) {
|
67 | pcall { text = englishToConceptLanguage(text); }
|
68 | print("Text: " + text);
|
69 | |
70 | if (possibleGlobalID(text)) {
|
71 | AIConcept c = findWhere(aiConcepts, globalID := text); |
72 | if (c != null) {
|
73 | print("Have concept (" + c.globalID + " - " + c.name + ")");
|
74 | ret renderConcept(c); |
75 | } |
76 | } |
77 | |
78 | new CirclesAndLines cal; |
79 | for (S s : splitAtPlus(text)) cal.circle_autoVis(s, 0.5, 0.5); |
80 | autoPositionCircles(cal); |
81 | ret cal; |
82 | } |
83 | |
84 | static CirclesAndLines renderConcept(AIConcept c) {
|
85 | new CirclesAndLines cal; |
86 | conceptCircle(cal, c, true); |
87 | autoPositionCircles(cal); |
88 | ret cal; |
89 | } |
90 | |
91 | static Circle conceptCircle(CirclesAndLines cal, S conceptID, bool withRelations) {
|
92 | AIConcept c = aiConceptsMap_cached().get(conceptID); |
93 | if (c == null) ret cal.circle(conceptID + " [?]", 0.5, 0.5); |
94 | ret conceptCircle(cal, c, withRelations); |
95 | } |
96 | |
97 | static Circle conceptCircle(CirclesAndLines cal, AIConcept c, bool withRelations) {
|
98 | BufferedImage img = getConceptImage(c); |
99 | Circle cc; |
100 | print("conceptCircle " + c.globalID + " img: " + (img != null));
|
101 | if (img != null) |
102 | cc = cal.circle(img, 0.5, 0.5, c.name); |
103 | else |
104 | cc = cal.circle_autoVis(c.name, 0.5, 0.5); |
105 | cc.addTrait(c.globalID); |
106 | if (withRelations) |
107 | findRelations(cal, cc, c); |
108 | ret cc; |
109 | } |
110 | |
111 | svoid findRelations(CirclesAndLines cal, Circle cc, AIConcept c) {
|
112 | S id = c.globalID; |
113 | for (S s : trueStatements_cached()) {
|
114 | Lisp l = clParse(s); |
115 | if (l.size() == 2) {
|
116 | if (eq(l.getString(0), id)) {
|
117 | S label = makeLabel(l.head); |
118 | Circle dd = conceptCircle(cal, l.getString(1), false); |
119 | cal.arrow(cc, label, dd); |
120 | } |
121 | else if (eq(l.getString(1), id)) {
|
122 | S label = makeLabel(l.head); |
123 | Circle dd = conceptCircle(cal, l.getString(0), false); |
124 | cal.arrow(dd, label, cc); |
125 | } |
126 | } |
127 | } |
128 | } |
129 | |
130 | sS makeLabel(S id) {
|
131 | SS map = litmap( |
132 | "gqlkqsxygqmmptoi", "SHORT FOR", |
133 | "yppdjirdezcvlhhg", "SYNONYM"); |
134 | try answer map.get(id); |
135 | S name = conceptToName(id); |
136 | new Matches m; |
137 | if (l(name) > 1) name = dropSuffix(".", name);
|
138 | if (flexMatch("X * Y", name, m))
|
139 | ret toUpper($1); |
140 | ret toUpper(name); |
141 | //ret toUpper(id); |
142 | } |
Began life as a copy of #1007383
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, picgnzycjide, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1007463 |
| Snippet name: | Encyclopedia 0.3 |
| Eternal ID of this version: | #1007463/45 |
| Text MD5: | 2d66bff1d7ea863fb83eafcccbb5d7ff |
| Transpilation MD5: | ec6d5af727aae10a9460285cd1366cec |
| Author: | stefan |
| Category: | javax / a.i. / gui |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-09-19 22:38:44 |
| Source code size: | 4114 bytes / 142 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 911 / 2047 |
| Version history: | 44 change(s) |
| Referenced in: | [show references] |