How to use the natural.LevenshteinDistance function in natural

To help you get started, we’ve selected a few natural examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwilliamson / node-license-sniffer / lib / index.js View on Github external
var distances = licenseTexts.map(function(license) {
        return {
            distance: natural.LevenshteinDistance(license.text, text) / Math.max(license.text.length, text.length),
            license: license
        };
    });
    var closest = _.min(distances, function(distance) {
github alfonsogoberjr / knearest / adapters / memory.js View on Github external
_.forEach(this.features, (prop, name) => {
                  let delta = 0;
                  if (node.features[name] && _node.features[name] && (typeof node.features[name] === 'number') && (typeof _node.features[name] === 'number') && (this.features[name].range !== 0)) {
                    let difference = 0;
                    if (_node.features[name] > node.features[name]) difference = _node.features[name] - node.features[name];
                    if (node.features[name] > _node.features[name]) difference = node.features[name] - _node.features[name];
                    delta = difference / (prop.max - prop.min);
                    let feature = Math.sqrt(delta * delta);
                    features.push(feature);
                  }
                  else if (node.features[name] && _node.features[name] && (typeof node.features[name] === 'string') && (typeof _node.features[name] === 'string') && (this.features[name].range !== 0)) {
                    if (this.stringAlgorithm === 'Jaro-Winkler') delta = natural.JaroWinklerDistance(node.features[name], _node.features[name]);
                    if (this.stringAlgorithm === 'Levenshtein') delta = natural.LevenshteinDistance(node.features[name], _node.features[name]);
                    if (this.stringAlgorithm === 'Dice') delta = natural.DiceCoefficient(node.features[name], _node.features[name]);
                    let feature = Math.sqrt(delta * delta);
                    features.push(feature);
                  }
                });
                arc.distance = features.length > 1 ? features.reduce((x, y) => x + y) : 0;
github bishop-ai / bishop-ai / nlp / index.js View on Github external
nlp.LevenshteinDistance = function (s1, s2) {
    return natural.LevenshteinDistance(s1, s2);
};
github alfonsogoberjr / knearest / adapters / mongo.js View on Github external
_.forEach(this.features, (prop, name) => {
                      let delta = 0;
                      if (node.features[name] && _node.features[name] && (typeof node.features[name] === 'number') && (typeof _node.features[name] === 'number') && (this.features[name].range !== 0)) {
                        let difference = 0;
                        if (_node.features[name] > node.features[name]) difference = _node.features[name] - node.features[name]
                        else if (node.features[name] > _node.features[name]) difference = node.features[name] - _node.features[name]
                        delta = difference / (prop.max - prop.min);
                        let feature = Math.sqrt(delta * delta);
                        features.push(feature);
                      }
                      else if (node.features[name] && _node.features[name] && (typeof node.features[name] === 'string') && (typeof _node.features[name] === 'string') && (this.features[name].range !== 0)) {
                        if (this.stringAlgorithm === 'Jaro-Winkler') delta = natural.JaroWinklerDistance(node.features[name], _node.features[name]);
                        if (this.stringAlgorithm === 'Levenshtein') delta = natural.LevenshteinDistance(node.features[name], _node.features[name]);
                        if (this.stringAlgorithm === 'Dice') delta = natural.DiceCoefficient(node.features[name], _node.features[name]);
                        let feature = Math.sqrt(delta * delta);
                        features.push(feature);
                      }
                    });
                    arc.distance = features.length > 1 ? features.reduce((x, y) => x + y) : features[0];
github dadi / api / dadi / lib / model / search.js View on Github external
const weight = Object.keys(fields).reduce((weight, field) => {
      if (!document[field]) return weight

      const {distance} = natural.LevenshteinDistance(query, document[field], {
        search: true
      })
      const distanceFactor = 1 / (distance + 1)

      return weight + indexWeight * distanceFactor
    }, 0)
github spion / triplie-ng / lib / pipeline / levenshtein.js View on Github external
self.similar = function leven_similar(w1, w2) {
        if (w1.id == w2.id)
            return true;
        var s1 = w1, s2 = w2;
        return s1.length >= 6 && s2.length >= 6
            && 2 * leven(s1, s2) / (s1.length + s2.length)
                < (opt.percent || 30) / 100;
    }

natural

General natural language (tokenizing, stemming (English, Russian, Spanish), part-of-speech tagging, sentiment analysis, classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.

MIT
Latest version published 1 month ago

Package Health Score

98 / 100
Full package analysis