Libraryless. Click here for Pure Java version (3459L/21K).
static MMOPattern mmo2_parsePattern(S s) { // drop outer brackets and tokenize s = trim(tok_deRoundBracket(trim(s))); LS tok = javaTokWithBrackets(s); // commas (or) - "car, vehicle" LS l = tok_splitAtComma(tok); if (l(l) > 1) ret new MMOPattern.Or(lambdaMap mmo2_parsePattern(l)); // plus (and) - "give + money" l = tok_splitAtPlus(tok); if (l(l) > 1) ret new MMOPattern.And(lambdaMap mmo2_parsePattern(l)); // exclam (not) - "!something" if (startsWith(s, "!")) ret new MMOPattern.Not(mmo2_parsePattern(dropFirst(s))); // ^... - match start of line if (startsWith(s, "^")) ret new MMOPattern.StartOfLine(mmo2_parsePattern(dropFirst(s))); // ...$ - match end of line if (endsWith(s, "$")) ret new MMOPattern.EndOfLine(mmo2_parsePattern(dropLast(s))); // ...*0.5 - weighted pattern l = tok_splitAtAsterisk(tok); if (l(l) == 2) ret new MMOPattern.Weighted(parseDouble(second(l)), mmo2_parsePattern(first(l))); // phrase (possibly quoted) ret new MMOPattern.Phrase(unquote(s), isQuoted(s)); }
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: | 240 / 366 |
Version history: | 5 change(s) |
Referenced in: | [show references] |