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

60
LINES

< > BotCompany Repo | #1001494 // Answer Questions Bot (developing)

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

Libraryless. Click here for Pure Java version (1683L/11K/39K).

1  
// Answer Questions Bot knows how to answer questions to any other bot.
2  
3  
!747
4  
5  
m {
6  
  static new AList<Question> questions;
7  
  
8  
  !include #1001495 // AList
9  
  
10  
  static class Question {
11  
    S botID;
12  
    S questionPattern;
13  
    new Code code;
14  
  }
15  
  
16  
  static class Code {
17  
    S snippetID;
18  
    boolean blessed; // is it known to be safe to run?
19  
  }
20  
  
21  
  p {
22  
    readLocally("questions");
23  
    makeAndroid3("Questions Bot.");
24  
  }
25  
  
26  
  static synchronized S answer(S s, L<S> history) {
27  
    new Matches m;
28  
    
29  
    if (match3("how can question * to bot * be answered?", s, m)) {
30  
      S botID = formatSnippetID(m.unq(0));
31  
      S text = m.unq(1);
32  
      L<Question> l = findQuestion(botID, text);
33  
      if (l.isEmpty())
34  
        ret "I don't know.";
35  
      Code code = l.get(0).code;
36  
      ret format3("code: *, (" + (code.blessed ? "blessed" : "non-blessed") + ")", code.snippetID);
37  
    }
38  
    
39  
    if (match3("add: bot *, question *, code snippet: *, blessed: *", s, m)) {
40  
      new Question q;
41  
      q.botID = m.fsi(0);
42  
      q.questionPattern = m.unq(1);
43  
      q.code.snippetID = m.fsi(2);
44  
      q.code.blessed = m.bool(3);
45  
    }
46  
    
47  
    ret standardQuery(s, "questions");
48  
  }
49  
  
50  
  static L<Question> findQuestion(S botID, S text) {
51  
    new L<Question> l;
52  
    
53  
    // It is thread-safe to iterate over an AList :)
54  
    for (Question q : questions)
55  
      if (sameSnippetID(q.botID, botID)
56  
        && match3(q.questionPattern, text))
57  
        l.add(q);
58  
    ret l;
59  
  }
60  
}

Author comment

Began life as a copy of #1001493

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001494
Snippet name: Answer Questions Bot (developing)
Eternal ID of this version: #1001494/1
Text MD5: bd79681b7c9277f813be585ae39adfa2
Transpilation MD5: 0b080757b4dd646d47c6899e7e000f17
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-20 23:52:48
Source code size: 1516 bytes / 60 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 612 / 619
Referenced in: [show references]