Libraryless. Click here for Pure Java version (3459L/21K).
1 | static MMOPattern mmo2_parsePattern(S s) { |
2 | // drop outer brackets and tokenize |
3 | |
4 | s = trim(tok_deRoundBracket(trim(s))); |
5 | LS tok = javaTokWithBrackets(s); |
6 | |
7 | // commas (or) - "car, vehicle" |
8 | |
9 | LS l = tok_splitAtComma(tok); |
10 | if (l(l) > 1) |
11 | ret new MMOPattern.Or(lambdaMap mmo2_parsePattern(l)); |
12 | |
13 | // plus (and) - "give + money" |
14 | |
15 | l = tok_splitAtPlus(tok); |
16 | if (l(l) > 1) |
17 | ret new MMOPattern.And(lambdaMap mmo2_parsePattern(l)); |
18 | |
19 | // exclam (not) - "!something" |
20 | |
21 | if (startsWith(s, "!")) |
22 | ret new MMOPattern.Not(mmo2_parsePattern(dropFirst(s))); |
23 | |
24 | // ^... - match start of line |
25 | |
26 | if (startsWith(s, "^")) |
27 | ret new MMOPattern.StartOfLine(mmo2_parsePattern(dropFirst(s))); |
28 | |
29 | // ...$ - match end of line |
30 | |
31 | if (endsWith(s, "$")) |
32 | ret new MMOPattern.EndOfLine(mmo2_parsePattern(dropLast(s))); |
33 | |
34 | // ...*0.5 - weighted pattern |
35 | |
36 | l = tok_splitAtAsterisk(tok); |
37 | if (l(l) == 2) |
38 | ret new MMOPattern.Weighted(parseDouble(second(l)), mmo2_parsePattern(first(l))); |
39 | |
40 | // phrase (possibly quoted) |
41 | |
42 | ret new MMOPattern.Phrase(unquote(s), isQuoted(s)); |
43 | } |
Began life as a copy of #1026499
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028071 |
Snippet name: | mmo2_parsePattern - V2 of the NLP pattern language - with ^, $ and weights |
Eternal ID of this version: | #1028071/6 |
Text MD5: | cf37bc206102e2210fb0929dfde33868 |
Transpilation MD5: | a01a74f08339eb828e0a131643e1a38d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-25 13:09:18 |
Source code size: | 1149 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 241 / 367 |
Version history: | 5 change(s) |
Referenced in: | [show references] |