Libraryless. Click here for Pure Java version (672L/5K/16K).
!747 !multi-line strings m { !include #1001509 // rules & statements static Map<S, L<S>> synMap = new TreeMap<S, L<S>>(); p { statements.add("one is a synonym of 1."); statements.add("\"eins\" is a synonym of 1."); statements.add("two is a synonym of 2."); makeSynMap(); ask([[what are the synonyms of 1?]]); ask([[what are the synonyms of 2?]]); } static void makeSynMap() { for (Map<S, S> m : matchStatements("$1 is a synonym of $2")) addSynonym(unquote(m.get("$1")), unquote(m.get("$2"))); } static void addSynonym(S a, S b) { L<S> la = synMap.get(a), lb = synMap.get(b); if (la == null && lb == null) { L<S> l = litlist(a, b); synMap.put(a, l); synMap.put(b, l); } else if (la == lb) { // nothing to do, they're already synonyms } else if (lb == null) { la.add(b); synMap.put(b, la); } else if (la == null) { lb.add(a); synMap.put(a, lb); } else mergeLists(la, lb); } static void mergeLists(L<S> la, L<S> lb) { for (S b : lb) { la.add(b); synMap.put(b, la); } } static void ask(S q) { print("? " + q); new Map<S, S> map; if (match4("what are the synonyms of $1?", q, map)) print(" => " + structure(getSynonyms(map.get("$1")))); else print("dunno."); } static L<S> getSynonyms(S x) { ret synMap.get(x); } }
Began life as a copy of #1001510
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001511 |
Snippet name: | Synonyms |
Eternal ID of this version: | #1001511/1 |
Text MD5: | b29e91e132d84cff796f507f94ca5efa |
Transpilation MD5: | 206380f267bc3c70c077ddd68cc91e54 |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-21 16:31:35 |
Source code size: | 1501 bytes / 63 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 554 / 615 |
Referenced in: | #1001512 - Synonyms (class) #1001513 - Synonyms (with include) #1001514 - Mental nodes (developing) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |