Uses 911K of libraries. Click here for Pure Java version (18691L/103K).
!7 cmodule AIPackagesSpike > DynTextArea { transient PhilosophyBot1 bot; transient Scorer scorer; S verificationResult; start { grabInterval = 1.0; dm_onFieldChangeAndNow text(r compute); } void compute q { S input = getText(); TreeMap<S> sections = asCIMap(underlinedHeadingSections(input)); LS tests = nempties(itemPlusList(getAny(sections, "", "test"), valuesForKeysStartingWith(sections, "test "))); print("Have " + nTests(tests)); S solutionText = sections.get("Example solution"); scorer = new Scorer; for (S testText : tests) scorer.add(testSolution(testText, solutionText)); setField(verificationResult := str(scorer)); print(scorer); } bool testSolution(S testText, S solutionText) { MultiMap<S> testPairs = parseColonPropertyCIMultiMap(testText); MultiMap<S> solutionPairs = parseColonPropertyCIMultiMap_honorBrackets(solutionText); // facts LS qs = testPairs.get("Q"); Cl<S> facts = concatLists( testPairs.get("Fact"), qs, solutionPairs.get("Fact"), map(qs, q -> format_quoteAll("input is *", q))); // get patterns from rules Cl<S> rules = solutionPairs.get("Rule"); pnl("RULES> ", rules); bot = new PhilosophyBot1(joinWithEmptyLines(rules)); philosophyBot_autoJava(bot); pb_enableAutoPatterns(bot); // add facts to bot, calculate S program = joinWithEmptyLines(facts); printWithIndent("PROGRAM> ", program); bot.loadProgram(program); bot.run(); // Check answer Set<S> wantedAnswers = mapToCISet dropPunctuation(testPairs.get("A")); Set<S> unwantedAnswers = mapToCISet dropPunctuation(testPairs.get("Not an answer")); pnl(+wantedAnswers); pnl(+unwantedAnswers); bool good = listAndSetIntersect(bot.deducedFacts(), wantedAnswers); bool bad = listAndSetIntersect(bot.deducedFacts(), unwantedAnswers); if (bad) ret false with print("BAD answer!"); if (good) ret true with print("OK!"); ret false with print("No answer..."); } void saveIt enter { dm_call(dm_aiPackagesCRUD(), 'storeAIPackage, getText(), verificationResult); infoBox("Stored. Total number of AI packages: " + dm_rcall conceptCount(dm_aiPackagesCRUD())); } visual withMargin(withCenteredButtons( jvsplit(super, dm_printLogComponent()), "Compute", rThread compute, "Save", rThread saveIt)); }
Began life as a copy of #1027406
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027422 |
Snippet name: | AI Package Tester v2 [shortened/generalized, latest version] |
Eternal ID of this version: | #1027422/8 |
Text MD5: | 3483fab6b8cf6c665f79a56a75dde261 |
Transpilation MD5: | 79c8bde85f44c01d05992ea76c438057 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-19 15:33:09 |
Source code size: | 2508 bytes / 79 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 186 / 593 |
Version history: | 7 change(s) |
Referenced in: | [show references] |