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; }
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