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

74
LINES

< > BotCompany Repo | #1001694 - Points (developing)

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

Libraryless. Click here for Pure Java version (898L/7K/20K).

1  
!747
2  
!multi-line strings
3  
4  
m {
5  
  static S input = [[
6  
    // Dogmas
7  
    
8  
    A point consists of a number "x" and number "y".
9  
    These numbers are independent.
10  
    A number might be a float.
11  
12  
    // Questions
13  
    
14  
    What are x and y of the point "1,2"?
15  
  ]];
16  
  
17  
  !include #2000515 // unquote
18  
  !include #1000709 // formatSnippetID
19  
  
20  
  static class Point {
21  
    static Map<S, O> parse(S s) {
22  
      new Matches m;
23  
      if (match3("*,*", s, m))
24  
        ret litmap("x", parseDouble(m.unq(0)), "y", parseDouble(m.unq(1)));
25  
      ret null;
26  
    }
27  
  }
28  
  
29  
  static Map<S, O> concepts = litmap("point", Point.class);
30  
31  
  p {
32  
    for (S line : toLinesFullTrim(input))
33  
      print(answer(line));
34  
  }
35  
  
36  
  static S answer(S line) {
37  
    L<S> tok = nlTok(line);
38  
    if (l(tok) == 1) ret "...";
39  
    simplify(tok);
40  
    S s = join(tok);
41  
    print("  " + s);
42  
    
43  
    new Matches m;
44  
    
45  
    // Dogmas - We just ignore them this time
46  
    
47  
    // Questions
48  
    
49  
    if (match3("What are the * and * of the * *?", s, m)
50  
      || match3("What are * and * of the * *?", s, m)) {
51  
      S component1 = simplifyName(m.unq(0));
52  
      S component2 = simplifyName(m.unq(1));
53  
      S name = simplifyName(m.unq(2));
54  
      S pattern = m.unq(3);
55  
      O concept = concepts.get(name);
56  
      Map<S, O> instance = (Map) call(concept, "parse", pattern);
57  
      ret structure(instance); // TODO: filter for components
58  
    }
59  
    
60  
    ret "huh?";
61  
  }
62  
  
63  
  static S simplifyName(S s) {
64  
    ret join(" ", codeTokensOnly(tokensToLowerCase(nlTok(s))));
65  
  }
66  
  
67  
  static void simplify(L<S> tok) {
68  
    for (int i = 1; i < l(tok); )
69  
      if (equalsIgnoreCase(tok.get(i), "usually")) {
70  
        removeToken(tok, i);
71  
      } else
72  
        i += 2;
73  
  }
74  
}

Author comment

Began life as a copy of #1001685

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001694
Snippet name: Points (developing)
Eternal ID of this version: #1001694/1
Text MD5: 0e012e1d10d41cc4fa73413122c99d68
Transpilation MD5: c1fdb8dce7e16f4e972837fd787f705d
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-05 16:12:59
Source code size: 1775 bytes / 74 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 493 / 862
Referenced in: [show references]