svoid ai_parseTree_makeWeights(AI_BottomUpParser1 parser, L productions, final Element e) { // Descend first for (Element child : ai_parseTree_getChildren(parser, productions, e)) ai_parseTree_makeWeights(parser, productions, child); // Then calculate this node's weight if (e instanceof ChoosePart) e.weight = avg(collectMaxDouble(e.children, 'weight)); else if (e instanceof HaveCategory && empty(e.children)) e.weight = 1.0; // TODO 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; }