[READ-ONLY] Mirror of https://github.com/FoxxMD/string-sameness. Compare the sameness of two strings foxxmd.github.io/string-sameness/
compare cosine-similarity dice-coefficient levenshtein-distance sameness string text typescript
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: BREAKING remove versioned dist

Will only distribute in npm package

FoxxMD (Feb 15, 2024, 10:43 AM EST) 76096fbf b85f1813

-890
-64
dist/commonjs/atomic.d.ts
··· 1 - export interface StringComparisonOptions { 2 - /** 3 - * An array of transformations to apply to each string before comparing similarity 4 - * */ 5 - transforms?: StringTransformFunc[]; 6 - /** 7 - * An array of strategies used to score similarity. All strategies scores are combined for an average high score. 8 - * */ 9 - strategies?: ComparisonStrategy<ComparisonStrategyResultValue>[]; 10 - /** 11 - * Reorder second string so its token match order of first string as closely as possible 12 - * 13 - * Useful when only the differences in content are important, but not the order of the content 14 - * */ 15 - reorder?: boolean; 16 - /** 17 - * When `reorder` is used this determines how to split each string into the tokens that will be reordered. 18 - * 19 - * The value of this property is used in String.split() -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#separator 20 - * 21 - * @default " " 22 - * */ 23 - delimiter?: string | RegExp; 24 - } 25 - export interface StringSamenessResult { 26 - strategies: { 27 - [key: string]: ComparisonStrategyResult; 28 - }; 29 - highScore: number; 30 - highScoreWeighted: number; 31 - } 32 - export interface ComparisonStrategyResultObject { 33 - /** 34 - * The normalized (0 to 100) score of this comparison 35 - * */ 36 - score: number; 37 - /** 38 - * The raw value returned by the comparison (not normalized) 39 - * */ 40 - rawScore?: number; 41 - [key: string]: any; 42 - } 43 - export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { 44 - } 45 - export interface NamedComparisonStrategyObjectResult extends ComparisonStrategyResultObject { 46 - name: string; 47 - } 48 - export type ComparisonStrategyResultValue = number | ComparisonStrategyResultObject; 49 - export type StrategyFunc<T extends ComparisonStrategyResultValue> = (strA: string, strB: string) => T; 50 - export interface ComparisonStrategy<T extends ComparisonStrategyResultValue> { 51 - /** 52 - * The name of this strategy 53 - * */ 54 - name: string; 55 - /** 56 - * A function that accepts two string arguments and returns a number 57 - * */ 58 - strategy: StrategyFunc<T>; 59 - /** 60 - * An optional function that accepts two string arguments and returns whether this strategy should be used 61 - * */ 62 - isValid?: (strA: string, strB: string) => boolean; 63 - } 64 - export type StringTransformFunc = (str: string) => string;
-3
dist/commonjs/atomic.js
··· 1 - "use strict"; 2 - Object.defineProperty(exports, "__esModule", { value: true }); 3 - //# sourceMappingURL=atomic.js.map
-1
dist/commonjs/atomic.js.map
··· 1 - {"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":""}
-14
dist/commonjs/index.d.ts
··· 1 - import { ComparisonStrategyResult, StringComparisonOptions, StringSamenessResult, StringTransformFunc } from "./atomic.js"; 2 - import { strDefaultTransforms, transforms } from "./normalization/index.js"; 3 - declare const defaultStrategies: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>[]; 4 - declare const stringSameness: (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; 5 - export declare const reorderStr: (strA: string, strB: string, options?: StringComparisonOptions) => [string, string]; 6 - declare const createStringSameness: (defaults: StringComparisonOptions) => (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; 7 - declare const strategies: { 8 - diceStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 9 - levenStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 10 - cosineStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 11 - cosineStrategyAggressive: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 12 - }; 13 - declare const defaultStrCompareTransformFuncs: StringTransformFunc[]; 14 - export { StringSamenessResult, StringComparisonOptions, stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms, ComparisonStrategyResult, StringTransformFunc };
-133
dist/commonjs/index.js
··· 1 - "use strict"; 2 - Object.defineProperty(exports, "__esModule", { value: true }); 3 - exports.strDefaultTransforms = exports.defaultStrCompareTransformFuncs = exports.transforms = exports.strategies = exports.defaultStrategies = exports.createStringSameness = exports.stringSameness = exports.reorderStr = void 0; 4 - const index_js_1 = require("./matchingStrategies/index.js"); 5 - const index_js_2 = require("./normalization/index.js"); 6 - Object.defineProperty(exports, "strDefaultTransforms", { enumerable: true, get: function () { return index_js_2.strDefaultTransforms; } }); 7 - Object.defineProperty(exports, "transforms", { enumerable: true, get: function () { return index_js_2.transforms; } }); 8 - const sentenceLengthWeight = (length) => { 9 - // thanks jordan :') 10 - // constants are black magic 11 - return (Math.log(length) / 0.20) - 5; 12 - }; 13 - const defaultStrategies = [ 14 - index_js_1.diceStrategy, 15 - index_js_1.levenStrategy, 16 - index_js_1.cosineStrategy 17 - ]; 18 - exports.defaultStrategies = defaultStrategies; 19 - const stringSameness = (valA, valB, options) => { 20 - const { transforms = index_js_2.strDefaultTransforms, strategies = defaultStrategies, reorder = false, delimiter = ' ' } = options || {}; 21 - let cleanA = transforms.reduce((acc, curr) => curr(acc), valA); 22 - let cleanB = transforms.reduce((acc, curr) => curr(acc), valB); 23 - if (reorder) { 24 - // we want to ignore order of tokens as much as possible (user does not care about differences in word order, just absolute differences in characters overall) 25 - // so we will reorder the shorter of the two strings so its tokens match the order of tokens in the longer string as closely as possible 26 - // before we run strategies 27 - const [orderedX, orderedY] = (0, exports.reorderStr)(cleanA, cleanB); 28 - cleanA = orderedX; 29 - cleanB = orderedY; 30 - } 31 - const shortest = cleanA.length > cleanB.length ? cleanB : cleanA; 32 - const stratResults = []; 33 - for (const strat of strategies) { 34 - if (strat.isValid !== undefined && !strat.isValid(cleanA, cleanB)) { 35 - continue; 36 - } 37 - const res = strat.strategy(cleanA, cleanB); 38 - const resObj = typeof res === 'number' ? { score: res } : res; 39 - stratResults.push({ 40 - ...resObj, 41 - name: strat.name 42 - }); 43 - } 44 - // use shortest sentence for weight 45 - const weightScore = sentenceLengthWeight(shortest.length); 46 - // take average score 47 - const highScore = stratResults.reduce((acc, curr) => acc + curr.score, 0) / stratResults.length; 48 - // weight score can be a max of 15 49 - const highScoreWeighted = highScore + Math.min(weightScore, 15); 50 - const stratObj = stratResults.reduce((acc, curr) => { 51 - const { name, score, ...rest } = curr; 52 - acc[curr.name] = { 53 - ...rest, 54 - score, 55 - }; 56 - return acc; 57 - }, {}); 58 - return { 59 - strategies: stratObj, 60 - highScore, 61 - highScoreWeighted, 62 - }; 63 - }; 64 - exports.stringSameness = stringSameness; 65 - const reorderStr = (strA, strB, options) => { 66 - const { transforms = index_js_2.strDefaultTransforms, strategies = defaultStrategies, delimiter = ' ' } = options || {}; 67 - const cleanA = transforms.reduce((acc, curr) => curr(acc), strA); 68 - const cleanB = transforms.reduce((acc, curr) => curr(acc), strB); 69 - // split by "token" 70 - const eTokens = cleanA.split(delimiter); 71 - const cTokens = cleanB.split(delimiter); 72 - let longerTokens, shorterTokens; 73 - if (eTokens.length > cTokens.length) { 74 - longerTokens = eTokens; 75 - shorterTokens = cTokens; 76 - } 77 - else { 78 - longerTokens = cTokens; 79 - shorterTokens = eTokens; 80 - } 81 - // we will use longest string (token list) as the reducer and order the shorter list to match it 82 - // so we don't have to deal with undefined positions in the shorter list 83 - const orderedCandidateTokens = longerTokens.reduce((acc, curr) => { 84 - // if we've run out of tokens in the shorter list just return 85 - if (acc.remaining.length === 0) { 86 - return acc; 87 - } 88 - // on each iteration of tokens in the long list 89 - // we iterate through remaining tokens from the shorter list and find the token with the most sameness 90 - let highScore = 0; 91 - let highIndex = 0; 92 - let index = 0; 93 - for (const token of acc.remaining) { 94 - const result = stringSameness(curr, token, { strategies }); 95 - if (result.highScoreWeighted > highScore) { 96 - highScore = result.highScoreWeighted; 97 - highIndex = index; 98 - } 99 - index++; 100 - } 101 - // then remove the most same token from the remaining short list tokens 102 - const splicedRemaining = [...acc.remaining]; 103 - splicedRemaining.splice(highIndex, 1); 104 - return { 105 - // finally add the most same token to the ordered short list 106 - ordered: acc.ordered.concat(acc.remaining[highIndex]), 107 - // and return the remaining short list tokens 108 - remaining: splicedRemaining 109 - }; 110 - }, { 111 - // "ordered" is the result of ordering tokens in the shorter list to match longer token order 112 - ordered: [], 113 - // remaining is the initial shorter list 114 - remaining: shorterTokens 115 - }); 116 - return [longerTokens.join(' '), orderedCandidateTokens.ordered.join(' ')]; 117 - }; 118 - exports.reorderStr = reorderStr; 119 - const createStringSameness = (defaults) => { 120 - return (valA, valB, options = {}) => stringSameness(valA, valB, { ...defaults, ...options }); 121 - }; 122 - exports.createStringSameness = createStringSameness; 123 - const strategies = { 124 - diceStrategy: index_js_1.diceStrategy, 125 - levenStrategy: index_js_1.levenStrategy, 126 - cosineStrategy: index_js_1.cosineStrategy, 127 - cosineStrategyAggressive: index_js_1.cosineStrategyAggressive 128 - }; 129 - exports.strategies = strategies; 130 - // maintaining compatibility 131 - const defaultStrCompareTransformFuncs = index_js_2.strDefaultTransforms; 132 - exports.defaultStrCompareTransformFuncs = defaultStrCompareTransformFuncs; 133 - //# sourceMappingURL=index.js.map
-1
dist/commonjs/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAoH;AAQpH,uDAA0E;AAuKtE,qGAvKI,+BAAoB,OAuKJ;AAFpB,2FArK0B,qBAAU,OAqK1B;AAnKd,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC5C,oBAAoB;IACpB,4BAA4B;IAC5B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG;IACtB,uBAAY;IACZ,wBAAa;IACb,yBAAc;CACjB,CAAA;AAuJG,8CAAiB;AArJrB,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,OA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AG,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5C,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAEtC,OAAO;YACH,4DAA4D;YAC5D,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACrD,6CAA6C;YAC7C,SAAS,EAAE,gBAAgB;SAC9B,CAAC;IACN,CAAC,EAAE;QACC,6FAA6F;QAC7F,OAAO,EAAE,EAAE;QACX,wCAAwC;QACxC,SAAS,EAAE,aAAa;KAC3B,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAA;AArEY,QAAA,UAAU,cAqEtB;AAED,MAAM,oBAAoB,GAAG,CAAC,QAAiC,EAAE,EAAE;IAC/D,OAAO,CAAC,IAAY,EAAE,IAAY,EAAE,UAAmC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,EAAC,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAC,CAAC,CAAC;AACxI,CAAC,CAAA;AAgBG,oDAAoB;AAdxB,MAAM,UAAU,GAAG;IACf,YAAY,EAAZ,uBAAY;IACZ,aAAa,EAAb,wBAAa;IACb,cAAc,EAAd,yBAAc;IACd,wBAAwB,EAAxB,mCAAwB;CAC3B,CAAC;AAWE,gCAAU;AATd,4BAA4B;AAC5B,MAAM,+BAA+B,GAAG,+BAAoB,CAAC;AAUzD,0EAA+B"}
-14
dist/commonjs/matchingStrategies/cosineSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateCosineSimilarity: (strA: string, strB: string) => number; 3 - /** 4 - * Compares whole tokens (words) within a string independent of order 5 - * 6 - * This strategy is automatically disabled for strings with less than 4 words because it can lead to inaccurate scores due to not comparing characters IE it is not very useful for short sentences and comparing single words with typos 7 - * 8 - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one 9 - * */ 10 - export declare const cosineStrategy: ComparisonStrategy<ComparisonStrategyResultObject>; 11 - /** 12 - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings 13 - * */ 14 - export declare const cosineStrategyAggressive: ComparisonStrategy<ComparisonStrategyResultObject>;
-91
dist/commonjs/matchingStrategies/cosineSimilarity.js
··· 1 - "use strict"; 2 - // reproduced from https://github.com/sumn2u/string-comparison/blob/master/jscosine.js 3 - // https://sumn2u.medium.com/string-similarity-comparision-in-js-with-examples-4bae35f13968 4 - Object.defineProperty(exports, "__esModule", { value: true }); 5 - exports.cosineStrategyAggressive = exports.cosineStrategy = exports.calculateCosineSimilarity = void 0; 6 - function termFreqMap(str) { 7 - var words = str.split(' '); 8 - var termFreq = {}; 9 - words.forEach(function (w) { 10 - termFreq[w] = (termFreq[w] || 0) + 1; 11 - }); 12 - return termFreq; 13 - } 14 - function addKeysToDict(map, dict) { 15 - for (var key in map) { 16 - dict[key] = true; 17 - } 18 - } 19 - function termFreqMapToVector(map, dict) { 20 - var termFreqVector = []; 21 - for (var term in dict) { 22 - termFreqVector.push(map[term] || 0); 23 - } 24 - return termFreqVector; 25 - } 26 - function vecDotProduct(vecA, vecB) { 27 - var product = 0; 28 - for (var i = 0; i < vecA.length; i++) { 29 - product += vecA[i] * vecB[i]; 30 - } 31 - return product; 32 - } 33 - function vecMagnitude(vec) { 34 - var sum = 0; 35 - for (var i = 0; i < vec.length; i++) { 36 - sum += vec[i] * vec[i]; 37 - } 38 - return Math.sqrt(sum); 39 - } 40 - function cosineSimilarity(vecA, vecB) { 41 - return vecDotProduct(vecA, vecB) / (vecMagnitude(vecA) * vecMagnitude(vecB)); 42 - } 43 - const calculateCosineSimilarity = (strA, strB) => { 44 - var termFreqA = termFreqMap(strA); 45 - var termFreqB = termFreqMap(strB); 46 - var dict = {}; 47 - addKeysToDict(termFreqA, dict); 48 - addKeysToDict(termFreqB, dict); 49 - var termFreqVecA = termFreqMapToVector(termFreqA, dict); 50 - var termFreqVecB = termFreqMapToVector(termFreqB, dict); 51 - return cosineSimilarity(termFreqVecA, termFreqVecB); 52 - }; 53 - exports.calculateCosineSimilarity = calculateCosineSimilarity; 54 - const cosineBaseStrategy = { 55 - name: 'cosine', 56 - strategy: (valA, valB) => { 57 - let res = (0, exports.calculateCosineSimilarity)(valA, valB); 58 - if (res > 0.99999) { 59 - res = 1; 60 - } 61 - return { 62 - score: res * 100, 63 - rawScore: res 64 - }; 65 - } 66 - }; 67 - /** 68 - * Compares whole tokens (words) within a string independent of order 69 - * 70 - * This strategy is automatically disabled for strings with less than 4 words because it can lead to inaccurate scores due to not comparing characters IE it is not very useful for short sentences and comparing single words with typos 71 - * 72 - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one 73 - * */ 74 - exports.cosineStrategy = { 75 - ...cosineBaseStrategy, 76 - isValid: (valA, valB) => { 77 - // cosine only compares full tokens (words), rather than characters, in a string 78 - // which makes its score very inaccurate when comparing low token-count strings (short sentences and/or words with typos) 79 - // so disable its usage if there are less than 4 tokens 80 - const valATokenLength = valA.split(' ').length; 81 - const valBTokenLength = valB.split(' ').length; 82 - return valATokenLength < 4 || valBTokenLength < 4; 83 - } 84 - }; 85 - /** 86 - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings 87 - * */ 88 - exports.cosineStrategyAggressive = { 89 - ...cosineBaseStrategy 90 - }; 91 - //# sourceMappingURL=cosineSimilarity.js.map
-1
dist/commonjs/matchingStrategies/cosineSimilarity.js.map
··· 1 - {"version":3,"file":"cosineSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/cosineSimilarity.ts"],"names":[],"mappings":";AAAA,sFAAsF;AACtF,2FAA2F;;;AAa3F,SAAS,WAAW,CAAC,GAAW;IAC5B,IAAI,KAAK,GAAG,GAAG,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IAAY,EAAE,EAAE;QACpC,gFAAgF;QAChF,yHAAyH;QACzH,uDAAuD;QACvD,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC/C,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC/C,OAAO,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,CAAC,CAAC;IACtD,CAAC;CACJ,CAAA;AAED;;KAEK;AACQ,QAAA,wBAAwB,GAAuD;IACxF,GAAG,kBAAkB;CACxB,CAAA"}
-3
dist/commonjs/matchingStrategies/diceSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateDiceSimilarity: (valA: string, valB: string) => number; 3 - export declare const diceStrategy: ComparisonStrategy<ComparisonStrategyResultObject>;
-20
dist/commonjs/matchingStrategies/diceSimilarity.js
··· 1 - "use strict"; 2 - var __importDefault = (this && this.__importDefault) || function (mod) { 3 - return (mod && mod.__esModule) ? mod : { "default": mod }; 4 - }; 5 - Object.defineProperty(exports, "__esModule", { value: true }); 6 - exports.diceStrategy = exports.calculateDiceSimilarity = void 0; 7 - const string_similarity_1 = __importDefault(require("string-similarity")); 8 - const calculateDiceSimilarity = (valA, valB) => string_similarity_1.default.compareTwoStrings(valA, valB); 9 - exports.calculateDiceSimilarity = calculateDiceSimilarity; 10 - exports.diceStrategy = { 11 - name: 'dice', 12 - strategy: (valA, valB) => { 13 - const res = (0, exports.calculateDiceSimilarity)(valA, valB); 14 - return { 15 - score: res * 100, 16 - rawScore: res 17 - }; 18 - } 19 - }; 20 - //# sourceMappingURL=diceSimilarity.js.map
-1
dist/commonjs/matchingStrategies/diceSimilarity.js.map
··· 1 - {"version":3,"file":"diceSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/diceSimilarity.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAiD;AAG1C,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE,CAAC,2BAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAAzG,QAAA,uBAAuB,2BAAkF;AACzG,QAAA,YAAY,GAAuD;IAC5E,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;QACrC,MAAM,GAAG,GAAG,IAAA,+BAAuB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChD,OAAO;YACH,KAAK,EAAE,GAAG,GAAG,GAAG;YAChB,QAAQ,EAAE,GAAG;SAChB,CAAA;IACL,CAAC;CACJ,CAAA"}
-5
dist/commonjs/matchingStrategies/index.d.ts
··· 1 - import { levenStrategy } from "./levenSimilarity.js"; 2 - import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; 3 - import { diceStrategy } from "./diceSimilarity.js"; 4 - import { ComparisonStrategy, ComparisonStrategyResultValue, ComparisonStrategyResultObject, StrategyFunc } from '../atomic.js'; 5 - export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy, ComparisonStrategy, ComparisonStrategyResultObject, ComparisonStrategyResultValue, StrategyFunc };
-11
dist/commonjs/matchingStrategies/index.js
··· 1 - "use strict"; 2 - Object.defineProperty(exports, "__esModule", { value: true }); 3 - exports.diceStrategy = exports.cosineStrategyAggressive = exports.cosineStrategy = exports.levenStrategy = void 0; 4 - const levenSimilarity_js_1 = require("./levenSimilarity.js"); 5 - Object.defineProperty(exports, "levenStrategy", { enumerable: true, get: function () { return levenSimilarity_js_1.levenStrategy; } }); 6 - const cosineSimilarity_js_1 = require("./cosineSimilarity.js"); 7 - Object.defineProperty(exports, "cosineStrategy", { enumerable: true, get: function () { return cosineSimilarity_js_1.cosineStrategy; } }); 8 - Object.defineProperty(exports, "cosineStrategyAggressive", { enumerable: true, get: function () { return cosineSimilarity_js_1.cosineStrategyAggressive; } }); 9 - const diceSimilarity_js_1 = require("./diceSimilarity.js"); 10 - Object.defineProperty(exports, "diceStrategy", { enumerable: true, get: function () { return diceSimilarity_js_1.diceStrategy; } }); 11 - //# sourceMappingURL=index.js.map
-1
dist/commonjs/matchingStrategies/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/matchingStrategies/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmD;AAM/C,8FANI,kCAAa,OAMJ;AALjB,+DAA+E;AAM3E,+FANI,oCAAc,OAMJ;AACd,yGAPoB,8CAAwB,OAOpB;AAN5B,2DAAiD;AAO7C,6FAPI,gCAAY,OAOJ"}
-3
dist/commonjs/matchingStrategies/levenSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateLevenSimilarity: (valA: string, valB: string) => number[]; 3 - export declare const levenStrategy: ComparisonStrategy<ComparisonStrategyResultObject>;
-40
dist/commonjs/matchingStrategies/levenSimilarity.js
··· 1 - "use strict"; 2 - var __importDefault = (this && this.__importDefault) || function (mod) { 3 - return (mod && mod.__esModule) ? mod : { "default": mod }; 4 - }; 5 - Object.defineProperty(exports, "__esModule", { value: true }); 6 - exports.levenStrategy = exports.calculateLevenSimilarity = void 0; 7 - const leven_1 = __importDefault(require("leven")); 8 - const calculateLevenSimilarity = (valA, valB) => { 9 - let longer; 10 - let shorter; 11 - if (valA.length > valB.length) { 12 - longer = valA; 13 - shorter = valB; 14 - } 15 - else { 16 - longer = valB; 17 - shorter = valA; 18 - } 19 - const distance = (0, leven_1.default)(longer, shorter); 20 - // use the shorter length 21 - // because if we have more move/change operations than the length of the shortest string than we have two unique strings 22 - // and if we use the longer length the score actually gets *better* as the length gap gets larger (not what we want) 23 - // -- cap at 100% diff 24 - const diff = Math.min((distance / shorter.length) * 100, 100); 25 - return [distance, 100 - diff]; 26 - }; 27 - exports.calculateLevenSimilarity = calculateLevenSimilarity; 28 - const stratFunc = (valA, valB) => { 29 - const res = (0, exports.calculateLevenSimilarity)(valA, valB); 30 - return { 31 - rawScore: res[0], 32 - distance: res[0], 33 - score: res[1] 34 - }; 35 - }; 36 - exports.levenStrategy = { 37 - name: 'leven', 38 - strategy: stratFunc 39 - }; 40 - //# sourceMappingURL=levenSimilarity.js.map
-1
dist/commonjs/matchingStrategies/levenSimilarity.js.map
··· 1 - {"version":3,"file":"levenSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/levenSimilarity.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAGnB,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,MAAc,CAAC;IACnB,IAAI,OAAe,CAAC;IACpB,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;QAC3B,MAAM,GAAG,IAAI,CAAC;QACd,OAAO,GAAG,IAAI,CAAC;KAClB;SAAM;QACH,MAAM,GAAG,IAAI,CAAC;QACd,OAAO,GAAG,IAAI,CAAC;KAClB;IAED,MAAM,QAAQ,GAAG,IAAA,eAAK,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,yBAAyB;IACzB,wHAAwH;IACxH,oHAAoH;IACpH,sBAAsB;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC,CAAA;AAlBY,QAAA,wBAAwB,4BAkBpC;AAED,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;IAC7C,MAAM,GAAG,GAAG,IAAA,gCAAwB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO;QACH,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAChB,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAChB,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;KAChB,CAAC;AACN,CAAC,CAAA;AAEY,QAAA,aAAa,GAAuD;IAC7E,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,SAAS;CACtB,CAAA"}
-18
dist/commonjs/normalization/index.d.ts
··· 1 - import { StringTransformFunc } from "../atomic.js"; 2 - declare const lowercase: StringTransformFunc; 3 - declare const trim: StringTransformFunc; 4 - declare const replaceUnicode: StringTransformFunc; 5 - declare const removePunctuation: StringTransformFunc; 6 - declare const removeNonAlphanumeric: StringTransformFunc; 7 - declare const removeWhitespace: StringTransformFunc; 8 - declare const replaceMultiWhitespace: StringTransformFunc; 9 - declare const transforms: { 10 - lowercase: StringTransformFunc; 11 - trim: StringTransformFunc; 12 - replaceMultiWhitespace: StringTransformFunc; 13 - replaceUnicode: StringTransformFunc; 14 - removeWhitespace: StringTransformFunc; 15 - removePunctuation: StringTransformFunc; 16 - }; 17 - declare const strDefaultTransforms: StringTransformFunc[]; 18 - export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms };
-39
dist/commonjs/normalization/index.js
··· 1 - "use strict"; 2 - Object.defineProperty(exports, "__esModule", { value: true }); 3 - exports.strDefaultTransforms = exports.transforms = exports.replaceMultiWhitespace = exports.removeNonAlphanumeric = exports.removeWhitespace = exports.removePunctuation = exports.replaceUnicode = exports.trim = exports.lowercase = void 0; 4 - const PUNCTUATION_REGEX = new RegExp(/[`=(){}<>;',.~!@#$%^&*_+|:"?\-\\\[\]\/]/g); 5 - const NON_ALPHANUMERIC_REGEX = new RegExp(/[^\w\s]|_/g); 6 - const WHITESPACE_REGEX = new RegExp(/\s/g); 7 - const MULTI_WHITESPACE_REGEX = new RegExp(/\s{2,}/g); 8 - const lowercase = (str) => str.toLocaleLowerCase(); 9 - exports.lowercase = lowercase; 10 - const trim = (str) => str.trim(); 11 - exports.trim = trim; 12 - const replaceUnicode = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); 13 - exports.replaceUnicode = replaceUnicode; 14 - const removePunctuation = (str) => str.replace(PUNCTUATION_REGEX, ''); 15 - exports.removePunctuation = removePunctuation; 16 - const removeNonAlphanumeric = (str) => str.replace(NON_ALPHANUMERIC_REGEX, ''); 17 - exports.removeNonAlphanumeric = removeNonAlphanumeric; 18 - const removeWhitespace = (str) => str.replace(WHITESPACE_REGEX, ''); 19 - exports.removeWhitespace = removeWhitespace; 20 - const replaceMultiWhitespace = (str) => str.replace(MULTI_WHITESPACE_REGEX, ' '); 21 - exports.replaceMultiWhitespace = replaceMultiWhitespace; 22 - const transforms = { 23 - lowercase, 24 - trim, 25 - replaceMultiWhitespace, 26 - replaceUnicode, 27 - removeWhitespace, 28 - removePunctuation 29 - }; 30 - exports.transforms = transforms; 31 - const strDefaultTransforms = [ 32 - replaceUnicode, 33 - removePunctuation, 34 - trim, 35 - replaceMultiWhitespace, 36 - lowercase 37 - ]; 38 - exports.strDefaultTransforms = strDefaultTransforms; 39 - //# sourceMappingURL=index.js.map
-1
dist/commonjs/normalization/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/normalization/index.ts"],"names":[],"mappings":";;;AAEA,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,0CAA0C,CAAC,CAAC;AACjF,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3C,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AAErD,MAAM,SAAS,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;AA0B5E,8BAAS;AAzBb,MAAM,IAAI,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AA0B1D,oBAAI;AAzBR,MAAM,cAAc,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AA0B9G,wCAAc;AAzBlB,MAAM,iBAAiB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AA0B/F,8CAAiB;AAzBrB,MAAM,qBAAqB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;AA2BxG,sDAAqB;AA1BzB,MAAM,gBAAgB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAyB7F,4CAAgB;AAxBpB,MAAM,sBAAsB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;AA0B1G,wDAAsB;AAxB1B,MAAM,UAAU,GAAG;IACf,SAAS;IACT,IAAI;IACJ,sBAAsB;IACtB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;CACpB,CAAA;AAkBG,gCAAU;AAhBd,MAAM,oBAAoB,GAA0B;IAChD,cAAc;IACd,iBAAiB;IACjB,IAAI;IACJ,sBAAsB;IACtB,SAAS;CACZ,CAAC;AAWE,oDAAoB"}
-3
dist/commonjs/package.json
··· 1 - { 2 - "type": "commonjs" 3 - }
-64
dist/esm/atomic.d.ts
··· 1 - export interface StringComparisonOptions { 2 - /** 3 - * An array of transformations to apply to each string before comparing similarity 4 - * */ 5 - transforms?: StringTransformFunc[]; 6 - /** 7 - * An array of strategies used to score similarity. All strategies scores are combined for an average high score. 8 - * */ 9 - strategies?: ComparisonStrategy<ComparisonStrategyResultValue>[]; 10 - /** 11 - * Reorder second string so its token match order of first string as closely as possible 12 - * 13 - * Useful when only the differences in content are important, but not the order of the content 14 - * */ 15 - reorder?: boolean; 16 - /** 17 - * When `reorder` is used this determines how to split each string into the tokens that will be reordered. 18 - * 19 - * The value of this property is used in String.split() -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#separator 20 - * 21 - * @default " " 22 - * */ 23 - delimiter?: string | RegExp; 24 - } 25 - export interface StringSamenessResult { 26 - strategies: { 27 - [key: string]: ComparisonStrategyResult; 28 - }; 29 - highScore: number; 30 - highScoreWeighted: number; 31 - } 32 - export interface ComparisonStrategyResultObject { 33 - /** 34 - * The normalized (0 to 100) score of this comparison 35 - * */ 36 - score: number; 37 - /** 38 - * The raw value returned by the comparison (not normalized) 39 - * */ 40 - rawScore?: number; 41 - [key: string]: any; 42 - } 43 - export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { 44 - } 45 - export interface NamedComparisonStrategyObjectResult extends ComparisonStrategyResultObject { 46 - name: string; 47 - } 48 - export type ComparisonStrategyResultValue = number | ComparisonStrategyResultObject; 49 - export type StrategyFunc<T extends ComparisonStrategyResultValue> = (strA: string, strB: string) => T; 50 - export interface ComparisonStrategy<T extends ComparisonStrategyResultValue> { 51 - /** 52 - * The name of this strategy 53 - * */ 54 - name: string; 55 - /** 56 - * A function that accepts two string arguments and returns a number 57 - * */ 58 - strategy: StrategyFunc<T>; 59 - /** 60 - * An optional function that accepts two string arguments and returns whether this strategy should be used 61 - * */ 62 - isValid?: (strA: string, strB: string) => boolean; 63 - } 64 - export type StringTransformFunc = (str: string) => string;
-2
dist/esm/atomic.js
··· 1 - export {}; 2 - //# sourceMappingURL=atomic.js.map
-1
dist/esm/atomic.js.map
··· 1 - {"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":""}
-14
dist/esm/index.d.ts
··· 1 - import { ComparisonStrategyResult, StringComparisonOptions, StringSamenessResult, StringTransformFunc } from "./atomic.js"; 2 - import { strDefaultTransforms, transforms } from "./normalization/index.js"; 3 - declare const defaultStrategies: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>[]; 4 - declare const stringSameness: (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; 5 - export declare const reorderStr: (strA: string, strB: string, options?: StringComparisonOptions) => [string, string]; 6 - declare const createStringSameness: (defaults: StringComparisonOptions) => (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; 7 - declare const strategies: { 8 - diceStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 9 - levenStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 10 - cosineStrategy: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 11 - cosineStrategyAggressive: import("./atomic.js").ComparisonStrategy<import("./atomic.js").ComparisonStrategyResultObject>; 12 - }; 13 - declare const defaultStrCompareTransformFuncs: StringTransformFunc[]; 14 - export { StringSamenessResult, StringComparisonOptions, stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms, ComparisonStrategyResult, StringTransformFunc };
-123
dist/esm/index.js
··· 1 - import { cosineStrategy, levenStrategy, diceStrategy, cosineStrategyAggressive } from "./matchingStrategies/index.js"; 2 - import { strDefaultTransforms, transforms } from "./normalization/index.js"; 3 - const sentenceLengthWeight = (length) => { 4 - // thanks jordan :') 5 - // constants are black magic 6 - return (Math.log(length) / 0.20) - 5; 7 - }; 8 - const defaultStrategies = [ 9 - diceStrategy, 10 - levenStrategy, 11 - cosineStrategy 12 - ]; 13 - const stringSameness = (valA, valB, options) => { 14 - const { transforms = strDefaultTransforms, strategies = defaultStrategies, reorder = false, delimiter = ' ' } = options || {}; 15 - let cleanA = transforms.reduce((acc, curr) => curr(acc), valA); 16 - let cleanB = transforms.reduce((acc, curr) => curr(acc), valB); 17 - if (reorder) { 18 - // we want to ignore order of tokens as much as possible (user does not care about differences in word order, just absolute differences in characters overall) 19 - // so we will reorder the shorter of the two strings so its tokens match the order of tokens in the longer string as closely as possible 20 - // before we run strategies 21 - const [orderedX, orderedY] = reorderStr(cleanA, cleanB); 22 - cleanA = orderedX; 23 - cleanB = orderedY; 24 - } 25 - const shortest = cleanA.length > cleanB.length ? cleanB : cleanA; 26 - const stratResults = []; 27 - for (const strat of strategies) { 28 - if (strat.isValid !== undefined && !strat.isValid(cleanA, cleanB)) { 29 - continue; 30 - } 31 - const res = strat.strategy(cleanA, cleanB); 32 - const resObj = typeof res === 'number' ? { score: res } : res; 33 - stratResults.push({ 34 - ...resObj, 35 - name: strat.name 36 - }); 37 - } 38 - // use shortest sentence for weight 39 - const weightScore = sentenceLengthWeight(shortest.length); 40 - // take average score 41 - const highScore = stratResults.reduce((acc, curr) => acc + curr.score, 0) / stratResults.length; 42 - // weight score can be a max of 15 43 - const highScoreWeighted = highScore + Math.min(weightScore, 15); 44 - const stratObj = stratResults.reduce((acc, curr) => { 45 - const { name, score, ...rest } = curr; 46 - acc[curr.name] = { 47 - ...rest, 48 - score, 49 - }; 50 - return acc; 51 - }, {}); 52 - return { 53 - strategies: stratObj, 54 - highScore, 55 - highScoreWeighted, 56 - }; 57 - }; 58 - export const reorderStr = (strA, strB, options) => { 59 - const { transforms = strDefaultTransforms, strategies = defaultStrategies, delimiter = ' ' } = options || {}; 60 - const cleanA = transforms.reduce((acc, curr) => curr(acc), strA); 61 - const cleanB = transforms.reduce((acc, curr) => curr(acc), strB); 62 - // split by "token" 63 - const eTokens = cleanA.split(delimiter); 64 - const cTokens = cleanB.split(delimiter); 65 - let longerTokens, shorterTokens; 66 - if (eTokens.length > cTokens.length) { 67 - longerTokens = eTokens; 68 - shorterTokens = cTokens; 69 - } 70 - else { 71 - longerTokens = cTokens; 72 - shorterTokens = eTokens; 73 - } 74 - // we will use longest string (token list) as the reducer and order the shorter list to match it 75 - // so we don't have to deal with undefined positions in the shorter list 76 - const orderedCandidateTokens = longerTokens.reduce((acc, curr) => { 77 - // if we've run out of tokens in the shorter list just return 78 - if (acc.remaining.length === 0) { 79 - return acc; 80 - } 81 - // on each iteration of tokens in the long list 82 - // we iterate through remaining tokens from the shorter list and find the token with the most sameness 83 - let highScore = 0; 84 - let highIndex = 0; 85 - let index = 0; 86 - for (const token of acc.remaining) { 87 - const result = stringSameness(curr, token, { strategies }); 88 - if (result.highScoreWeighted > highScore) { 89 - highScore = result.highScoreWeighted; 90 - highIndex = index; 91 - } 92 - index++; 93 - } 94 - // then remove the most same token from the remaining short list tokens 95 - const splicedRemaining = [...acc.remaining]; 96 - splicedRemaining.splice(highIndex, 1); 97 - return { 98 - // finally add the most same token to the ordered short list 99 - ordered: acc.ordered.concat(acc.remaining[highIndex]), 100 - // and return the remaining short list tokens 101 - remaining: splicedRemaining 102 - }; 103 - }, { 104 - // "ordered" is the result of ordering tokens in the shorter list to match longer token order 105 - ordered: [], 106 - // remaining is the initial shorter list 107 - remaining: shorterTokens 108 - }); 109 - return [longerTokens.join(' '), orderedCandidateTokens.ordered.join(' ')]; 110 - }; 111 - const createStringSameness = (defaults) => { 112 - return (valA, valB, options = {}) => stringSameness(valA, valB, { ...defaults, ...options }); 113 - }; 114 - const strategies = { 115 - diceStrategy, 116 - levenStrategy, 117 - cosineStrategy, 118 - cosineStrategyAggressive 119 - }; 120 - // maintaining compatibility 121 - const defaultStrCompareTransformFuncs = strDefaultTransforms; 122 - export { stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms }; 123 - //# sourceMappingURL=index.js.map
-1
dist/esm/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,wBAAwB,EAAC,MAAM,+BAA+B,CAAC;AAQpH,OAAO,EAAC,oBAAoB,EAAE,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAE1E,MAAM,oBAAoB,GAAG,CAAC,MAA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,UAAU,EACV,UAAU,EACV,+BAA+B,EAC/B,oBAAoB,EAGvB,CAAA"}
-14
dist/esm/matchingStrategies/cosineSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateCosineSimilarity: (strA: string, strB: string) => number; 3 - /** 4 - * Compares whole tokens (words) within a string independent of order 5 - * 6 - * This strategy is automatically disabled for strings with less than 4 words because it can lead to inaccurate scores due to not comparing characters IE it is not very useful for short sentences and comparing single words with typos 7 - * 8 - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one 9 - * */ 10 - export declare const cosineStrategy: ComparisonStrategy<ComparisonStrategyResultObject>; 11 - /** 12 - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings 13 - * */ 14 - export declare const cosineStrategyAggressive: ComparisonStrategy<ComparisonStrategyResultObject>;
-87
dist/esm/matchingStrategies/cosineSimilarity.js
··· 1 - // reproduced from https://github.com/sumn2u/string-comparison/blob/master/jscosine.js 2 - // https://sumn2u.medium.com/string-similarity-comparision-in-js-with-examples-4bae35f13968 3 - function termFreqMap(str) { 4 - var words = str.split(' '); 5 - var termFreq = {}; 6 - words.forEach(function (w) { 7 - termFreq[w] = (termFreq[w] || 0) + 1; 8 - }); 9 - return termFreq; 10 - } 11 - function addKeysToDict(map, dict) { 12 - for (var key in map) { 13 - dict[key] = true; 14 - } 15 - } 16 - function termFreqMapToVector(map, dict) { 17 - var termFreqVector = []; 18 - for (var term in dict) { 19 - termFreqVector.push(map[term] || 0); 20 - } 21 - return termFreqVector; 22 - } 23 - function vecDotProduct(vecA, vecB) { 24 - var product = 0; 25 - for (var i = 0; i < vecA.length; i++) { 26 - product += vecA[i] * vecB[i]; 27 - } 28 - return product; 29 - } 30 - function vecMagnitude(vec) { 31 - var sum = 0; 32 - for (var i = 0; i < vec.length; i++) { 33 - sum += vec[i] * vec[i]; 34 - } 35 - return Math.sqrt(sum); 36 - } 37 - function cosineSimilarity(vecA, vecB) { 38 - return vecDotProduct(vecA, vecB) / (vecMagnitude(vecA) * vecMagnitude(vecB)); 39 - } 40 - export const calculateCosineSimilarity = (strA, strB) => { 41 - var termFreqA = termFreqMap(strA); 42 - var termFreqB = termFreqMap(strB); 43 - var dict = {}; 44 - addKeysToDict(termFreqA, dict); 45 - addKeysToDict(termFreqB, dict); 46 - var termFreqVecA = termFreqMapToVector(termFreqA, dict); 47 - var termFreqVecB = termFreqMapToVector(termFreqB, dict); 48 - return cosineSimilarity(termFreqVecA, termFreqVecB); 49 - }; 50 - const cosineBaseStrategy = { 51 - name: 'cosine', 52 - strategy: (valA, valB) => { 53 - let res = calculateCosineSimilarity(valA, valB); 54 - if (res > 0.99999) { 55 - res = 1; 56 - } 57 - return { 58 - score: res * 100, 59 - rawScore: res 60 - }; 61 - } 62 - }; 63 - /** 64 - * Compares whole tokens (words) within a string independent of order 65 - * 66 - * This strategy is automatically disabled for strings with less than 4 words because it can lead to inaccurate scores due to not comparing characters IE it is not very useful for short sentences and comparing single words with typos 67 - * 68 - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one 69 - * */ 70 - export const cosineStrategy = { 71 - ...cosineBaseStrategy, 72 - isValid: (valA, valB) => { 73 - // cosine only compares full tokens (words), rather than characters, in a string 74 - // which makes its score very inaccurate when comparing low token-count strings (short sentences and/or words with typos) 75 - // so disable its usage if there are less than 4 tokens 76 - const valATokenLength = valA.split(' ').length; 77 - const valBTokenLength = valB.split(' ').length; 78 - return valATokenLength < 4 || valBTokenLength < 4; 79 - } 80 - }; 81 - /** 82 - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings 83 - * */ 84 - export const cosineStrategyAggressive = { 85 - ...cosineBaseStrategy 86 - }; 87 - //# sourceMappingURL=cosineSimilarity.js.map
-1
dist/esm/matchingStrategies/cosineSimilarity.js.map
··· 1 - {"version":3,"file":"cosineSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/cosineSimilarity.ts"],"names":[],"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,CAAC,MAAM,cAAc,GAAuD;IAC9E,GAAG,kBAAkB;IACrB,OAAO,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;QACpC,gFAAgF;QAChF,yHAAyH;QACzH,uDAAuD;QACvD,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC/C,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC/C,OAAO,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,CAAC,CAAC;IACtD,CAAC;CACJ,CAAA;AAED;;KAEK;AACL,MAAM,CAAC,MAAM,wBAAwB,GAAuD;IACxF,GAAG,kBAAkB;CACxB,CAAA"}
-3
dist/esm/matchingStrategies/diceSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateDiceSimilarity: (valA: string, valB: string) => number; 3 - export declare const diceStrategy: ComparisonStrategy<ComparisonStrategyResultObject>;
-13
dist/esm/matchingStrategies/diceSimilarity.js
··· 1 - import stringSimilarity from 'string-similarity'; 2 - export const calculateDiceSimilarity = (valA, valB) => stringSimilarity.compareTwoStrings(valA, valB); 3 - export const diceStrategy = { 4 - name: 'dice', 5 - strategy: (valA, valB) => { 6 - const res = calculateDiceSimilarity(valA, valB); 7 - return { 8 - score: res * 100, 9 - rawScore: res 10 - }; 11 - } 12 - }; 13 - //# sourceMappingURL=diceSimilarity.js.map
-1
dist/esm/matchingStrategies/diceSimilarity.js.map
··· 1 - {"version":3,"file":"diceSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/diceSimilarity.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtH,MAAM,CAAC,MAAM,YAAY,GAAuD;IAC5E,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;QACrC,MAAM,GAAG,GAAG,uBAAuB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChD,OAAO;YACH,KAAK,EAAE,GAAG,GAAG,GAAG;YAChB,QAAQ,EAAE,GAAG;SAChB,CAAA;IACL,CAAC;CACJ,CAAA"}
-5
dist/esm/matchingStrategies/index.d.ts
··· 1 - import { levenStrategy } from "./levenSimilarity.js"; 2 - import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; 3 - import { diceStrategy } from "./diceSimilarity.js"; 4 - import { ComparisonStrategy, ComparisonStrategyResultValue, ComparisonStrategyResultObject, StrategyFunc } from '../atomic.js'; 5 - export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy, ComparisonStrategy, ComparisonStrategyResultObject, ComparisonStrategyResultValue, StrategyFunc };
-5
dist/esm/matchingStrategies/index.js
··· 1 - import { levenStrategy } from "./levenSimilarity.js"; 2 - import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; 3 - import { diceStrategy } from "./diceSimilarity.js"; 4 - export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy }; 5 - //# sourceMappingURL=index.js.map
-1
dist/esm/matchingStrategies/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/matchingStrategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,cAAc,EAAE,wBAAwB,EAAC,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EACH,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,YAAY,EAKf,CAAA"}
-3
dist/esm/matchingStrategies/levenSimilarity.d.ts
··· 1 - import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; 2 - export declare const calculateLevenSimilarity: (valA: string, valB: string) => number[]; 3 - export declare const levenStrategy: ComparisonStrategy<ComparisonStrategyResultObject>;
-33
dist/esm/matchingStrategies/levenSimilarity.js
··· 1 - import leven from "leven"; 2 - export const calculateLevenSimilarity = (valA, valB) => { 3 - let longer; 4 - let shorter; 5 - if (valA.length > valB.length) { 6 - longer = valA; 7 - shorter = valB; 8 - } 9 - else { 10 - longer = valB; 11 - shorter = valA; 12 - } 13 - const distance = leven(longer, shorter); 14 - // use the shorter length 15 - // because if we have more move/change operations than the length of the shortest string than we have two unique strings 16 - // and if we use the longer length the score actually gets *better* as the length gap gets larger (not what we want) 17 - // -- cap at 100% diff 18 - const diff = Math.min((distance / shorter.length) * 100, 100); 19 - return [distance, 100 - diff]; 20 - }; 21 - const stratFunc = (valA, valB) => { 22 - const res = calculateLevenSimilarity(valA, valB); 23 - return { 24 - rawScore: res[0], 25 - distance: res[0], 26 - score: res[1] 27 - }; 28 - }; 29 - export const levenStrategy = { 30 - name: 'leven', 31 - strategy: stratFunc 32 - }; 33 - //# sourceMappingURL=levenSimilarity.js.map
-1
dist/esm/matchingStrategies/levenSimilarity.js.map
··· 1 - {"version":3,"file":"levenSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/levenSimilarity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,MAAc,CAAC;IACnB,IAAI,OAAe,CAAC;IACpB,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;QAC3B,MAAM,GAAG,IAAI,CAAC;QACd,OAAO,GAAG,IAAI,CAAC;KAClB;SAAM;QACH,MAAM,GAAG,IAAI,CAAC;QACd,OAAO,GAAG,IAAI,CAAC;KAClB;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,yBAAyB;IACzB,wHAAwH;IACxH,oHAAoH;IACpH,sBAAsB;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;IAC7C,MAAM,GAAG,GAAG,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO;QACH,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAChB,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAChB,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;KAChB,CAAC;AACN,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAuD;IAC7E,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,SAAS;CACtB,CAAA"}
-18
dist/esm/normalization/index.d.ts
··· 1 - import { StringTransformFunc } from "../atomic.js"; 2 - declare const lowercase: StringTransformFunc; 3 - declare const trim: StringTransformFunc; 4 - declare const replaceUnicode: StringTransformFunc; 5 - declare const removePunctuation: StringTransformFunc; 6 - declare const removeNonAlphanumeric: StringTransformFunc; 7 - declare const removeWhitespace: StringTransformFunc; 8 - declare const replaceMultiWhitespace: StringTransformFunc; 9 - declare const transforms: { 10 - lowercase: StringTransformFunc; 11 - trim: StringTransformFunc; 12 - replaceMultiWhitespace: StringTransformFunc; 13 - replaceUnicode: StringTransformFunc; 14 - removeWhitespace: StringTransformFunc; 15 - removePunctuation: StringTransformFunc; 16 - }; 17 - declare const strDefaultTransforms: StringTransformFunc[]; 18 - export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms };
-28
dist/esm/normalization/index.js
··· 1 - const PUNCTUATION_REGEX = new RegExp(/[`=(){}<>;',.~!@#$%^&*_+|:"?\-\\\[\]\/]/g); 2 - const NON_ALPHANUMERIC_REGEX = new RegExp(/[^\w\s]|_/g); 3 - const WHITESPACE_REGEX = new RegExp(/\s/g); 4 - const MULTI_WHITESPACE_REGEX = new RegExp(/\s{2,}/g); 5 - const lowercase = (str) => str.toLocaleLowerCase(); 6 - const trim = (str) => str.trim(); 7 - const replaceUnicode = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); 8 - const removePunctuation = (str) => str.replace(PUNCTUATION_REGEX, ''); 9 - const removeNonAlphanumeric = (str) => str.replace(NON_ALPHANUMERIC_REGEX, ''); 10 - const removeWhitespace = (str) => str.replace(WHITESPACE_REGEX, ''); 11 - const replaceMultiWhitespace = (str) => str.replace(MULTI_WHITESPACE_REGEX, ' '); 12 - const transforms = { 13 - lowercase, 14 - trim, 15 - replaceMultiWhitespace, 16 - replaceUnicode, 17 - removeWhitespace, 18 - removePunctuation 19 - }; 20 - const strDefaultTransforms = [ 21 - replaceUnicode, 22 - removePunctuation, 23 - trim, 24 - replaceMultiWhitespace, 25 - lowercase 26 - ]; 27 - export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms }; 28 - //# sourceMappingURL=index.js.map
-1
dist/esm/normalization/index.js.map
··· 1 - {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/normalization/index.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,0CAA0C,CAAC,CAAC;AACjF,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3C,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,SAA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