Download Jar. Uses 3874K of libraries. Click here for Pure Java version (9202L/63K).
1 | !759 |
2 | |
3 | sS guessProgram = #1008669; //#1008653; |
4 | static SingleComponentPanel scp; |
5 | static int startIndex; |
6 | sO guessModule; |
7 | static ReliableSingleThread relearnThread = new(f relearn); |
8 | |
9 | concept Sentence { |
10 | S text; |
11 | S action; |
12 | } |
13 | |
14 | p-substance { |
15 | unswing { |
16 | useDBOf(#1008607); |
17 | db(); |
18 | indexConceptField(Sentence, "text"); |
19 | L<S> sentences = toLinesFullTrim(loadSnippet(#1008606)); |
20 | sentences = notStartingWith("\"", sentences); |
21 | time { makeUniqueConcepts(Sentence, "text", sentences); } |
22 | pcall { guessModule = runDependent(guessProgram); } |
23 | } |
24 | showFrame(centerAndSouth(scp = new SingleComponentPanel, |
25 | withTopMargin(20, jcenteredline( |
26 | jbutton("Prev", r { makePanel(max(startIndex-10, 0)) }), |
27 | jbutton("Next", f nextPage), |
28 | jbutton("Random", r { makePanel(random(countConcepts(Sentence))/10*10) }), |
29 | jbutton("All OK", r { clickButtons(findButtons(scp, "OK")); nextPage(); }), |
30 | jbutton("Re-learn", r { relearnThread.trigger() }))))); |
31 | setFrameWidth(scp, 1000); |
32 | centerFrame(scp); |
33 | makePanel(0); |
34 | } |
35 | |
36 | svoid makePanel(int startIndex) { |
37 | main.startIndex = startIndex; |
38 | JPanel panel = gridLayoutPanel_trackWidth_evenlySpacedCols(2); |
39 | panel.add(jlabel("Sentence")); |
40 | panel.add(jlabel("Action")); |
41 | for (final Sentence s : takeFirst(10, dropFirst(startIndex, list(Sentence)))) { |
42 | final JTextField tfText = jtextfield_caretLeft(s.text); |
43 | panel.add(tfText); |
44 | IntRange r = ai_parseSubjectAction(s.action); |
45 | if (r != null) |
46 | tfText.select(r.start, r.end); |
47 | |
48 | bool hasAction = nempty(s.action); |
49 | final JTextField tf = jtextfield(hasAction ? s.action : guessAction(s.text)); |
50 | final new Var<JButton> reviseBtn, okBtn; |
51 | okBtn.set(jbutton("OK", r { |
52 | cset(s, action := getTextTrim(tf)); |
53 | disableTextField(tf); |
54 | replaceComponent(okBtn!, reviseBtn!); |
55 | relearnThread.trigger(); |
56 | })); |
57 | reviseBtn.set(jbutton("Revise", r { |
58 | cset(s, action := null); |
59 | enableTextField(tf); |
60 | replaceComponent(reviseBtn!, okBtn!); |
61 | })); |
62 | if (hasAction) disableTextField(tf); |
63 | panel.add(centerAndEast(tf, hasAction ? reviseBtn! : okBtn!)); |
64 | |
65 | onCaret(tfText, r { |
66 | if (s.action == null) { |
67 | S a = ai_makeSubjectAction(s.text, new IntRange(tfText.getSelectionStart(), tfText.getSelectionEnd())); |
68 | if (a != null) tf.setText(a); |
69 | } |
70 | }); |
71 | } |
72 | scp.setComponent(jscroll(panel)); |
73 | } |
74 | |
75 | static IntRange guess(S sentence) { |
76 | if (guessModule == null) null; |
77 | ret (IntRange) quickImport(call(guessModule, "callGuesser", get(guessModule, "best"), sentence)); |
78 | } |
79 | |
80 | static S guessAction(S sentence) { |
81 | IntRange r = guess(sentence); |
82 | ret or2(ai_makeSubjectAction(sentence, r), "?"); |
83 | } |
84 | |
85 | static L<Pair<S, IntRange>> learningMaterial() { |
86 | L<Pair<S, IntRange>> out = new L; |
87 | for (Sentence s) { |
88 | if (s.action == null) continue; |
89 | IntRange r = ai_parseSubjectAction(s.action); |
90 | if (r != null) |
91 | out.add(pair(s.text, r)); |
92 | } |
93 | ret out; |
94 | } |
95 | |
96 | svoid relearn { |
97 | callMain(guessModule); |
98 | swing { makePanel(startIndex); } |
99 | } |
100 | |
101 | svoid nextPage { |
102 | if (startIndex+10 < countConcepts(Sentence)) makePanel(startIndex+10); |
103 | } |
Began life as a copy of #1008607
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008632 |
Snippet name: | Sentences to subject with guessing [OK] |
Eternal ID of this version: | #1008632/29 |
Text MD5: | 0df6a4a338d889071e0406090caf53b1 |
Transpilation MD5: | 5ae4f699e98890921ab7ef99c55bc45b |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-28 00:40:33 |
Source code size: | 3215 bytes / 103 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 698 / 1512 |
Version history: | 28 change(s) |
Referenced in: | [show references] |