1.0.2 • Published 3 years ago

node-rank-fns v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

node-rank-fns

A native node addon with implementations of ranking functions.

Install

  • npm i node-rank-fns

Examples

1. TF-IDF (Wiki)

Input files: documents.txt terms.txt

    const NodeRankFns = require('node-rank-fns');
    const assert = require('assert');
    const rankFns = new NodeRankFns();

    rankFns.tfIdf('./documents.txt', './terms.txt', (err, res) => {
        assert.deepEqual(res, [0, 0.12901285528456335]);
    });

Run example here

2. BM25 (Wiki)

Input files: documents.txt terms.txt

    const NodeRankFns = require('node-rank-fns');
    const assert = require('assert');
    const rankFns = new NodeRankFns();

    rankFns.bm25('./documents.txt', './terms.txt', (err, res) => {
        assert.deepEqual(res, [0, 0.07811157572119272]);
    });

    // Pass paramers k and b for BM25
    // k is used in BM25 to control the contribution of term frequency. (Term saturation) (Default: `1`)
    // As k increases the impact of a higher TF to the score would be lower.
    // b is used in BM25 to control the contribution of document length. (Must be between `0` and `1`). (Default: `1`)
    // as b increases towards `1` the impact of document length is increased. `0` means that document length is not taken into account.
    const rankFns = new NodeRankFns({k: 2, b: 0.5});
    rankFns.bm25('./documents.txt', './terms.txt', (err, res) => {
        assert.deepEqual(res, [0, 0.04487832504164857]);
    });

Run example here

Benchmarks

npm run benchmarks

ImplementationExecution time
vanillaJS*10005.063s
nativeAddon*1000767.641ms
vanillaJS*10005.069s
nativeAddon*1000738.792ms

Contributing

Pull requests are welcome.

TODO

  • Make functions with promises instead of callbacks.

Changelog

For complete changelog click here.

License

MIT License

Copyright (c) 2021 Dimitar Andreev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.