mozilla/fathom

Error running the example.

ydennisy opened this issue · 2 comments

Hi,

I am just trying to play with the example given here, and the following error arises:

/Users/dennisy/dev/labs/fathom/node_modules/fathom-web/rule.js:56
        this.rhs = rhs.asRhs();
                       ^

TypeError: rhs.asRhs is not a function
    at new Rule (/Users/dennisy/dev/labs/fathom/node_modules/fathom-web/rule.js:56:24)
    at new InwardRule (/Users/dennisy/dev/labs/fathom/node_modules/fathom-web/rule.js:161:1)
    at rule (/Users/dennisy/dev/labs/fathom/node_modules/fathom-web/rule.js:39:12)
    at Object.<anonymous> (/Users/dennisy/dev/labs/fathom/index.js:29:3)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11

Node: v12.11.0
Fathom: v3.1.0

Hello, I'd love to help. Can you give more detail on how you ran the example?

Hey @danielhertenstein !

Yeah I just copied and pasted the example from your docs, to receive the above error.

const {rule, ruleset, dom, out, and, atMost, max, note, props, score, type, typeIn} = require('fathom-web');
const JSDOM = require('jsdom').JSDOM;  // jsdom v10 and up
const fetch = require('node-fetch');


const rules = ruleset([
  // Put all <title> tags in the bucket of candidate titles.
  rule(dom('title'), type('titley').score(1)),

  // Tag any OpenGraph meta tag as title-ish as well:
  rule(dom('meta[property="og:title"]'), type('titley').score(1)),

  // Take all title-ish candidates, and punish them to the degree they
  // contain navigational claptrap like colons or dashes. Compress the
  // number into the standard 0..1 range using a sigmoid function.
  rule(type('titley'), score(fnode => sigmoid(numberOfColonsOrDashes(fnode.element))), {name: 'colons'}),

  // Add a rule for title length, intuiting that very long titles may not
  // be titles at all. Again, limit the range to 0..1 using a sigmoid. The
  // resulting score means "the probability that the title is 'long'", for
  // some definition of "long" that the trainer will later determine by
  // adding a scaling coefficient.
  rule(type('titley'), score(fnode => sigmoid(fnode.element.innerText.length)), {name: 'length'}),

  // Offer the max-scoring title-ish node under the output key "title".
  // The score on that node will represent the probability, informed by a
  // corpus of training pages, that the node is, indeed, the proper page
  // title.
  rule(type('titley').max(), 'title')
],
[['colons', -0.3606211543083191], ['length', -1.6875461339950562]],  // coefficients from training
['titley', 3.660104751586914]  // biases from training
);