Libraryless. Click here for Pure Java version (2977L/20K/64K).
1 | !759 |
2 | |
3 | static Class parser; |
4 | |
5 | static S javaRulesID = "#1002329"; |
6 | |
7 | p { |
8 | print("parser bot loading"); |
9 | parser = hotwire_overBot("#1002472"); |
10 | print("parser bot loaded"); |
11 | } |
12 | |
13 | answer { |
14 | if (startsWithIgnoreCase(s, "parse ")) try { |
15 | fillNLParser(parser); |
16 | S text = s.substring(5).trim(); |
17 | boolean debug = text.startsWith("debug "); |
18 | if (debug) text = text.substring(5).trim(); |
19 | boolean explain = text.startsWith("explain "); |
20 | S explainClass = null; |
21 | if (explain) { |
22 | text = text.substring("explain ".length()).trim(); |
23 | int i = text.indexOf(' '); |
24 | explainClass = text.substring(0, i).trim(); |
25 | text = text.substring(i).trim(); |
26 | } |
27 | |
28 | O result; |
29 | time { |
30 | result = call(parser, "parse", text); |
31 | } |
32 | |
33 | if (debug) |
34 | ret structure(get(parser, "recog")); |
35 | else if (explain) |
36 | ret structure(call(result, "explain", explainClass)); |
37 | else { |
38 | L<S> classes = cast call(result, "fullMatchClasses"); |
39 | ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]"; |
40 | } |
41 | } catch (Throwable e) { |
42 | ret exceptionToUser(e); |
43 | } |
44 | |
45 | if (startsWithIgnoreCase(s, "jparse ")) try { |
46 | S text = s.substring(6).trim(); |
47 | |
48 | // make a separate parser for Java |
49 | O parser = hotwire_overBot("#1002472"); |
50 | |
51 | boolean debug = text.startsWith("debug "); |
52 | if (debug) text = text.substring(5).trim(); |
53 | boolean explain = text.startsWith("explain "); |
54 | S explainClass = null; |
55 | if (explain) { |
56 | text = text.substring("explain ".length()).trim(); |
57 | int i = text.indexOf(' '); |
58 | explainClass = text.substring(0, i).trim(); |
59 | text = text.substring(i).trim(); |
60 | } |
61 | |
62 | O result; |
63 | time { |
64 | result = call(parser, "parse", text, javaRulesID); |
65 | } |
66 | |
67 | if (debug) |
68 | ret "```" + call(result, "prettierAnalysis") + "```"; |
69 | else if (explain) |
70 | ret structure(call(result, "explain", explainClass)); |
71 | else { |
72 | L<S> classes = cast call(result, "fullMatchClasses"); |
73 | ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]"; |
74 | } |
75 | } catch (Throwable e) { |
76 | ret exceptionToUser(e); |
77 | } |
78 | } |
79 | |
80 | static void fillNLParser(O parser) { |
81 | callOpt(parser, "addDict", "adjective", makeEleuSet("adjective")); |
82 | |
83 | O bot = getBot("#1002342"); // nouns bot |
84 | if (bot != null) |
85 | callOpt(parser, "addDict", "noun", get(bot, "nouns")); |
86 | } |
Began life as a copy of #1002308
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002372 |
Snippet name: | New Parser Bot (parse/jparse) |
Eternal ID of this version: | #1002372/1 |
Text MD5: | 61300e08f4333bc3f99089d5d7fdf44b |
Transpilation MD5: | 22e34baa7a7e5ac885341764f1a3c3e5 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-01 19:57:32 |
Source code size: | 2604 bytes / 86 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 681 / 1633 |
Referenced in: | [show references] |