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

37
LINES

< > BotCompany Repo | #1010470 // web_ifThen2 - with adding nodes [works]

JavaX fragment (include)

1  
static Web web_ifThen2(Web inputWeb, Web web) {
2  
  Web patternWeb, Map<WebNode> patternMap = unpair cloneWebWithMap(web);
3  
  web_dropRelationsStartingWith(patternWeb, "Then:");
4  
  
5  
  Collection<WebNode> adders = mapUsingMap(reversedMap(patternMap), web_singleNodes(patternWeb));
6  
  web_dropSingleNodes(patternWeb); // To remove things only linked through "then" relations
7  
8  
  Web thenWeb, Map<WebNode> thenMap = unpair cloneWebWithReverseMap(web);
9  
  web_unpackRelationsStartingWith(thenWeb, "Then:");
10  
  
11  
  Map<WebNode> match = web_matchAllPerms_partial(patternWeb, inputWeb);
12  
  
13  
  if (match != null) {
14  
    print("Have match. Adders: " + adders);
15  
    // Add new nodes first
16  
    
17  
    new HashMap<WebNode> adderMap;
18  
    for (WebNode n : adders) { // adders are in "web" space
19  
      WebNode inputNode;
20  
      WebNode thenNode = reverseLookup(thenMap, n);
21  
      web_setLabels(inputNode = inputWeb.newNode(), n.labels);
22  
      adderMap.put(thenNode, inputNode);
23  
    }
24  
    
25  
    // Then add relations from thenWeb
26  
    for (WebRelation rel : web_relationObjects(thenWeb)) {
27  
      WebNode a = or(mapGet(adderMap, rel.a), mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.a))));
28  
      WebNode b = or(mapGet(adderMap, rel.b), mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.b))));
29  
      if (a != null && b != null) {
30  
        WebRelation rel2 = inputWeb.getRelation(a, b);
31  
        web_addLabelsFromNodeToNode(rel, rel2);
32  
      }
33  
    }
34  
  }
35  
  
36  
  ret inputWeb;
37  
}

Author comment

Began life as a copy of #1010463

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: #1010470
Snippet name: web_ifThen2 - with adding nodes [works]
Eternal ID of this version: #1010470/7
Text MD5: b326a03040c7d80084dbae9afdba6f2c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-22 17:47:49
Source code size: 1483 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 332 / 359
Version history: 6 change(s)
Referenced in: [show references]