Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
_.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;
nlp.LevenshteinDistance = function (s1, s2) {
return natural.LevenshteinDistance(s1, s2);
};
_.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];
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)
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;
}