Download Jar. Uses 4597K of libraries. Click here for Pure Java version (22718L/168K).
!7 set flag WebWithRelationsMap. sS inputDiagrams = [[ CirclesAndLines(circles=[Circle(text="A [Anything]", x=d("0.32"), y=d("0.55")), Circle(text="B [Anything]", x=d("0.68"), y=d("0.55"))], lines=[Arrow(a=t5, b=t26, text="is"), Arrow(a=t26, b=t5, text="then: is?")], title="A B B A") CirclesAndLines(circles=[Circle(quickvis="Philosophy", text="Philosophy", x=d("0.27"), y=d("0.47")), Circle(quickvis="Asking questions", text="Asking questions", x=d("0.75"), y=d("0.47"))], lines=[Arrow(a=t5, b=t30, text="is")], title="Philosophy") ]]; sS linkWord = "always"; static L<Web> webs; static Web inputWeb, resultWeb; static S question; static JTabbedPane tabs; p-subst { cal_lineLength(50); webs = websFromCALStructures_vis(inputDiagrams); inputWeb = last(webs); think(); final CirclesAndLines cal = webToCAL_live_vis(inputWeb, voidfunc(Web w) { inputWeb = w; think() }); setFrameWidth(700, tabs = showTabbedWebs( "Instruction", calAutoLayout2(webToCAL_live_vis(first(webs), voidfunc(Web w) { webs.set(0, w); think() })), "Input", /*inputWeb,*/ calAutoLayout2(cal), "Result", resultWeb != null ? resultWeb : jlabel("Sorry"), "Computer's Question", second(jFullCenterTextPane(question)))); think(); } svoid think { loading { print("Thinking."); Web web = first(webs); // Instruction Web patternWeb, Map<WebNode> patternMap = unpair cloneWebWithMap(web); web_dropRelationsStartingWith(patternWeb, "Then:"); Web thenWeb, Map<WebNode> thenMap = unpair cloneWebWithMap(web); web_unpackRelationsStartingWith(thenWeb, "Then:"); Map<WebNode> match = web_matchAllPerms(patternWeb, inputWeb); // Clone inputWeb to get resultWeb Web resultWeb, Map<WebNode> resultMap = unpair cloneWebWithMap(inputWeb); main.resultWeb = resultWeb; if (match != null) { // Then add relations from thenWeb for (WebRelation rel : web_relationObjects(thenWeb)) { WebNode a = mapGet(resultMap, mapGet(match, mapGet(patternMap, reverseLookup(thenMap, rel.a))); WebNode b = mapGet(resultMap, mapGet(match, mapGet(patternMap, reverseLookup(thenMap, rel.b))); if (a != null && b != null) { print("Adding labels " + rel.labels + " to: " + a + " - " + b); WebRelation rel2 = resultWeb.getRelation(a, b); web_addLabelsFromNodeToNode(rel, rel2); } } } // Make question WebRelation rel = web_findDoubleRelation(resultWeb, "Is", "Is?"); question = "?"; if (rel != null) { S a = web_text(rel.a), b = web_text(rel.b); question = firstToUpper(a) + " may be " + firstToLower(b) + ".\n\n" + "But is " + firstToLower(b) + " " + addSpaceIfNempty(linkWord) + firstToLower(a) + "?"; } if (tabs != null) { printWeb(resultWeb); CirclesAndLines cal = webToCAL(resultWeb); printBeautify(cal_structure(cal)); replaceTab(tabs, "Result", webToCALWithAutoLayout(resultWeb)); replaceTab(tabs, "Computer's Question", second(jFullCenterTextPane(question))); } }}
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1010298 |
Snippet name: | If - Then [OK] |
Eternal ID of this version: | #1010298/76 |
Text MD5: | 8df5a4a3f2f1b2007c6521fda4b80519 |
Transpilation MD5: | f36d832d8b421416d0529ed3060cfbae |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-20 13:10:41 |
Source code size: | 3100 bytes / 84 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 836 / 2060 |
Version history: | 75 change(s) |
Referenced in: | #1010323 - Test full match (match all permutations of a web with another web) [OK] #1010365 - If - Then with 3 nodes [OK] |