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

36
LINES

< > BotCompany Repo | #1001510 // Singular & plural (v4, with include)

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

Libraryless. Click here for Pure Java version (649L/5K/16K).

!747
!multi-line strings

m {
  !include #1001509 // rules & statements
  
  p {
    rules.add([["$1 is the singular of $2." <=> "$2 is the plural of $1."]]);
    statements.add("house is the singular of houses.");
    
    process();
    print(fromLines(statements));

    ask([[how many plurals does "house" have?]]);
    ask([[what are the plurals of "house"?]]);
  }
  
  static void ask(S q) {
    print("? " + q);
    
    new Map<S, S> map;
    if (match4("how many plurals does $1 have?", q, map))
      print("  => " + getPlurals(map.get("$1")).size());
    else if (match4("what are the plurals of $1?", q, map))
      print("  => " + structure(getPlurals(map.get("$1"))));
    else
      print("dunno.");
  }
  
  static L<S> getPlurals(S x) {
    S c = "$2 is the plural of " + x;
    print("[" + c + "]");
    MultiMap<S, S> matches = matchAll(c);
    ret matches.get("$2");
  }
}

Author comment

Began life as a copy of #1001508

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: #1001510
Snippet name: Singular & plural (v4, with include)
Eternal ID of this version: #1001510/1
Text MD5: 3ded1bdd6f42b487bc960eb41e9b12bf
Transpilation MD5: 9e0a3543a2246cc8e06e9ba190726f95
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-21 16:19:10
Source code size: 928 bytes / 36 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 617 / 637
Referenced in: [show references]