Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

84
LINES

< > BotCompany Repo | #1010298 // If - Then [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 4597K of libraries. Click here for Pure Java version (22718L/168K).

1  
!7
2  
3  
set flag WebWithRelationsMap.
4  
5  
sS inputDiagrams = [[
6  
  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")
7  
  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")
8  
]];
9  
10  
sS linkWord = "always";
11  
12  
static L<Web> webs;
13  
static Web inputWeb, resultWeb;
14  
static S question;
15  
static JTabbedPane tabs;
16  
17  
p-subst {
18  
  cal_lineLength(50);
19  
  webs = websFromCALStructures_vis(inputDiagrams);
20  
  inputWeb = last(webs);
21  
  
22  
  think();
23  
  
24  
  final CirclesAndLines cal = webToCAL_live_vis(inputWeb,
25  
    voidfunc(Web w) { inputWeb = w; think() });
26  
27  
  setFrameWidth(700, tabs = showTabbedWebs(
28  
    "Instruction", calAutoLayout2(webToCAL_live_vis(first(webs),
29  
      voidfunc(Web w) { webs.set(0, w); think() })),
30  
    "Input", /*inputWeb,*/ calAutoLayout2(cal),
31  
    "Result", resultWeb != null ? resultWeb : jlabel("Sorry"),
32  
    "Computer's Question", second(jFullCenterTextPane(question))));
33  
    
34  
  think();
35  
}
36  
37  
svoid think { loading {
38  
  print("Thinking.");
39  
  
40  
  Web web = first(webs); // Instruction
41  
  
42  
  Web patternWeb, Map<WebNode> patternMap = unpair cloneWebWithMap(web);
43  
  web_dropRelationsStartingWith(patternWeb, "Then:");
44  
  
45  
  Web thenWeb, Map<WebNode> thenMap = unpair cloneWebWithMap(web);
46  
  web_unpackRelationsStartingWith(thenWeb, "Then:");
47  
  
48  
  Map<WebNode> match = web_matchAllPerms(patternWeb, inputWeb);
49  
  
50  
  // Clone inputWeb to get resultWeb
51  
  Web resultWeb, Map<WebNode> resultMap = unpair cloneWebWithMap(inputWeb);
52  
  main.resultWeb = resultWeb;
53  
  
54  
  if (match != null) {
55  
    // Then add relations from thenWeb
56  
    for (WebRelation rel : web_relationObjects(thenWeb)) {
57  
      WebNode a = mapGet(resultMap, mapGet(match, mapGet(patternMap, reverseLookup(thenMap, rel.a)));
58  
      WebNode b = mapGet(resultMap, mapGet(match, mapGet(patternMap, reverseLookup(thenMap, rel.b)));
59  
      if (a != null && b != null) {
60  
        print("Adding labels " + rel.labels + " to: " + a + " - " + b);
61  
        WebRelation rel2 = resultWeb.getRelation(a, b);
62  
        web_addLabelsFromNodeToNode(rel, rel2);
63  
      }
64  
    }
65  
  }
66  
  
67  
  // Make question
68  
  
69  
  WebRelation rel = web_findDoubleRelation(resultWeb, "Is", "Is?");
70  
  question = "?";
71  
  if (rel != null) {
72  
    S a = web_text(rel.a), b = web_text(rel.b);
73  
    question = firstToUpper(a) + " may be " + firstToLower(b) + ".\n\n"
74  
      + "But is " + firstToLower(b) + " " + addSpaceIfNempty(linkWord) + firstToLower(a) + "?";
75  
  }
76  
  
77  
  if (tabs != null) {
78  
    printWeb(resultWeb);
79  
    CirclesAndLines cal = webToCAL(resultWeb);
80  
    printBeautify(cal_structure(cal));
81  
    replaceTab(tabs, "Result", webToCALWithAutoLayout(resultWeb));
82  
    replaceTab(tabs, "Computer's Question", second(jFullCenterTextPane(question)));
83  
  }
84  
}}

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: 837 / 2063
Version history: 75 change(s)
Referenced in: [show references]