_.chain(sentences) .map(function (sentence) { sentence['word_order_similarity'] = _.chain(sentences) .map(function (item) { return sim3(item['words'], sentence['words']) }) .reduce(function(total, n) { return total + n }) .value() return sentence }) .value()
/** * @param {} * @return {} * @api public */ var distance = function (vector) { var sum = _.chain(vector) .map(function (a) { return a*a }) .reduce(function(total, n) { return total + n }) .value() return mathjs.sqrt(sum) }
/** * Parse & merge multiple rank results from redis. * @param {array} ranks In this format: [['foo', '39', 'bar', '13'], ['foo', '11']] * @return {object} In this format: [{ foo: 50 }, { bar: 13 }] */ const createRankTotalParser = (direction, startingAt, limit) => ranks => { return _.chain(ranks) .flatten() .chunk(2) .reduce((acc, [key, count]) => _.tap(acc, acc => { acc[key] = (acc[key] || 0) + Number(count); }), { }) .toPairs() .sortBy(([, count]) => direction === 'asc' ? count : -count) .drop(startingAt) .takeWhile((value, index) => limit <= 0 || index < limit) .map(([key, count]) => ({ [key]: count })) .value(); }
var WordSemanticSimilarity = function (words1, words2) { var sum_wssim = _.chain(words1) .map(function (word1) { return wssim(word1, words2) }) .reduce(function(total, n) { return total + n }) .value() var sum_wssim2 = _.chain(words2) .map(function (word2) { return wssim(word2, words1) }) .reduce(function(total, n) { return total + n }) .value() sum_wssim = (sum_wssim) ? sum_wssim : 0 sum_wssim2 = (sum_wssim2) ? sum_wssim2 : 0 var result = (sum_wssim + sum_wssim2) / (words1.length + words2.length) result = ((words1.length + words2.length) == 0) ? 0 : result return result }
_.chain(sentences) .map(function (sentence) { sentence['word_semantic_similarity'] = _.chain(sentences) .map(function (item) { return sim2(item['words'], sentence['words']) }) .reduce(function(total, n) { return total + n }) .value() return sentence }) .value()
_.chain(sentences) .map(function (sentence) { sentence['word_form_similarity'] = _.chain(sentences) .map(function (item) { return sim1(item['words'], sentence['words']) }) .reduce(function(total, n) { return total + n }) .value() return sentence }) .value()