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).

!759

static S code = [=[
  if   [User < says < what < is < a < XY]
  and  [XY < can < be < split < in < 2 < as < X < and < Y]
  // and  [X < is < an < adjective]
  then [say < maybe < [a > XY] is < [a > Y] < that < is < [very > X]]
]=];

static boolean yo(Lisp snl, Map m) {
  new HashMap<S, Lisp> m2;
  if (snlMatch("XY < can < be < split < in < 2 < as < X < and < Y", snl, m2)) {
    //print("m2: " + structure (m2));
    S XY = snlGetString(m2, "XY");
    L<S> l = codeTokensOnly(javaTok(XY));
    print ("XY: " + XY + ", " + l);
    if (l(l) != 2) ret false;
    putMatchX(m, m2, "X", l.get(0));
    putMatchX(m, m2, "Y", l.get(1));
    ret true;
  }
  
  if (snlMatch("X < is < an < adjective", snl, m2)) {
    S X = snlGetString(m2, "X");
    ret isYes(askSelf("is * an adjective", X));
  }
  
  ret false;
}

static S answer(S s) {
  s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s);
  Lisp in = snlToTree(s);
  new HashMap<S, Lisp> m;
  for (S cs : toLinesFullTrim(code)) {
    Lisp code = snlToTree(cs);
    if (code.isic("if *", "and *")) {
      Lisp a = code.get(0);
      Lisp b = snlApply(a, m);

      boolean OK = false;
      S x;
      if (snlMatchX(b, x = "user < says < [ " + s + " ]", m)) OK = true;
      print("ok: " + OK + ", x: " + x + ", b: " + b + ", " + snlToTree(x) + "m: " + structure (m));

      pcall {
        if (!OK && yo(b, m)) { // todo: rename vars
         OK = true;
        }
      }

      print("ok: " + OK);

      if (!OK) ret null;

      print ("Ok " + snlFromTree(b));

    } else if (code.isic("then *")) {
      Lisp a = code.get(0);
      if (a.isA("<")) { // say
        Lisp b = a.get (1);
        print ("m: " + structure (m) + ", b: " + structure (b));
        ret snlToText(snlApply(b, m));
      }
    }
  }

  null;

}

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: 687 / 890
Referenced in: [show references]