Download Jar. Libraryless. Click here for Pure Java version (18657L/133K).
!7 sS input = "plants grow"; p { ai_alternativeSmartBot(); WordSequence pat = WordSequence( SomethingWhichIs("a noun"), SomethingWhichIs("a verb")); printStruct(pat); WordSequence real = WordSequence("plants", "grow"); printStruct(real); new IdentityHashMap map; if (matchWordSequence(pat, real, map)) printStruct(map); else print("no match"); } static bool matchWordSequence(WordSequence pat, WordSequence real, Map map) { int n = l(pat.l); if (n != l(real.l)) false; for i to n: if (!matchElement(pat.l.get(i), real.l.get(i), map)) false; true; } static bool matchElement(O pat, O real, Map map) { if (eq(pat, real)) true; if (pat << SomethingWhichIs && real instanceof S) { if (!ai_is(quote((S) real), pat/SomethingWhichIs.type)) false; print("Assigning " + pat + " => " + real); ret strictPut(map, pat, real); } false; }
Began life as a copy of #1012746
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1012747 |
Snippet name: | Playing with patterns [OK] |
Eternal ID of this version: | #1012747/13 |
Text MD5: | 0f76bdd2304d7375770c02d81170e491 |
Transpilation MD5: | 8289052eb9909d989e2a2c33b641d844 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-12-11 19:38:30 |
Source code size: | 941 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 558 / 1260 |
Version history: | 12 change(s) |
Referenced in: | #1012755 - Playing with patterns v2 [OK] |