* every node in candidates get a specified weight. * @param node the node element. * @param cans candidates array. * @param options options.
(node, cans, options)
| 546 | * @param options options. |
| 547 | */ |
| 548 | function getNodeWeight(node, cans, options){ |
| 549 | // Add the score to the parent. The grandparent gets half |
| 550 | var parent = node.parent(); |
| 551 | |
| 552 | // if parent not exists, break. |
| 553 | if (parent && parent.length == 0) { |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | var text = node.text().trim(); |
| 558 | |
| 559 | // if this paragraph is less than [minTextLength] characters, don't even count it. |
| 560 | if (text.length < options.minTextLength) { |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | var score = 1; |
| 565 | // add points for any commas within this paragraph. |
| 566 | var commas = text.match(regexps.commas); |
| 567 | if (commas && commas.length) { |
| 568 | score += commas.length; |
| 569 | } |
| 570 | // for every 100 characters in this paragraph, add another point. up to 3 points. |
| 571 | score += Math.min(Math.floor(text.length / 100), 3); |
| 572 | // add the score to the parent and the grandparent gets half. |
| 573 | scoreNode(parent, score, cans, options.scoreRule); |
| 574 | |
| 575 | var grandParent = parent.parent(); |
| 576 | if (grandParent && grandParent.length > 0) { |
| 577 | var dampedScore = score * (isFinite(options.damping) ? options.damping : (1 / 2)); |
| 578 | dampedScore = isFinite(dampedScore) ? dampedScore : 0; |
| 579 | scoreNode(grandParent, dampedScore, cans, options.scoreRule); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Add score to the node. |
no test coverage detected
searching dependent graphs…