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

67
LINES

< > BotCompany Repo | #1010365 // If - Then with 3 nodes [OK]

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (15089L/108K).

1  
!7
2  
3  
sS inputDiagrams = [[
4  
  CirclesAndLines(circles=[Circle(text="A [Anything]", x=d("0.26"), y=d("0.2")), Circle(text="B [Anything]", x=d("0.52"), y=d("0.49")), Circle(text="C [Anything]", x=d("0.75"), y=d("0.19"))], lines=[Arrow(a=t5, b=t26, text="likes"), Arrow(a=t26, b=t47, text="likes"), Arrow(a=t47, b=t5, text="Then: likes")], title="Transitivity of liking")
5  
  CirclesAndLines(circles=[Circle(text="John", traits=[], x=d("0.28"), y=d("0.23")), Circle(text="Mary", traits=[], x=d("0.77"), y=d("0.23")), Circle(text="Peter", traits=[], x=d("0.52"), y=d("0.52"))], lines=[Arrow(a=t5, b=t31, text="likes", traits=[]), Arrow(a=t31, b=t57, text="likes", traits=[])], title="John")
6  
]];
7  
8  
static L<Web> webs;
9  
static Web inputWeb, resultWeb;
10  
static JTabbedPane tabs;
11  
12  
p-subst {
13  
  cal_lineLength(50);
14  
  webs = websFromCALStructures_vis(inputDiagrams);
15  
  inputWeb = last(webs);
16  
  
17  
  think();
18  
  
19  
  final CirclesAndLines cal = webToCAL_live_vis(inputWeb,
20  
    voidfunc(Web w) { inputWeb = w; think() });
21  
22  
  setFrameWidth(700, tabs = showTabbedWebs(
23  
    "Instruction", calAutoLayout2(webToCAL_live_vis(first(webs),
24  
      voidfunc(Web w) { webs.set(0, w); think() })),
25  
    "Input", /*inputWeb,*/ calAutoLayout2(cal),
26  
    "Result", resultWeb != null ? resultWeb : jlabel("Sorry")));
27  
    
28  
  think();
29  
}
30  
31  
svoid think { loading {
32  
  print("Thinking.");
33  
  
34  
  Web web = first(webs); // Instruction
35  
  
36  
  Web patternWeb, Map<WebNode> patternMap = unpair cloneWebWithMap(web);
37  
  web_dropRelationsStartingWith(patternWeb, "Then:");
38  
  
39  
  Web thenWeb, Map<WebNode> thenMap = unpair cloneWebWithReverseMap(web);
40  
  web_unpackRelationsStartingWith(thenWeb, "Then:");
41  
  
42  
  Map<WebNode> match = web_matchAllPerms(patternWeb, inputWeb);
43  
  
44  
  // Clone inputWeb to get resultWeb
45  
  Web resultWeb, Map<WebNode> resultMap = unpair cloneWebWithMap(inputWeb);
46  
  main.resultWeb = resultWeb;
47  
  
48  
  if (match != null) {
49  
    // Then add relations from thenWeb
50  
    for (WebRelation rel : web_relationObjects(thenWeb)) {
51  
      WebNode a = mapGet(resultMap, mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.a)));
52  
      WebNode b = mapGet(resultMap, mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.b)));
53  
      if (a != null && b != null) {
54  
        print("Adding labels " + rel.labels + " to: " + a + " - " + b);
55  
        WebRelation rel2 = resultWeb.getRelation(a, b);
56  
        web_addLabelsFromNodeToNode(rel, rel2);
57  
      }
58  
    }
59  
  }
60  
  
61  
  if (tabs != null) {
62  
    printWeb(resultWeb);
63  
    CirclesAndLines cal = webToCAL(resultWeb);
64  
    printBeautify(cal_structure(cal));
65  
    replaceTab(tabs, "Result", webToCALWithAutoLayout(resultWeb));
66  
  }
67  
}}

Author comment

Began life as a copy of #1010298

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: #1010365
Snippet name: If - Then with 3 nodes [OK]
Eternal ID of this version: #1010365/4
Text MD5: b7c717cfc05a50b129f78720b78871c2
Transpilation MD5: bf23ffc8fde361ca88ad4bc0899b19b9
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-09-18 02:15:32
Source code size: 2673 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 506 / 1123
Version history: 3 change(s)
Referenced in: [show references]