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

68
LINES

< > BotCompany Repo | #1002761 // SNL Logic Engine 5, factored out LogicEngine

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

Libraryless. Click here for Pure Java version (4525L/29K/93K).

1  
!759
2  
3  
static S codeSnippetID = "#1002758";
4  
static Lisp code;
5  
static new L<Lisp> memory;
6  
static LogicEngine engine;
7  
8  
!include #1002759 // LogicEngine
9  
10  
static class MyEngine extends LogicEngine {
11  
  *(Lisp code, L<Lisp> memory) {
12  
    super(code, memory);
13  
  }
14  
  
15  
  public boolean yo(Lisp snl, SNLMatches m) {
16  
    if (super.yo(snl, m))
17  
      ret true;
18  
    
19  
    new SNLMatches mInner;
20  
   
21  
    if (snlMatch2("[the > length < of < string < S] < is < L < characters", snl, mInner)) { // TODO: variable renaming?
22  
      S s = snlGetString(mInner.map, "S");
23  
      putMatchX(m.map, mInner.map, "L", lstr(s));
24  
      ret true;
25  
    }
26  
    
27  
    ret false;
28  
  }
29  
}
30  
31  
p {
32  
  code = snlToTree(loadSnippet(codeSnippetID));
33  
  print(getProgramID() + ": parse result = " + code);
34  
  load("memory");
35  
}
36  
37  
synchronized answer {
38  
  if (!attn()) ret null;
39  
  
40  
  if (match("log " + parseSnippetID(programID()), s))
41  
    ret engine == null ? "nullie haven't run yet": slackSnippet(fromLines(engine.log));
42  
  
43  
  if (match("memory " + parseSnippetID(programID()), s))
44  
    ret slackSnippet(snlAllToText(memory));
45  
  
46  
  // convert to SNL first
47  
  s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s);
48  
  Lisp in = snlToTree(s);
49  
  
50  
  Lisp statement = snlToTree("user < says < [" + snlFromTree(in) + "]");
51  
  engine = new MyEngine(code, memory) {
52  
    void saveMemory() {
53  
      save("memory");
54  
    }
55  
  };
56  
  engine.stmAdd(statement);
57  
  
58  
  L<Lisp> out = engine.run();
59  
  if (nempty(out))
60  
    ret "[SNL: " + snlFromTree(in) + "])\n" + snlAllToText(out);
61  
}
62  
63  
static Lisp quickrun(L<Lisp> memory, S userInput) {
64  
  engine = new LogicEngine(code, memory);
65  
  Lisp statement = snlToTree("user < says < [" + userInput + "]");
66  
  engine.stmAdd(statement);
67  
  ret snlMakeJuxta(engine.run());
68  
}

Author comment

Began life as a copy of #1002751

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: #1002761
Snippet name: SNL Logic Engine 5, factored out LogicEngine
Eternal ID of this version: #1002761/1
Text MD5: f8d7318419e38962ae798552b536dc2d
Transpilation MD5: 41ef1048130f8303346a47e294825ee4
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-22 19:42:22
Source code size: 1805 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 609 / 858
Referenced in: [show references]