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)

static Web web_ifThen2(Web inputWeb, Web web) {
  Web patternWeb, Map<WebNode> patternMap = unpair cloneWebWithMap(web);
  web_dropRelationsStartingWith(patternWeb, "Then:");
  
  Collection<WebNode> adders = mapUsingMap(reversedMap(patternMap), web_singleNodes(patternWeb));
  web_dropSingleNodes(patternWeb); // To remove things only linked through "then" relations

  Web thenWeb, Map<WebNode> thenMap = unpair cloneWebWithReverseMap(web);
  web_unpackRelationsStartingWith(thenWeb, "Then:");
  
  Map<WebNode> match = web_matchAllPerms_partial(patternWeb, inputWeb);
  
  if (match != null) {
    print("Have match. Adders: " + adders);
    // Add new nodes first
    
    new HashMap<WebNode> adderMap;
    for (WebNode n : adders) { // adders are in "web" space
      WebNode inputNode;
      WebNode thenNode = reverseLookup(thenMap, n);
      web_setLabels(inputNode = inputWeb.newNode(), n.labels);
      adderMap.put(thenNode, inputNode);
    }
    
    // Then add relations from thenWeb
    for (WebRelation rel : web_relationObjects(thenWeb)) {
      WebNode a = or(mapGet(adderMap, rel.a), mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.a))));
      WebNode b = or(mapGet(adderMap, rel.b), mapGet(match, mapGet(patternMap, mapGet(thenMap, rel.b))));
      if (a != null && b != null) {
        WebRelation rel2 = inputWeb.getRelation(a, b);
        web_addLabelsFromNodeToNode(rel, rel2);
      }
    }
  }
  
  ret inputWeb;
}

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: 441 / 449
Version history: 6 change(s)
Referenced in: [show references]