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

30
LINES

< > BotCompany Repo | #1010802 // web_matchNodeLists_x - returns match score (0 or negative); with node matcher

JavaX fragment (include)

1  
static bool web_matchNodeLists_x_debug;
2  
3  
// nodeMatcher: func(WebNode, WebNode) -> double
4  
static int web_matchNodeLists_x(L<WebNode> l1, L<WebNode> l2, O nodeMatcher) {
5  
  if (l(l1) != l(l2)) ret -1000;
6  
  int score = 0;
7  
  if (empty(l1)) ret score;
8  
  HashMap<WebNode> map = twoListsToHashMap(l1, l2);
9  
  Web web = first(l1).web, web2 = first(l2).web;
10  
  
11  
  // Score nodes
12  
  for i over l1: {
13  
    WebNode a = l1.get(i), b = l2.get(i);
14  
    score += toDouble(callF(nodeMatcher, a, b));
15  
  }
16  
  
17  
  // Score relations
18  
  for (WebRelation rel : web_relationObjects(web)) {
19  
    WebNode aa = map.get(rel.a), bb = map.get(rel.b);
20  
    if (aa == null || bb == null) continue;
21  
    WebRelation rel2 = web2.getRelationOpt(aa, bb);
22  
    if (web_matchNodeLists_x_debug)
23  
      print("a=" + rel.a + ", b=" + rel.b + ", aa=" + aa + ", bb=" + bb + ", rel2 labels=" + (rel2 == null ? "-" : str(rel2.labels)) + ", labels=" + rel.labels);
24  
    //if (rel2 == null || !containsAll(rel2.labels, rel.labels))
25  
    //  --score;
26  
    if (rel2 == null) --score;
27  
    else score += toDouble(callF(nodeMatcher, rel, rel2));
28  
  }
29  
  ret score;
30  
}

Author comment

Began life as a copy of #1010326

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: #1010802
Snippet name: web_matchNodeLists_x - returns match score (0 or negative); with node matcher
Eternal ID of this version: #1010802/3
Text MD5: fb2b87a77a408696460efc167e73aaf2
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-09 02:00:25
Source code size: 1126 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 349 / 392
Version history: 2 change(s)
Referenced in: [show references]