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

81
LINES

< > BotCompany Repo | #1017900 // Calculation Bot v1 [Dyn Module, thinks about a topic, dev.]

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

Libraryless. Compilation Failed (22306L/166K).

1  
!7
2  
3  
set flag DynModule.
4  
5  
sclass CalculationBot > DynPrintLog {
6  
  bool debug;
7  
  LS entities = synchroList();
8  
  LS facts = synchroList();
9  
  SS questions = synchroCIMap();
10  
  L<IfThen> rules;
11  
  L<S> externalFacts;
12  
  
13  
  start {
14  
    loadFunctions_preferCached();
15  
    dm_useLocallyCopiedMechLists();
16  
    
17  
    Pair<L<IfThen>, LS> p = ai_activeRulesAndFacts();
18  
    rules = p.a;
19  
    rules.addAll(ai_parseRules(mL_raw("Data structures [Script]")));
20  
    //print("Have rules:");
21  
    //pnl(rules);
22  
    externalFacts = p.b;
23  
    
24  
    entities.add("the dawn of time");
25  
    new Thinking().step();
26  
    print("done");
27  
  }
28  
29  
  S evalExp(Exp e, NLLogicChecker_v2.Matching m) {
30  
    S code = nlLogic_text(e);
31  
    print("Eval'ing: " + code);
32  
    S result = str(evalWithDollarVars(code, m.matches));
33  
    print("Result: " + shorten(result, 100));
34  
    ret result;
35  
  }
36  
37  
  class Thinking {
38  
    void step {
39  
      final new NLLogicChecker_v3 c;
40  
41  
      c.entities = entities;
42  
      c.evaluator = func(Exp e, NLLogicChecker_v2.Matching m) -> S { evalExp(e, m) };
43  
      
44  
      c.facts = concatLists(facts, externalFacts);
45  
46  
      applyNLLogicFacts_v4(c, voidfunc(IfThen rule, NLLogicChecker_v2.Matching m) {
47  
        // Rule fired!
48  
        
49  
        print("Firing rule " + rule.globalID);
50  
        executeRule(c, RuleWithParams(rule, m.matches));
51  
      }, rules);
52  
    }
53  
    
54  
    void executeRule(NLLogicChecker_v3 c, RuleWithParams r) {
55  
      // Execute rule
56  
      for (Exp e : nlLogic_unrollAnd(r.rule.out)) {
57  
        e = c.apply(e, r.matches);
58  
        if (e cast Func) {
59  
          S name = e.name;
60  
          if (eq(name, 'fact)) {
61  
            S fact = nlLogic_text(e.arg);
62  
            if (!containsNL(facts, fact))
63  
              facts.add(fact);
64  
          } else if (eq(name, 'entity)) {
65  
            S ent = nlLogic_text(e.arg);
66  
            if (!containsNL(entities, ent)) {
67  
              entities.add(ent);
68  
              print("New entity: " + ent);
69  
            }
70  
          } /*else if (eq(name, 'input)) {
71  
            S x = nlLogic_text(e.arg);
72  
            if (!rewrittenInputs.contains(x) && newRewrittenInputs.add(x))
73  
              print("New rewritten input: " + x);
74  
          } */else
75  
            ret with print("Skipping rule with unknown RHS func: " + e.name);
76  
        } else
77  
          ret with print("Skipping rule with unknown RHS element: " + e);
78  
      }
79  
    }
80  
  } // end class Thinking
81  
}

Author comment

Began life as a copy of #1017807

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017900
Snippet name: Calculation Bot v1 [Dyn Module, thinks about a topic, dev.]
Eternal ID of this version: #1017900/22
Text MD5: 5857db5afbb59a27495446f837791e88
Transpilation MD5: d40f0c1601b6f979a714d458bd266a75
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: 2018-08-21 13:59:19
Source code size: 2441 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 374 / 799
Version history: 21 change(s)
Referenced in: [show references]