Libraryless. Click here for Pure Java version (3766L/23K).
// potentially slow (not using levenLimited) // returns edit distance or null if no match at all static Int mmo_levenWithSwapsScore_parsedPattern(MMOPattern pattern, S s) { S s2 = trim(s); if (pattern == null) null; if (startsWith(s2, "#")) null; // hashtags not handled here if (pattern cast MMOPattern.Phrase) { if (pattern.quoted) ret mmo_match_parsedPattern(pattern, s2) ? (Int) 0 : null; S p = pattern.phrase; if (startsWith(p, "#")) null; // hashtags not handled here if (endsWith(p, "!")) ret find3(p, s) ? 0 : null; else ret find3_levenWithSwapsDistance(p, s2); } if (pattern cast MMOPattern.And) { int score = 0; for (MMOPattern pat : pattern.l) { Int score2 = mmo_levenWithSwapsScore_parsedPattern(pat, s2); if (score2 == null) null; score += score2; } ret score; } if (pattern cast MMOPattern.Or) { Int min = null; for (MMOPattern pat : pattern.l) min = min_withNull(min, mmo_levenWithSwapsScore_parsedPattern(pat, s2)); ret min; } // not clauses are not checked for typos if (pattern instanceof MMOPattern.Not) ret mmo_match_parsedPattern(pattern, s2) ? 0 : null; fail("what. " + pattern); } static Int mmo_levenWithSwapsScore_parsedPattern(S pattern, S s) { ret mmo_levenWithSwapsScore_parsedPattern(mmo_parsePattern(pattern), s); }
Began life as a copy of #1026037
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: | #1026502 |
Snippet name: | mmo_levenWithSwapsScore_parsedPattern - like mmo_match_parsedPattern, but return leven difference |
Eternal ID of this version: | #1026502/11 |
Text MD5: | 980384013927c866e09b13b8362b70df |
Transpilation MD5: | 0aa87e809e5606ba052bd4b63c0bc7fd |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-05-05 21:47:27 |
Source code size: | 1404 bytes / 41 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 316 / 470 |
Version history: | 10 change(s) |
Referenced in: | [show references] |