You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mercury-parser/src/extractors/generic/content/scoring/get-or-init-score.js

29 lines
466 B
JavaScript

import {
getScore,
scoreNode,
getWeight,
addToParent,
} from './index';
// gets and returns the score if it exists
// if not, initializes a score based on
// the node's tag type
export default function getOrInitScore($node, $, weightNodes = true) {
let score = getScore($node);
if (score) {
return score;
}
score = scoreNode($node);
if (weightNodes) {
score += getWeight($node);
}
addToParent($node, $, score);
return score;
}