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

51
LINES

< > BotCompany Repo | #1017398 // ai_parseTree_makeWeights

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (11798L/84K).

1  
scope ai_parseTree_makeWeights.
2  
3  
sbool #verbose;
4  
static int #maxLevelSeen;
5  
6  
svoid ai_parseTree_makeWeights(AI_BottomUpParser1 parser, L<WeightedProduction> productions, final PTElement e) {
7  
  ai_parseTree_makeWeights(parser, productions, e, 1);
8  
}
9  
10  
svoid ai_parseTree_makeWeights(AI_BottomUpParser1 parser, L<WeightedProduction> productions, final PTElement e, int level) {
11  
  ping();
12  
  
13  
  if (level >= parser.maxDepth) {
14  
    if (!parser.maxDepthReached) {
15  
      parser.maxDepthReached = true;
16  
      print("Max parse tree level reached: " + parser.maxDepth);
17  
      print("Path from root:");
18  
      pnl(ptElement_pathFromRoot(e));
19  
    }
20  
    e.children = ll();
21  
    ret;
22  
  }
23  
    
24  
  if (verbose && level > maxLevelSeen)
25  
    print("ai_parseTree_makeWeights new max level seen: " + (maxLevelSeen = level));
26  
  
27  
  // Descend first
28  
  for (PTElement child : ai_parseTree_getChildren(parser, productions, e))
29  
    ai_parseTree_makeWeights(parser, productions, child, level+1);
30  
    
31  
  // Then calculate this node's weight
32  
  
33  
  // check for explicit anti-examples
34  
  if (e instanceof HaveCategory && contains(ai_antiWordCategoriesWithElements().get(e/HaveCategory.category), e.text()))
35  
    ret with e.weight = 0.1;
36  
    
37  
  if (e instanceof ChoosePart)
38  
    e.weight = avg(first(e.children).weight, second(e.children).weight);
39  
  else if (e instanceof HaveCategory && empty(e.children))
40  
    e.weight = or(ai_getWordToCategoryWeight(e.text(), e/HaveCategory.category), 1.0);
41  
  else
42  
    e.weight = collectMaxDouble(e.children, 'weight);
43  
    
44  
  ai_Reconstructed r =
45  
    e instanceof ChoosePart ? e/ChoosePart.reconstruction
46  
    : e instanceof HaveCategory ? e/HaveCategory.reconstruction : null;
47  
  if (r != null)
48  
    e.weight *= r.production.weight;
49  
}
50  
51  
end scope

Author comment

Began life as a copy of #1017396

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017398
Snippet name: ai_parseTree_makeWeights
Eternal ID of this version: #1017398/29
Text MD5: 697b3c88217535421ec6cca58d1fa486
Transpilation MD5: a621d30fb6d5614a02bdfc94ce0a4478
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-10 20:20:26
Source code size: 1787 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 341 / 459
Version history: 28 change(s)
Referenced in: [show references]