Libraryless. Click here for Pure Java version (3290L/23K/74K).
1 | !7 |
2 | |
3 | // np = noun phrase |
4 | // q = question word |
5 | // vb = verb phrase |
6 | // adj = adjective |
7 | |
8 | static SS data = litmap( |
9 | "Commodore", "np", |
10 | "Commodore 64", "np", |
11 | "Amiga", "np", |
12 | "Atari", "np", |
13 | "Atari ST", "np", |
14 | "What", "q", |
15 | "Where", "q", |
16 | "How", "q", |
17 | "Why", "q", |
18 | "When", "q", |
19 | "is", "vb", |
20 | "are", "vb", |
21 | "wants", "vb", |
22 | "does", "vb", |
23 | "goes", "vb", |
24 | "fast", "adj", |
25 | "slow", "adj", |
26 | "new", "adj", |
27 | "old", "adj", |
28 | "<q> <vb> <np>", "question", |
29 | ); |
30 | |
31 | static O parser; |
32 | |
33 | p { |
34 | parser = hotwire("#1002719"); |
35 | print(parse("What is Amiga")); |
36 | makeBot(); |
37 | } |
38 | |
39 | static S parse(S text) { |
40 | S rules = makeRules(); |
41 | O result; |
42 | time { |
43 | result = call(parser, "parse", text, rules); |
44 | } |
45 | |
46 | //ret "```" + call(result, "prettierAnalysis") + "```"; |
47 | //ret structure(call(result, "explain", explainClass)); |
48 | |
49 | L<S> classes = cast call(result, "fullMatchClasses"); |
50 | ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]"; |
51 | } |
52 | |
53 | static S makeRules() { |
54 | ret fromLines(map(data, func(S s, S c) { s + " = " + c })); |
55 | } |
56 | |
57 | synchronized static S answer(S s) { |
58 | ret parse(s); |
59 | } |
Began life as a copy of #1005313
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005314 |
Snippet name: | Destructuring Text Using Bottom-Up Parser [does something] |
Eternal ID of this version: | #1005314/4 |
Text MD5: | 8602a3a86003670d0bb40eeb5e48a3b7 |
Transpilation MD5: | 574cdb6b8f9db5f9b94cc08d16d427ef |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-24 22:35:01 |
Source code size: | 1222 bytes / 59 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 417 / 507 |
Version history: | 3 change(s) |
Referenced in: | [show references] |