1 | sclass WebNode { |
2 | new L<S> labels; |
3 | |
4 | void addLabel(S label) { |
5 | setAdd(labels, label); |
6 | } |
7 | |
8 | bool hasLabel(S label) { ret labels.contains(label); } |
9 | } |
10 | |
11 | sclass Web { |
12 | new L<WebNode> nodes; |
13 | Map<Pair<WebNode>, WebNode> relations = new HashMap; |
14 | |
15 | void relation(Lisp l) { |
16 | if (l(l) != 2) ret; |
17 | getRelation(l.s(0), l.s(1)).addLabel(l.head); |
18 | } |
19 | |
20 | WebNode getRelation(S a, S b) { |
21 | Pair<WebNode> p = pair(findNode(a), findNode(b)); |
22 | WebNode r = relations.get(p); |
23 | if (r == null) relations.put(p, r = new WebNode); |
24 | ret r; |
25 | } |
26 | |
27 | WebNode findNode(S s) { |
28 | for (WebNode n : nodes) |
29 | if (n.labels.contains(s)) |
30 | ret n; |
31 | ret newNode(s); |
32 | } |
33 | |
34 | WebNode newNode(S... labels) { |
35 | new WebNode n; |
36 | for (S label : labels) n.addLabel(label); |
37 | nodes.add(n); |
38 | ret n; |
39 | } |
40 | } |
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: | #1007660 |
Snippet name: | Web + WebNode |
Eternal ID of this version: | #1007660/1 |
Text MD5: | c961e37bbe4884de6d2fcafdaaf7af93 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-30 21:57:10 |
Source code size: | 855 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 616 / 862 |
Referenced in: | [show references] |