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

70
LINES

< > BotCompany Repo | #1002723 // SNL Logic Engine (developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (3931L/26K/85K).

1  
!759
2  
3  
static S code = [=[
4  
  if   [User < says < what < is < a < XY]
5  
  and  [XY < can < be < split < in < 2 < as < X < and < Y]
6  
  // and  [X < is < an < adjective]
7  
  then [say < maybe < [a > XY] is < [a > Y] < that < is < [very > X]]
8  
]=];
9  
10  
static boolean yo(Lisp snl, Map m) {
11  
  new HashMap<S, Lisp> m2;
12  
  if (snlMatch("XY < can < be < split < in < 2 < as < X < and < Y", snl, m2)) {
13  
    //print("m2: " + structure (m2));
14  
    S XY = snlGetString(m2, "XY");
15  
    L<S> l = codeTokensOnly(javaTok(XY));
16  
    print ("XY: " + XY + ", " + l);
17  
    if (l(l) != 2) ret false;
18  
    putMatchX(m, m2, "X", l.get(0));
19  
    putMatchX(m, m2, "Y", l.get(1));
20  
    ret true;
21  
  }
22  
  
23  
  if (snlMatch("X < is < an < adjective", snl, m2)) {
24  
    S X = snlGetString(m2, "X");
25  
    ret isYes(askSelf("is * an adjective", X));
26  
  }
27  
  
28  
  ret false;
29  
}
30  
31  
static S answer(S s) {
32  
  s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s);
33  
  Lisp in = snlToTree(s);
34  
  new HashMap<S, Lisp> m;
35  
  for (S cs : toLinesFullTrim(code)) {
36  
    Lisp code = snlToTree(cs);
37  
    if (code.isic("if *", "and *")) {
38  
      Lisp a = code.get(0);
39  
      Lisp b = snlApply(a, m);
40  
41  
      boolean OK = false;
42  
      S x;
43  
      if (snlMatchX(b, x = "user < says < [ " + s + " ]", m)) OK = true;
44  
      print("ok: " + OK + ", x: " + x + ", b: " + b + ", " + snlToTree(x) + "m: " + structure (m));
45  
46  
      pcall {
47  
        if (!OK && yo(b, m)) { // todo: rename vars
48  
         OK = true;
49  
        }
50  
      }
51  
52  
      print("ok: " + OK);
53  
54  
      if (!OK) ret null;
55  
56  
      print ("Ok " + snlFromTree(b));
57  
58  
    } else if (code.isic("then *")) {
59  
      Lisp a = code.get(0);
60  
      if (a.isA("<")) { // say
61  
        Lisp b = a.get (1);
62  
        print ("m: " + structure (m) + ", b: " + structure (b));
63  
        ret snlToText(snlApply(b, m));
64  
      }
65  
    }
66  
  }
67  
68  
  null;
69  
70  
}

Author comment

Began life as a copy of #1002718

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002723
Snippet name: SNL Logic Engine (developing)
Eternal ID of this version: #1002723/1
Text MD5: 748d33abb54cc1d398f914e8fa25f671
Transpilation MD5: 940f0b8d8f215eb860da69089ccdba61
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-24 21:34:11
Source code size: 1865 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 688 / 893
Referenced in: [show references]