/** * Perform a traversal of the heap binary tree using recursion. Given a node, * visit its children and check if their spans is equivalent to the least * spans. If the spans is equivalent, it sums its score for the current node and recursively visit its * two children. */ private final float sumScoreInNode(final int root) throws IOException { float score = 0; final int i1 = (root << 1); // index of first child node final int i2 = i1 + 1; // index of second child node Spans top = this.top(); if (i1 <= this.size()) { final Spans child1 = (Spans) this.getHeapArray()[i1]; if (nodeEqual(top, child1)) { score += child1.scoreInNode(); score += this.sumScoreInNode(i1); } } if (i2 <= this.size()) { final Spans child2 = (Spans) this.getHeapArray()[i2]; if (nodeEqual(top, child2)) { score += child2.scoreInNode(); score += this.sumScoreInNode(i2); } } return score; }
public float scoreInNode() throws IOException { // Sum the score of spans, starting from the top, having the same document and node. // Add the score of the top. return this.sumScoreInNode(1) + this.top().scoreInNode(); }