Download Jar. Libraryless. Click here for Pure Java version (18657L/133K).
1 | !7 |
2 | |
3 | sS input = "plants grow"; |
4 | |
5 | p {
|
6 | ai_alternativeSmartBot(); |
7 | |
8 | WordSequence pat = WordSequence( |
9 | SomethingWhichIs("a noun"),
|
10 | SomethingWhichIs("a verb"));
|
11 | printStruct(pat); |
12 | |
13 | WordSequence real = WordSequence("plants", "grow");
|
14 | printStruct(real); |
15 | |
16 | new IdentityHashMap map; |
17 | if (matchWordSequence(pat, real, map)) |
18 | printStruct(map); |
19 | else |
20 | print("no match");
|
21 | } |
22 | |
23 | static bool matchWordSequence(WordSequence pat, WordSequence real, Map map) {
|
24 | int n = l(pat.l); |
25 | if (n != l(real.l)) false; |
26 | for i to n: |
27 | if (!matchElement(pat.l.get(i), real.l.get(i), map)) false; |
28 | true; |
29 | } |
30 | |
31 | static bool matchElement(O pat, O real, Map map) {
|
32 | if (eq(pat, real)) true; |
33 | if (pat << SomethingWhichIs && real instanceof S) {
|
34 | if (!ai_is(quote((S) real), pat/SomethingWhichIs.type)) false; |
35 | print("Assigning " + pat + " => " + real);
|
36 | ret strictPut(map, pat, real); |
37 | } |
38 | false; |
39 | } |
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: | 932 / 2005 |
| Version history: | 12 change(s) |
| Referenced in: | [show references] |