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

49
LINES

< > BotCompany Repo | #1000886 // Answer questions 3

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

Libraryless. Click here for Pure Java version (316L/3K/9K).

1  
!747
2  
3  
m {
4  
  static S question = "Is port 80 open?";
5  
  
6  
  static class ThePortOracle {
7  
    static S isPort_open(S s) {
8  
      int port = parseInt(s);
9  
      print("I'll check port " + port + "..."); 
10  
      boolean b = isPortOpen(port);
11  
      return b ? "Yes, it is open!" : "No, it is not open.";
12  
    }
13  
  }
14  
  
15  
  // pattern, class name, method
16  
  static String[][] entries = {
17  
    {"is port * open", "ThePortOracle", "isPort_open"}
18  
  };
19  
  
20  
  static S answerQuestion(S question) {
21  
    L<S> tok = parse(question);
22  
    
23  
    for (S[] e : entries) {
24  
      S[] m = match2(parse(e[0]), tok);
25  
      if (m != null) ctex {
26  
        Class c = Class.forName("main$" + e[1]);
27  
        return "" + call(c, e[2], (Object[]) m);
28  
      }
29  
    }
30  
    return unknown(question);
31  
  }
32  
  
33  
  static S unknown(S question) {
34  
    return "? Unknown question: " + question;
35  
  }
36  
37  
  p {
38  
    if (args.length != 0)
39  
      question = join(" ", args);
40  
    print("Q: " + question);
41  
    
42  
    S answer = answerQuestion(question);
43  
    print("A: " + answer);
44  
  }
45  
  
46  
  static L<S> parse(S s) {
47  
    return tokensToLowerCase(dropPunctuation(javaTokPlusPeriod(s)));
48  
  }
49  
}

Author comment

Began life as a copy of #1000885

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: #1000886
Snippet name: Answer questions 3
Eternal ID of this version: #1000886/1
Text MD5: 2312f8b135c2df083b06cd0e28d0a78d
Transpilation MD5: a3a62b838f4a3046884589c441829158
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-05 15:26:45
Source code size: 1165 bytes / 49 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 639 / 614
Referenced in: [show references]