Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var params = {
text: 'How\'s it going?'
, from: 'en'
, to: 'ru'
};
// Don't worry about access token, it will be auto-generated if needed.
client.translate(params, function(err, data) {
console.log(data);
console.log(err);
});
*/
var natural = require('natural');
console.log(natural.DiceCoefficient("i want","want"))
// console.log(natural.JaroWinklerDistance('not', 'same'));
// console.log(natural.DiceCoefficient('thing', 'thing'));
nlp.DiceCoefficient = function (s1, s2) {
return natural.DiceCoefficient(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];
var distance = function (X,Y)
{
if ((X.length == 0) || (Y.length == 0))
return 0
return natural.DiceCoefficient(X.join(" "),Y.join(" "))
}
_.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;