Download Jar. Libraryless. Click here for Pure Java version (6893L/49K).
!7 sclass Token { S text; CNC group; int index; toString { ret text; } } sclass CNC { S text; // if known new L<Token> tokens; } p-exp { S s = "There are 6 chess pieces. How many chess pieces do you know?"; CNC in1 = makeCNC("There are 6 chess pieces. How many chess pieces do you know?"); CNC out1 = makeCNC("6 I guess"); CNC in2 = makeCNC("There are 16 chess pieces. How many chess pieces do you know?"); LPair<Token> l = zipCNC(in1, in2); if (l == null) ret; l = antiFilter(l, func(Pair<Token> p) -> Bool { eqic(p.a.text, p.b.text) }); print("Remaining differences:"); pnl(l); SS daMap = pairsToMap(pairListMap(func(Token t) -> S { t.text }, l)); printStruct(daMap); S result = join(mapTokens_getOrKeep(collect(out1.tokens, 'text), daMap)); assertEqualsVerbose("16 I guess", result); } static CNC makeCNC(S s) { CNC cnc = nu(CNC, text := s); L<S> tok = javaTokWithAngleBrackets(s); for i over tok: cnc.tokens.add(nu(Token, text := tok.get(i), group := cnc, index := i); ret cnc; } // may return null (no match) static LPair<Token> zipCNC(CNC cnc1, CNC cnc2) { ret zipTwoListsToPairs_ifSameLength(cnc1.tokens, cnc2.tokens); } static LPair<Token> dropSame(LPair<Token> l) { ret antiFilter(l, func(Pair<Token> p) -> Bool { eqic(p.a.text, p.b.text) }); }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1017527 |
| Snippet name: | Intelligent Token Objects [OK] |
| Eternal ID of this version: | #1017527/9 |
| Text MD5: | 39fec17320383e523d62392635db1bfe |
| Transpilation MD5: | 21b57e91d0a91128e38569c6b28e1df2 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-07-26 10:26:09 |
| Source code size: | 1366 bytes / 48 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 675 / 1479 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |