scope ai_parseTree_makeWeights. sbool #verbose; static int #maxLevelSeen; svoid ai_parseTree_makeWeights(AI_BottomUpParser1 parser, L productions, final PTElement e) { ai_parseTree_makeWeights(parser, productions, e, 1); } svoid ai_parseTree_makeWeights(AI_BottomUpParser1 parser, L productions, final PTElement e, int level) { ping(); if (level >= parser.maxDepth) { if (!parser.maxDepthReached) { parser.maxDepthReached = true; print("Max parse tree level reached: " + parser.maxDepth); print("Path from root:"); pnl(ptElement_pathFromRoot(e)); } e.children = ll(); ret; } if (verbose && level > maxLevelSeen) print("ai_parseTree_makeWeights new max level seen: " + (maxLevelSeen = level)); // Descend first for (PTElement child : ai_parseTree_getChildren(parser, productions, e)) ai_parseTree_makeWeights(parser, productions, child, level+1); // Then calculate this node's weight // check for explicit anti-examples if (e instanceof HaveCategory && contains(ai_antiWordCategoriesWithElements().get(e/HaveCategory.category), e.text())) ret with e.weight = 0.1; if (e instanceof ChoosePart) e.weight = avg(first(e.children).weight, second(e.children).weight); else if (e instanceof HaveCategory && empty(e.children)) e.weight = or(ai_getWordToCategoryWeight(e.text(), e/HaveCategory.category), 1.0); else e.weight = collectMaxDouble(e.children, 'weight); ai_Reconstructed r = e instanceof ChoosePart ? e/ChoosePart.reconstruction : e instanceof HaveCategory ? e/HaveCategory.reconstruction : null; if (r != null) e.weight *= r.production.weight; } end scope