Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1025613 // Philosophy Bot 2 - match questions and answers [v3 with soc, dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6601L/34K).

!7

cmodule PhilosophyBot2 extends DynPrintLog {
  transient L unmappedLines = ll("good", "early morning");
  transient L unmappedQuestions = ll("what is the time", "how do you feel");
  transient SS mappings = ciMap();
  
  transient S program = [[
    start
    
    start => proc {
      run (proc {
        while (there are unmapped questions):
          find (an unmapped question) x
          find (an unmapped line) y
          map x to y
      }
) with backtracking
    }
  ]];
  
  transient new PhilosophyBot1 bot;

  start-thread {
    bot.program = program;
    bot.addNativePredicate("there are unmapped questions",
      () -> nempty(unmappedQuestions));

    bot.addNativePredicate("find (an unmapped question) x",
      (map, env) -> {
        print("find unmapped question x");
        ret randomChoiceFromChangingList('x, unmappedQuestions, env);
      });

    bot.addNativePredicate("find (an unmapped line) z",
      (map, env) -> {
        print("find unmapped line z");
        ret randomChoiceFromChangingList('z, unmappedLines, env);
      });

    bot.addNativePredicate("map x to y",
      (map, env) -> {
        S x = map.get("x"), y = map.get("y");
        unmappedQuestions.remove(x);
        unmappedLines.remove(y);
        print("Remaining unmapped questions: " + l(unmappedQuestions));
        mappings.put(x, y);
        print("Mapped question " + quote(x) + " to answer " + quote(y));
        ret !env.wantAlternatives() ? true : new PhilosophyBot1.WithAlternative(() -> {
          print("Undoing mapping of " + quote(x) + " to answer " + quote(y));
          unmappedQuestions.add(x);
          unmappedLines.add(y);
          false;
        }, true);
      });

   bot.addNativePredicate("run x with backtracking",
     (SS map) -> {
        S x = map.get("x");
        print("Run x with backtracking: " + x);
        bot.runParsedProcedure(bot.parseProcedure(x)); // TODO
        print("Ran x with backtracking: " + x);
        true;
     });
   
    bot.run();
  }

  O randomChoiceFromChangingList(S var, Cl<S> list, PhilosophyBot1.Env env) {
    if (empty(unmappedLines)) false;
    if (!env.wantAlternatives())
      ret litcimap(var, random(list));
    ret lazyMap(cloneList(list), z -> litcimap(var, z));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1025613
Snippet name: Philosophy Bot 2 - match questions and answers [v3 with soc, dev.]
Eternal ID of this version: #1025613/8
Text MD5: f9848b135a5ea6ee3c31e7397c1e94fe
Transpilation MD5: 77b4b289bbf6c621635afada90fc880b
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-08 20:34:38
Source code size: 2281 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 225 / 512
Version history: 7 change(s)
Referenced in: