mozilla / fathom

A framework for extracting meaning from web pages
http://mozilla.github.io/fathom/
Mozilla Public License 2.0
1.97k stars 76 forks source link

in Readability.mjs file deviationscore class call infinite times #83

Closed rajbaraiya123 closed 4 years ago

rajbaraiya123 commented 6 years ago

in readability.mjs file when i call anneal function , deviationScore class call infinite time. for compare two file i hardcode two sourcefile html and expected output html file.

function anneal() { const annealer = new ContentFnodesTuner(); coeffs = annealer.anneal(); }

class ContentFnodesTuner extends Annealer { constructor() { super(); // const docPairs = readabilityDocPairs(); this.solutionCost = coeffs => deviationScore(coeffs); /// deviationscore call infinite times

}

randomTransition(solution) {
    // Nudge a random coefficient in a random direction.
    const ret = solution.slice();
    let element, nudge;

    // Don't let weights go negative. Negative scores make overall
    // scores flip signs spastically. If you want fractional scores in
    // your ruleset, put 1 / coefficient in your ruleset.
    do {
        element = Math.floor(Math.random() * solution.length);
        nudge = Math.floor(Math.random() * 2) ? -.5 : .5;
    } while (ret[element] + nudge < 0);

    ret[element] += nudge;
    return ret;
}

initialSolution() {
    console.log("this is random init")
    return coeffs;
}

}

function deviationScore(coeffs) { var coeffs = [14.5, 11, 18, 5, 9.5, 21, 33, doc]; const stats = new DiffStats(tunedContentFnodes(coeffs)); return stats.score(); } class DiffStats {

constructor(contentFnodes, doc) {
    this.doc = doc
    this.lengthOfExpectedTexts = 0;
    this.lengthOfDiffs = 0;
    this.contentFnodes = contentFnodes || tunedContentFnodes();
}

compare(expectedDom, sourceDom) {
    expected = Hardcode expected dom in string ;
    source = Hardcode source dom in string;
    var expectedDom = parser.parseFromString(expected, "text/html");
    var sourceDom = parser.parseFromString(source, "text/html");
    const expectedText = collapseNewlines(trimLines(textContent(expectedDom)));
    const gotText = collapseNewlines(trimLines(tunedContentFnodes(14.5, 4, 2, 13.5, 11.5, 2, 12.5, 
    sourceDom2).map(fnode => fnode.element.textContent).join('\n')));
    console.log(gotText)
    this.lengthOfExpectedTexts += expectedText.length;
    this.lengthOfDiffs += leven(expectedText, gotText)
}
biancadanforth commented 4 years ago

Going to close this, as the Readability module and tests were removed in #151 .