Libraryless. Click here for Pure Java version (649L/5K/16K).
1 | !747 |
2 | !multi-line strings |
3 | |
4 | m {
|
5 | !include #1001509 // rules & statements |
6 | |
7 | p {
|
8 | rules.add([["$1 is the singular of $2." <=> "$2 is the plural of $1."]]); |
9 | statements.add("house is the singular of houses.");
|
10 | |
11 | process(); |
12 | print(fromLines(statements)); |
13 | |
14 | ask([[how many plurals does "house" have?]]); |
15 | ask([[what are the plurals of "house"?]]); |
16 | } |
17 | |
18 | static void ask(S q) {
|
19 | print("? " + q);
|
20 | |
21 | new Map<S, S> map; |
22 | if (match4("how many plurals does $1 have?", q, map))
|
23 | print(" => " + getPlurals(map.get("$1")).size());
|
24 | else if (match4("what are the plurals of $1?", q, map))
|
25 | print(" => " + structure(getPlurals(map.get("$1"))));
|
26 | else |
27 | print("dunno.");
|
28 | } |
29 | |
30 | static L<S> getPlurals(S x) {
|
31 | S c = "$2 is the plural of " + x; |
32 | print("[" + c + "]");
|
33 | MultiMap<S, S> matches = matchAll(c); |
34 | ret matches.get("$2");
|
35 | } |
36 | } |
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: | 826 / 891 |
| Referenced in: | [show references] |