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).

!747
!multi-line strings

m {
  static S input = [[
    // Dogmas
    
    A point consists of a number "x" and number "y".
    These numbers are independent.
    A number might be a float.

    // Questions
    
    What are x and y of the point "1,2"?
  ]];
  
  !include #2000515 // unquote
  !include #1000709 // formatSnippetID
  
  static class Point {
    static Map<S, O> parse(S s) {
      new Matches m;
      if (match3("*,*", s, m))
        ret litmap("x", parseDouble(m.unq(0)), "y", parseDouble(m.unq(1)));
      ret null;
    }
  }
  
  static Map<S, O> concepts = litmap("point", Point.class);

  p {
    for (S line : toLinesFullTrim(input))
      print(answer(line));
  }
  
  static S answer(S line) {
    L<S> tok = nlTok(line);
    if (l(tok) == 1) ret "...";
    simplify(tok);
    S s = join(tok);
    print("  " + s);
    
    new Matches m;
    
    // Dogmas - We just ignore them this time
    
    // Questions
    
    if (match3("What are the * and * of the * *?", s, m)
      || match3("What are * and * of the * *?", s, m)) {
      S component1 = simplifyName(m.unq(0));
      S component2 = simplifyName(m.unq(1));
      S name = simplifyName(m.unq(2));
      S pattern = m.unq(3);
      O concept = concepts.get(name);
      Map<S, O> instance = (Map) call(concept, "parse", pattern);
      ret structure(instance); // TODO: filter for components
    }
    
    ret "huh?";
  }
  
  static S simplifyName(S s) {
    ret join(" ", codeTokensOnly(tokensToLowerCase(nlTok(s))));
  }
  
  static void simplify(L<S> tok) {
    for (int i = 1; i < l(tok); )
      if (equalsIgnoreCase(tok.get(i), "usually")) {
        removeToken(tok, i);
      } else
        i += 2;
  }
}

Author comment

Began life as a copy of #1001685

download  show line numbers  debug dex   

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

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: 431 / 712
Referenced in: [show references]

Formerly at http://tinybrain.de/1001694 & http://1001694.tinybrain.de