Libraryless. Click here for Pure Java version (3789L/24K).
abstract sclass WordTokRule extends Attractor implements RuleOnTok, RuleOnString, RuleOnExtTok, RuleOnExtS { S pattern; // example sentence Set<S> vars; // list of the variable words in the sentence bool debug; transient LS tokPat; // parsed pattern transient SS map; // not null if there is a match *() {} *(S *pattern, S... vars) { this.vars = litciset(vars); } *(S *pattern, Set<S> *vars) {} LS tokPat() { if (tokPat == null) tokPat = wordTok(pattern); ret tokPat; } public final bool matches(ExtS s) { process(s); ret matched(); } public final bool matches(S s) { process(s); ret matched(); } public void process(S s) { process(ext(s)); } public void process(ExtS s) { processExtTok(extLift(wordTok(s!), s)); } public void processTok(LS tok) { processExtTok(ext(tok)); } public void processExtTok(Ext<LS> tok) { if (!preCheck(tok)) ret; map = nullIfContainsKeysOtherThan(gazelle_zipTwoTokenizationsToMap(tokPat(), tok!), vars); if (debug) print(pattern + " + " + join(tok!) + " => " + map); } bool preCheck(DynamicObject o) { true; } bool matched() { ret map != null; } S getVar(S name) { ret getOrKeep(map, name); } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1023173 |
Snippet name: | WordTokRule |
Eternal ID of this version: | #1023173/23 |
Text MD5: | af680d66a7bd4ac1c41c0e2684d516ea |
Transpilation MD5: | 70ef83d2a316da7edf529193800f9c89 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-06-27 14:18:59 |
Source code size: | 1300 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 393 / 921 |
Version history: | 22 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |