Download Jar. Uses 3874K of libraries. Click here for Pure Java version (9759L/67K).
!759 sS guessProgramS = #1008669; //#1008653; sS guessProgramV = #1008680; static SingleComponentPanel scp; static int startIndex; sO guessModuleS, guessModuleV; static ReliableSingleThread relearnThread = new(f relearn); static JComboBox cbMode; concept Sentence { S text; S action; // subject S verb; } p-substance { unswing { useDBOf(#1008607); db(); indexConceptField(Sentence, "text"); L<S> sentences = toLinesFullTrim(loadSnippet(#1008606)); sentences = notStartingWith("\"", sentences); time { makeUniqueConcepts(Sentence, "text", sentences); } pcall { guessModuleS = runDependent(guessProgramS); } pcall { guessModuleV = runDependent(guessProgramV); } } showFrame(centerAndSouth(scp = new SingleComponentPanel, withTopMargin(20, jcenteredline( jbutton("Prev", r { makePanel(max(startIndex-10, 0)) }), jbutton("Next", f nextPage), jbutton("Random", r { makePanel(random(countConcepts(Sentence))/10*10) }), jbutton("All OK", r { clickButtons(findButtons(scp, "OK")); nextPage(); }), jbutton("Re-learn", r { relearnThread.trigger() }))))); setFrameWidth(scp, 1000); centerFrame(scp); makePanel(0); } svoid makePanel(int startIndex) { main.startIndex = startIndex; makePanel(); } svoid makePanel() { JPanel panel = gridLayoutPanel_trackWidth_evenlySpacedCols(2); panel.add(jlabel("Sentence")); panel.add(jline(cbMode = jcombobox_copySelection(cbMode, "Subject", "Verb"))); onChange(cbMode, f makePanel); for (final Sentence s : takeFirst(10, dropFirst(startIndex, list(Sentence)))) { final JTextField tfText = jtextfield_caretLeft(s.text); tfText.setCaret(new DefaultCaret { @Override public void setSelectionVisible(boolean visible) { super.setSelectionVisible(true); } }); panel.add(tfText); IntRange r = ai_parseSubjectAction(s.action); if (r != null) tfText.select(r.start, r.end); bool hasAction = nempty(verbMode() ? s.verb : s.action); final JTextField tf = jtextfield(hasAction ? (verbMode() ? s.verb : s.action) : guessAction(s)); final new Var<JButton> reviseBtn, okBtn; okBtn.set(jbutton("OK", r { cset(s, verbMode() ? "verb" : "action", getTextTrim(tf)); disableTextField(tf); replaceComponent(okBtn!, reviseBtn!); relearnThread.trigger(); })); reviseBtn.set(jbutton("Revise", r { cset(s, verbMode() ? "verb" : "action", null); enableTextField(tf); replaceComponent(reviseBtn!, okBtn!); })); if (hasAction) disableTextField(tf); panel.add(centerAndEast(tf, hasAction ? reviseBtn! : okBtn!)); onCaret(tfText, r { if ((verbMode() ? s.verb : s.action) == null) { S a; IntRange r = IntRange(tfText.getSelectionStart(), tfText.getSelectionEnd()); if (verbMode()) a = ai_makeVerbAction(s.text, ll(r)); else a = ai_makeSubjectAction(s.text, r); if (a != null) tf.setText(a); } }); } scp.setComponent(jscroll(panel)); } static IntRange guessSubject(S sentence) { if (guessModuleS == null) null; ret (IntRange) quickImport(call(guessModuleS, "callGuesser", get(guessModuleS, "best"), sentence)); } static L<IntRange> guessVerb(S sentence, IntRange subject) { if (guessModuleV == null) null; ret (L<IntRange>) callWithImportExport(guessModuleV, "callGuesser", get(guessModuleV, "best"), sentence, subject); } static S guessAction(Sentence s) { if (verbMode()) { IntRange subject = ai_parseSubjectAction(s.action); ret or2(ai_makeVerbAction(s.text, guessVerb(s.text, subject)), "?"); } else ret or2(ai_makeSubjectAction(s.text, guessSubject(s.text)), "?"); } svoid relearn { callMain(guessModuleS); callMain(guessModuleV); swing { makePanel(); } } svoid nextPage { if (startIndex+10 < countConcepts(Sentence)) makePanel(startIndex+10); } sbool verbMode() { ret cbMode.getSelectedIndex() > 0; }
Began life as a copy of #1008632
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: | #1008674 |
Snippet name: | Sentences to subject/verb with guessing [WORKS a bit] |
Eternal ID of this version: | #1008674/24 |
Text MD5: | 5a152c68cab3063ddbd184765df94eb4 |
Transpilation MD5: | 2062b7c3e296803307861e23e41ed315 |
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 20:08:11 |
Source code size: | 4097 bytes / 126 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 548 / 1210 |
Version history: | 23 change(s) |
Referenced in: | [show references] |