tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GreedyContentRanker.mjs (880B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 const RANKED_SECTION = "top_stories_section";
      6 const FEATURE_PREFIX = "s_";
      7 
      8 export async function scoreItemInferred(item, interests, weights) {
      9  item.score = item.item_score;
     10  if (item.section === RANKED_SECTION) {
     11    const inferred_score = Object.keys(item.features)
     12      .filter(key => key.startsWith(FEATURE_PREFIX))
     13      .reduce((acc, key) => {
     14        const actualKey = key.slice(2);
     15        return acc + (interests[actualKey] || 0);
     16      }, 0);
     17    const score =
     18      (weights.local * inferred_score) / (weights.inferred_norm + 1e-6) +
     19      weights.server * (item.server_score ?? 0);
     20    item.score = score;
     21    item.item_score = score;
     22  }
     23 
     24  return item;
     25 }