diff --git a/dist/commonjs/atomic.d.ts b/dist/commonjs/atomic.d.ts deleted file mode 100644 index e88c7e6..0000000 --- a/dist/commonjs/atomic.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -export interface StringComparisonOptions { - /** - * An array of transformations to apply to each string before comparing similarity - * */ - transforms?: StringTransformFunc[]; - /** - * An array of strategies used to score similarity. All strategies scores are combined for an average high score. - * */ - strategies?: ComparisonStrategy[]; - /** - * Reorder second string so its token match order of first string as closely as possible - * - * Useful when only the differences in content are important, but not the order of the content - * */ - reorder?: boolean; - /** - * When `reorder` is used this determines how to split each string into the tokens that will be reordered. - * - * 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 - * - * @default " " - * */ - delimiter?: string | RegExp; -} -export interface StringSamenessResult { - strategies: { - [key: string]: ComparisonStrategyResult; - }; - highScore: number; - highScoreWeighted: number; -} -export interface ComparisonStrategyResultObject { - /** - * The normalized (0 to 100) score of this comparison - * */ - score: number; - /** - * The raw value returned by the comparison (not normalized) - * */ - rawScore?: number; - [key: string]: any; -} -export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { -} -export interface NamedComparisonStrategyObjectResult extends ComparisonStrategyResultObject { - name: string; -} -export type ComparisonStrategyResultValue = number | ComparisonStrategyResultObject; -export type StrategyFunc = (strA: string, strB: string) => T; -export interface ComparisonStrategy { - /** - * The name of this strategy - * */ - name: string; - /** - * A function that accepts two string arguments and returns a number - * */ - strategy: StrategyFunc; - /** - * An optional function that accepts two string arguments and returns whether this strategy should be used - * */ - isValid?: (strA: string, strB: string) => boolean; -} -export type StringTransformFunc = (str: string) => string; diff --git a/dist/commonjs/atomic.js b/dist/commonjs/atomic.js deleted file mode 100644 index 25299c0..0000000 --- a/dist/commonjs/atomic.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=atomic.js.map \ No newline at end of file diff --git a/dist/commonjs/atomic.js.map b/dist/commonjs/atomic.js.map deleted file mode 100644 index d76053d..0000000 --- a/dist/commonjs/atomic.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/commonjs/index.d.ts b/dist/commonjs/index.d.ts deleted file mode 100644 index 7bf1740..0000000 --- a/dist/commonjs/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ComparisonStrategyResult, StringComparisonOptions, StringSamenessResult, StringTransformFunc } from "./atomic.js"; -import { strDefaultTransforms, transforms } from "./normalization/index.js"; -declare const defaultStrategies: import("./atomic.js").ComparisonStrategy[]; -declare const stringSameness: (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; -export declare const reorderStr: (strA: string, strB: string, options?: StringComparisonOptions) => [string, string]; -declare const createStringSameness: (defaults: StringComparisonOptions) => (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; -declare const strategies: { - diceStrategy: import("./atomic.js").ComparisonStrategy; - levenStrategy: import("./atomic.js").ComparisonStrategy; - cosineStrategy: import("./atomic.js").ComparisonStrategy; - cosineStrategyAggressive: import("./atomic.js").ComparisonStrategy; -}; -declare const defaultStrCompareTransformFuncs: StringTransformFunc[]; -export { StringSamenessResult, StringComparisonOptions, stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms, ComparisonStrategyResult, StringTransformFunc }; diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js deleted file mode 100644 index 3c0ba3d..0000000 --- a/dist/commonjs/index.js +++ /dev/null @@ -1,133 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.strDefaultTransforms = exports.defaultStrCompareTransformFuncs = exports.transforms = exports.strategies = exports.defaultStrategies = exports.createStringSameness = exports.stringSameness = exports.reorderStr = void 0; -const index_js_1 = require("./matchingStrategies/index.js"); -const index_js_2 = require("./normalization/index.js"); -Object.defineProperty(exports, "strDefaultTransforms", { enumerable: true, get: function () { return index_js_2.strDefaultTransforms; } }); -Object.defineProperty(exports, "transforms", { enumerable: true, get: function () { return index_js_2.transforms; } }); -const sentenceLengthWeight = (length) => { - // thanks jordan :') - // constants are black magic - return (Math.log(length) / 0.20) - 5; -}; -const defaultStrategies = [ - index_js_1.diceStrategy, - index_js_1.levenStrategy, - index_js_1.cosineStrategy -]; -exports.defaultStrategies = defaultStrategies; -const stringSameness = (valA, valB, options) => { - const { transforms = index_js_2.strDefaultTransforms, strategies = defaultStrategies, reorder = false, delimiter = ' ' } = options || {}; - let cleanA = transforms.reduce((acc, curr) => curr(acc), valA); - let cleanB = transforms.reduce((acc, curr) => curr(acc), valB); - if (reorder) { - // 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) - // 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 - // before we run strategies - const [orderedX, orderedY] = (0, exports.reorderStr)(cleanA, cleanB); - cleanA = orderedX; - cleanB = orderedY; - } - const shortest = cleanA.length > cleanB.length ? cleanB : cleanA; - const stratResults = []; - for (const strat of strategies) { - if (strat.isValid !== undefined && !strat.isValid(cleanA, cleanB)) { - continue; - } - const res = strat.strategy(cleanA, cleanB); - const resObj = typeof res === 'number' ? { score: res } : res; - stratResults.push({ - ...resObj, - name: strat.name - }); - } - // use shortest sentence for weight - const weightScore = sentenceLengthWeight(shortest.length); - // take average score - const highScore = stratResults.reduce((acc, curr) => acc + curr.score, 0) / stratResults.length; - // weight score can be a max of 15 - const highScoreWeighted = highScore + Math.min(weightScore, 15); - const stratObj = stratResults.reduce((acc, curr) => { - const { name, score, ...rest } = curr; - acc[curr.name] = { - ...rest, - score, - }; - return acc; - }, {}); - return { - strategies: stratObj, - highScore, - highScoreWeighted, - }; -}; -exports.stringSameness = stringSameness; -const reorderStr = (strA, strB, options) => { - const { transforms = index_js_2.strDefaultTransforms, strategies = defaultStrategies, delimiter = ' ' } = options || {}; - const cleanA = transforms.reduce((acc, curr) => curr(acc), strA); - const cleanB = transforms.reduce((acc, curr) => curr(acc), strB); - // split by "token" - const eTokens = cleanA.split(delimiter); - const cTokens = cleanB.split(delimiter); - let longerTokens, shorterTokens; - if (eTokens.length > cTokens.length) { - longerTokens = eTokens; - shorterTokens = cTokens; - } - else { - longerTokens = cTokens; - shorterTokens = eTokens; - } - // we will use longest string (token list) as the reducer and order the shorter list to match it - // so we don't have to deal with undefined positions in the shorter list - const orderedCandidateTokens = longerTokens.reduce((acc, curr) => { - // if we've run out of tokens in the shorter list just return - if (acc.remaining.length === 0) { - return acc; - } - // on each iteration of tokens in the long list - // we iterate through remaining tokens from the shorter list and find the token with the most sameness - let highScore = 0; - let highIndex = 0; - let index = 0; - for (const token of acc.remaining) { - const result = stringSameness(curr, token, { strategies }); - if (result.highScoreWeighted > highScore) { - highScore = result.highScoreWeighted; - highIndex = index; - } - index++; - } - // then remove the most same token from the remaining short list tokens - const splicedRemaining = [...acc.remaining]; - splicedRemaining.splice(highIndex, 1); - return { - // finally add the most same token to the ordered short list - ordered: acc.ordered.concat(acc.remaining[highIndex]), - // and return the remaining short list tokens - remaining: splicedRemaining - }; - }, { - // "ordered" is the result of ordering tokens in the shorter list to match longer token order - ordered: [], - // remaining is the initial shorter list - remaining: shorterTokens - }); - return [longerTokens.join(' '), orderedCandidateTokens.ordered.join(' ')]; -}; -exports.reorderStr = reorderStr; -const createStringSameness = (defaults) => { - return (valA, valB, options = {}) => stringSameness(valA, valB, { ...defaults, ...options }); -}; -exports.createStringSameness = createStringSameness; -const strategies = { - diceStrategy: index_js_1.diceStrategy, - levenStrategy: index_js_1.levenStrategy, - cosineStrategy: index_js_1.cosineStrategy, - cosineStrategyAggressive: index_js_1.cosineStrategyAggressive -}; -exports.strategies = strategies; -// maintaining compatibility -const defaultStrCompareTransformFuncs = index_js_2.strDefaultTransforms; -exports.defaultStrCompareTransformFuncs = defaultStrCompareTransformFuncs; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/commonjs/index.js.map b/dist/commonjs/index.js.map deleted file mode 100644 index ccd1a95..0000000 --- a/dist/commonjs/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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,OAAiC,EAAwB,EAAE;IAE3G,MAAM,EACF,UAAU,GAAG,+BAAoB,EACjC,UAAU,GAAG,iBAAiB,EAC9B,OAAO,GAAG,KAAK,EACf,SAAS,GAAG,GAAG,EAClB,GAAG,OAAO,IAAI,EAAE,CAAC;IAElB,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/D,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAE/D,IAAI,OAAO,EAAE;QACT,8JAA8J;QAC9J,wIAAwI;QACxI,2BAA2B;QAC3B,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,M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AAC,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"} \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/cosineSimilarity.d.ts b/dist/commonjs/matchingStrategies/cosineSimilarity.d.ts deleted file mode 100644 index 1a6679e..0000000 --- a/dist/commonjs/matchingStrategies/cosineSimilarity.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateCosineSimilarity: (strA: string, strB: string) => number; -/** - * Compares whole tokens (words) within a string independent of order - * - * 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 - * - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one - * */ -export declare const cosineStrategy: ComparisonStrategy; -/** - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings - * */ -export declare const cosineStrategyAggressive: ComparisonStrategy; diff --git a/dist/commonjs/matchingStrategies/cosineSimilarity.js b/dist/commonjs/matchingStrategies/cosineSimilarity.js deleted file mode 100644 index 2895abe..0000000 --- a/dist/commonjs/matchingStrategies/cosineSimilarity.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; -// reproduced from https://github.com/sumn2u/string-comparison/blob/master/jscosine.js -// https://sumn2u.medium.com/string-similarity-comparision-in-js-with-examples-4bae35f13968 -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cosineStrategyAggressive = exports.cosineStrategy = exports.calculateCosineSimilarity = void 0; -function termFreqMap(str) { - var words = str.split(' '); - var termFreq = {}; - words.forEach(function (w) { - termFreq[w] = (termFreq[w] || 0) + 1; - }); - return termFreq; -} -function addKeysToDict(map, dict) { - for (var key in map) { - dict[key] = true; - } -} -function termFreqMapToVector(map, dict) { - var termFreqVector = []; - for (var term in dict) { - termFreqVector.push(map[term] || 0); - } - return termFreqVector; -} -function vecDotProduct(vecA, vecB) { - var product = 0; - for (var i = 0; i < vecA.length; i++) { - product += vecA[i] * vecB[i]; - } - return product; -} -function vecMagnitude(vec) { - var sum = 0; - for (var i = 0; i < vec.length; i++) { - sum += vec[i] * vec[i]; - } - return Math.sqrt(sum); -} -function cosineSimilarity(vecA, vecB) { - return vecDotProduct(vecA, vecB) / (vecMagnitude(vecA) * vecMagnitude(vecB)); -} -const calculateCosineSimilarity = (strA, strB) => { - var termFreqA = termFreqMap(strA); - var termFreqB = termFreqMap(strB); - var dict = {}; - addKeysToDict(termFreqA, dict); - addKeysToDict(termFreqB, dict); - var termFreqVecA = termFreqMapToVector(termFreqA, dict); - var termFreqVecB = termFreqMapToVector(termFreqB, dict); - return cosineSimilarity(termFreqVecA, termFreqVecB); -}; -exports.calculateCosineSimilarity = calculateCosineSimilarity; -const cosineBaseStrategy = { - name: 'cosine', - strategy: (valA, valB) => { - let res = (0, exports.calculateCosineSimilarity)(valA, valB); - if (res > 0.99999) { - res = 1; - } - return { - score: res * 100, - rawScore: res - }; - } -}; -/** - * Compares whole tokens (words) within a string independent of order - * - * 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 - * - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one - * */ -exports.cosineStrategy = { - ...cosineBaseStrategy, - isValid: (valA, valB) => { - // cosine only compares full tokens (words), rather than characters, in a string - // which makes its score very inaccurate when comparing low token-count strings (short sentences and/or words with typos) - // so disable its usage if there are less than 4 tokens - const valATokenLength = valA.split(' ').length; - const valBTokenLength = valB.split(' ').length; - return valATokenLength < 4 || valBTokenLength < 4; - } -}; -/** - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings - * */ -exports.cosineStrategyAggressive = { - ...cosineBaseStrategy -}; -//# sourceMappingURL=cosineSimilarity.js.map \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/cosineSimilarity.js.map b/dist/commonjs/matchingStrategies/cosineSimilarity.js.map deleted file mode 100644 index 3158aaa..0000000 --- a/dist/commonjs/matchingStrategies/cosineSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,QAAQ,GAAW,EAAE,CAAC;IAC1B,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QACrB,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,IAAa;IAC7C,KAAK,IAAI,GAAG,IAAI,GAAG,EAAE;QACjB,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;KACpB;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW,EAAE,IAAY;IAClD,IAAI,cAAc,GAAG,EAAE,CAAC;IACxB,KAAK,IAAI,IAAI,IAAI,IAAI,EAAE;QACnB,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;KACvC;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AC,SAAS,EAAE,IAAI,CAAC,CAAC;IAExD,OAAO,gBAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACxD,CAAC,CAAA;AAZY,QAAA,yBAAyB,6BAYrC;AAED,MAAM,kBAAkB,GAAuD;IAC3E,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;QACrC,IAAI,GAAG,GAAG,IAAA,iCAAyB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChD,IAAG,GAAG,GAAG,OAAO,EAAE;YACd,GAAG,GAAG,CAAC,CAAC;SACX;QACD,OAAO;YACH,KAAK,EAAE,GAAG,GAAG,GAAG;YAChB,QAAQ,EAAE,GAAG;SAChB,CAAA;IACL,CAAC;CACJ,CAAA;AAED;;;;;;KAMK;AACQ,QAAA,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;AACQ,QAAA,wBAAwB,GAAuD;IACxF,GAAG,kBAAkB;CACxB,CAAA"} \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/diceSimilarity.d.ts b/dist/commonjs/matchingStrategies/diceSimilarity.d.ts deleted file mode 100644 index 65d0389..0000000 --- a/dist/commonjs/matchingStrategies/diceSimilarity.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateDiceSimilarity: (valA: string, valB: string) => number; -export declare const diceStrategy: ComparisonStrategy; diff --git a/dist/commonjs/matchingStrategies/diceSimilarity.js b/dist/commonjs/matchingStrategies/diceSimilarity.js deleted file mode 100644 index a83d16f..0000000 --- a/dist/commonjs/matchingStrategies/diceSimilarity.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.diceStrategy = exports.calculateDiceSimilarity = void 0; -const string_similarity_1 = __importDefault(require("string-similarity")); -const calculateDiceSimilarity = (valA, valB) => string_similarity_1.default.compareTwoStrings(valA, valB); -exports.calculateDiceSimilarity = calculateDiceSimilarity; -exports.diceStrategy = { - name: 'dice', - strategy: (valA, valB) => { - const res = (0, exports.calculateDiceSimilarity)(valA, valB); - return { - score: res * 100, - rawScore: res - }; - } -}; -//# sourceMappingURL=diceSimilarity.js.map \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/diceSimilarity.js.map b/dist/commonjs/matchingStrategies/diceSimilarity.js.map deleted file mode 100644 index c06824b..0000000 --- a/dist/commonjs/matchingStrategies/diceSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/index.d.ts b/dist/commonjs/matchingStrategies/index.d.ts deleted file mode 100644 index 8c9b96f..0000000 --- a/dist/commonjs/matchingStrategies/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { levenStrategy } from "./levenSimilarity.js"; -import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; -import { diceStrategy } from "./diceSimilarity.js"; -import { ComparisonStrategy, ComparisonStrategyResultValue, ComparisonStrategyResultObject, StrategyFunc } from '../atomic.js'; -export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy, ComparisonStrategy, ComparisonStrategyResultObject, ComparisonStrategyResultValue, StrategyFunc }; diff --git a/dist/commonjs/matchingStrategies/index.js b/dist/commonjs/matchingStrategies/index.js deleted file mode 100644 index d1ce17c..0000000 --- a/dist/commonjs/matchingStrategies/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.diceStrategy = exports.cosineStrategyAggressive = exports.cosineStrategy = exports.levenStrategy = void 0; -const levenSimilarity_js_1 = require("./levenSimilarity.js"); -Object.defineProperty(exports, "levenStrategy", { enumerable: true, get: function () { return levenSimilarity_js_1.levenStrategy; } }); -const cosineSimilarity_js_1 = require("./cosineSimilarity.js"); -Object.defineProperty(exports, "cosineStrategy", { enumerable: true, get: function () { return cosineSimilarity_js_1.cosineStrategy; } }); -Object.defineProperty(exports, "cosineStrategyAggressive", { enumerable: true, get: function () { return cosineSimilarity_js_1.cosineStrategyAggressive; } }); -const diceSimilarity_js_1 = require("./diceSimilarity.js"); -Object.defineProperty(exports, "diceStrategy", { enumerable: true, get: function () { return diceSimilarity_js_1.diceStrategy; } }); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/index.js.map b/dist/commonjs/matchingStrategies/index.js.map deleted file mode 100644 index a655b05..0000000 --- a/dist/commonjs/matchingStrategies/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/levenSimilarity.d.ts b/dist/commonjs/matchingStrategies/levenSimilarity.d.ts deleted file mode 100644 index 4dee4fe..0000000 --- a/dist/commonjs/matchingStrategies/levenSimilarity.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateLevenSimilarity: (valA: string, valB: string) => number[]; -export declare const levenStrategy: ComparisonStrategy; diff --git a/dist/commonjs/matchingStrategies/levenSimilarity.js b/dist/commonjs/matchingStrategies/levenSimilarity.js deleted file mode 100644 index ffb2786..0000000 --- a/dist/commonjs/matchingStrategies/levenSimilarity.js +++ /dev/null @@ -1,40 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.levenStrategy = exports.calculateLevenSimilarity = void 0; -const leven_1 = __importDefault(require("leven")); -const calculateLevenSimilarity = (valA, valB) => { - let longer; - let shorter; - if (valA.length > valB.length) { - longer = valA; - shorter = valB; - } - else { - longer = valB; - shorter = valA; - } - const distance = (0, leven_1.default)(longer, shorter); - // use the shorter length - // because if we have more move/change operations than the length of the shortest string than we have two unique strings - // and if we use the longer length the score actually gets *better* as the length gap gets larger (not what we want) - // -- cap at 100% diff - const diff = Math.min((distance / shorter.length) * 100, 100); - return [distance, 100 - diff]; -}; -exports.calculateLevenSimilarity = calculateLevenSimilarity; -const stratFunc = (valA, valB) => { - const res = (0, exports.calculateLevenSimilarity)(valA, valB); - return { - rawScore: res[0], - distance: res[0], - score: res[1] - }; -}; -exports.levenStrategy = { - name: 'leven', - strategy: stratFunc -}; -//# sourceMappingURL=levenSimilarity.js.map \ No newline at end of file diff --git a/dist/commonjs/matchingStrategies/levenSimilarity.js.map b/dist/commonjs/matchingStrategies/levenSimilarity.js.map deleted file mode 100644 index c1ee3c1..0000000 --- a/dist/commonjs/matchingStrategies/levenSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/commonjs/normalization/index.d.ts b/dist/commonjs/normalization/index.d.ts deleted file mode 100644 index 09d40c3..0000000 --- a/dist/commonjs/normalization/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { StringTransformFunc } from "../atomic.js"; -declare const lowercase: StringTransformFunc; -declare const trim: StringTransformFunc; -declare const replaceUnicode: StringTransformFunc; -declare const removePunctuation: StringTransformFunc; -declare const removeNonAlphanumeric: StringTransformFunc; -declare const removeWhitespace: StringTransformFunc; -declare const replaceMultiWhitespace: StringTransformFunc; -declare const transforms: { - lowercase: StringTransformFunc; - trim: StringTransformFunc; - replaceMultiWhitespace: StringTransformFunc; - replaceUnicode: StringTransformFunc; - removeWhitespace: StringTransformFunc; - removePunctuation: StringTransformFunc; -}; -declare const strDefaultTransforms: StringTransformFunc[]; -export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms }; diff --git a/dist/commonjs/normalization/index.js b/dist/commonjs/normalization/index.js deleted file mode 100644 index 60d07d5..0000000 --- a/dist/commonjs/normalization/index.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.strDefaultTransforms = exports.transforms = exports.replaceMultiWhitespace = exports.removeNonAlphanumeric = exports.removeWhitespace = exports.removePunctuation = exports.replaceUnicode = exports.trim = exports.lowercase = void 0; -const PUNCTUATION_REGEX = new RegExp(/[`=(){}<>;',.~!@#$%^&*_+|:"?\-\\\[\]\/]/g); -const NON_ALPHANUMERIC_REGEX = new RegExp(/[^\w\s]|_/g); -const WHITESPACE_REGEX = new RegExp(/\s/g); -const MULTI_WHITESPACE_REGEX = new RegExp(/\s{2,}/g); -const lowercase = (str) => str.toLocaleLowerCase(); -exports.lowercase = lowercase; -const trim = (str) => str.trim(); -exports.trim = trim; -const replaceUnicode = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); -exports.replaceUnicode = replaceUnicode; -const removePunctuation = (str) => str.replace(PUNCTUATION_REGEX, ''); -exports.removePunctuation = removePunctuation; -const removeNonAlphanumeric = (str) => str.replace(NON_ALPHANUMERIC_REGEX, ''); -exports.removeNonAlphanumeric = removeNonAlphanumeric; -const removeWhitespace = (str) => str.replace(WHITESPACE_REGEX, ''); -exports.removeWhitespace = removeWhitespace; -const replaceMultiWhitespace = (str) => str.replace(MULTI_WHITESPACE_REGEX, ' '); -exports.replaceMultiWhitespace = replaceMultiWhitespace; -const transforms = { - lowercase, - trim, - replaceMultiWhitespace, - replaceUnicode, - removeWhitespace, - removePunctuation -}; -exports.transforms = transforms; -const strDefaultTransforms = [ - replaceUnicode, - removePunctuation, - trim, - replaceMultiWhitespace, - lowercase -]; -exports.strDefaultTransforms = strDefaultTransforms; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/commonjs/normalization/index.js.map b/dist/commonjs/normalization/index.js.map deleted file mode 100644 index fd2c87f..0000000 --- a/dist/commonjs/normalization/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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,MAA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b/dist/commonjs/package.json deleted file mode 100644 index 5bbefff..0000000 --- a/dist/commonjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "commonjs" -} diff --git a/dist/esm/atomic.d.ts b/dist/esm/atomic.d.ts deleted file mode 100644 index e88c7e6..0000000 --- a/dist/esm/atomic.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -export interface StringComparisonOptions { - /** - * An array of transformations to apply to each string before comparing similarity - * */ - transforms?: StringTransformFunc[]; - /** - * An array of strategies used to score similarity. All strategies scores are combined for an average high score. - * */ - strategies?: ComparisonStrategy[]; - /** - * Reorder second string so its token match order of first string as closely as possible - * - * Useful when only the differences in content are important, but not the order of the content - * */ - reorder?: boolean; - /** - * When `reorder` is used this determines how to split each string into the tokens that will be reordered. - * - * 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 - * - * @default " " - * */ - delimiter?: string | RegExp; -} -export interface StringSamenessResult { - strategies: { - [key: string]: ComparisonStrategyResult; - }; - highScore: number; - highScoreWeighted: number; -} -export interface ComparisonStrategyResultObject { - /** - * The normalized (0 to 100) score of this comparison - * */ - score: number; - /** - * The raw value returned by the comparison (not normalized) - * */ - rawScore?: number; - [key: string]: any; -} -export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { -} -export interface NamedComparisonStrategyObjectResult extends ComparisonStrategyResultObject { - name: string; -} -export type ComparisonStrategyResultValue = number | ComparisonStrategyResultObject; -export type StrategyFunc = (strA: string, strB: string) => T; -export interface ComparisonStrategy { - /** - * The name of this strategy - * */ - name: string; - /** - * A function that accepts two string arguments and returns a number - * */ - strategy: StrategyFunc; - /** - * An optional function that accepts two string arguments and returns whether this strategy should be used - * */ - isValid?: (strA: string, strB: string) => boolean; -} -export type StringTransformFunc = (str: string) => string; diff --git a/dist/esm/atomic.js b/dist/esm/atomic.js deleted file mode 100644 index 7730b0a..0000000 --- a/dist/esm/atomic.js +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=atomic.js.map \ No newline at end of file diff --git a/dist/esm/atomic.js.map b/dist/esm/atomic.js.map deleted file mode 100644 index d76053d..0000000 --- a/dist/esm/atomic.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/index.d.ts b/dist/esm/index.d.ts deleted file mode 100644 index 7bf1740..0000000 --- a/dist/esm/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ComparisonStrategyResult, StringComparisonOptions, StringSamenessResult, StringTransformFunc } from "./atomic.js"; -import { strDefaultTransforms, transforms } from "./normalization/index.js"; -declare const defaultStrategies: import("./atomic.js").ComparisonStrategy[]; -declare const stringSameness: (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; -export declare const reorderStr: (strA: string, strB: string, options?: StringComparisonOptions) => [string, string]; -declare const createStringSameness: (defaults: StringComparisonOptions) => (valA: string, valB: string, options?: StringComparisonOptions) => StringSamenessResult; -declare const strategies: { - diceStrategy: import("./atomic.js").ComparisonStrategy; - levenStrategy: import("./atomic.js").ComparisonStrategy; - cosineStrategy: import("./atomic.js").ComparisonStrategy; - cosineStrategyAggressive: import("./atomic.js").ComparisonStrategy; -}; -declare const defaultStrCompareTransformFuncs: StringTransformFunc[]; -export { StringSamenessResult, StringComparisonOptions, stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms, ComparisonStrategyResult, StringTransformFunc }; diff --git a/dist/esm/index.js b/dist/esm/index.js deleted file mode 100644 index 9a862b4..0000000 --- a/dist/esm/index.js +++ /dev/null @@ -1,123 +0,0 @@ -import { cosineStrategy, levenStrategy, diceStrategy, cosineStrategyAggressive } from "./matchingStrategies/index.js"; -import { strDefaultTransforms, transforms } from "./normalization/index.js"; -const sentenceLengthWeight = (length) => { - // thanks jordan :') - // constants are black magic - return (Math.log(length) / 0.20) - 5; -}; -const defaultStrategies = [ - diceStrategy, - levenStrategy, - cosineStrategy -]; -const stringSameness = (valA, valB, options) => { - const { transforms = strDefaultTransforms, strategies = defaultStrategies, reorder = false, delimiter = ' ' } = options || {}; - let cleanA = transforms.reduce((acc, curr) => curr(acc), valA); - let cleanB = transforms.reduce((acc, curr) => curr(acc), valB); - if (reorder) { - // 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) - // 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 - // before we run strategies - const [orderedX, orderedY] = reorderStr(cleanA, cleanB); - cleanA = orderedX; - cleanB = orderedY; - } - const shortest = cleanA.length > cleanB.length ? cleanB : cleanA; - const stratResults = []; - for (const strat of strategies) { - if (strat.isValid !== undefined && !strat.isValid(cleanA, cleanB)) { - continue; - } - const res = strat.strategy(cleanA, cleanB); - const resObj = typeof res === 'number' ? { score: res } : res; - stratResults.push({ - ...resObj, - name: strat.name - }); - } - // use shortest sentence for weight - const weightScore = sentenceLengthWeight(shortest.length); - // take average score - const highScore = stratResults.reduce((acc, curr) => acc + curr.score, 0) / stratResults.length; - // weight score can be a max of 15 - const highScoreWeighted = highScore + Math.min(weightScore, 15); - const stratObj = stratResults.reduce((acc, curr) => { - const { name, score, ...rest } = curr; - acc[curr.name] = { - ...rest, - score, - }; - return acc; - }, {}); - return { - strategies: stratObj, - highScore, - highScoreWeighted, - }; -}; -export const reorderStr = (strA, strB, options) => { - const { transforms = strDefaultTransforms, strategies = defaultStrategies, delimiter = ' ' } = options || {}; - const cleanA = transforms.reduce((acc, curr) => curr(acc), strA); - const cleanB = transforms.reduce((acc, curr) => curr(acc), strB); - // split by "token" - const eTokens = cleanA.split(delimiter); - const cTokens = cleanB.split(delimiter); - let longerTokens, shorterTokens; - if (eTokens.length > cTokens.length) { - longerTokens = eTokens; - shorterTokens = cTokens; - } - else { - longerTokens = cTokens; - shorterTokens = eTokens; - } - // we will use longest string (token list) as the reducer and order the shorter list to match it - // so we don't have to deal with undefined positions in the shorter list - const orderedCandidateTokens = longerTokens.reduce((acc, curr) => { - // if we've run out of tokens in the shorter list just return - if (acc.remaining.length === 0) { - return acc; - } - // on each iteration of tokens in the long list - // we iterate through remaining tokens from the shorter list and find the token with the most sameness - let highScore = 0; - let highIndex = 0; - let index = 0; - for (const token of acc.remaining) { - const result = stringSameness(curr, token, { strategies }); - if (result.highScoreWeighted > highScore) { - highScore = result.highScoreWeighted; - highIndex = index; - } - index++; - } - // then remove the most same token from the remaining short list tokens - const splicedRemaining = [...acc.remaining]; - splicedRemaining.splice(highIndex, 1); - return { - // finally add the most same token to the ordered short list - ordered: acc.ordered.concat(acc.remaining[highIndex]), - // and return the remaining short list tokens - remaining: splicedRemaining - }; - }, { - // "ordered" is the result of ordering tokens in the shorter list to match longer token order - ordered: [], - // remaining is the initial shorter list - remaining: shorterTokens - }); - return [longerTokens.join(' '), orderedCandidateTokens.ordered.join(' ')]; -}; -const createStringSameness = (defaults) => { - return (valA, valB, options = {}) => stringSameness(valA, valB, { ...defaults, ...options }); -}; -const strategies = { - diceStrategy, - levenStrategy, - cosineStrategy, - cosineStrategyAggressive -}; -// maintaining compatibility -const defaultStrCompareTransformFuncs = strDefaultTransforms; -export { stringSameness, createStringSameness, defaultStrategies, strategies, transforms, defaultStrCompareTransformFuncs, strDefaultTransforms }; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map deleted file mode 100644 index 1c07647..0000000 --- a/dist/esm/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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,MAAc,EAAE,EAAE;IAC5C,oB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BAA+B,EAC/B,oBAAoB,EAGvB,CAAA"} \ No newline at end of file diff --git a/dist/esm/matchingStrategies/cosineSimilarity.d.ts b/dist/esm/matchingStrategies/cosineSimilarity.d.ts deleted file mode 100644 index 1a6679e..0000000 --- a/dist/esm/matchingStrategies/cosineSimilarity.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateCosineSimilarity: (strA: string, strB: string) => number; -/** - * Compares whole tokens (words) within a string independent of order - * - * 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 - * - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one - * */ -export declare const cosineStrategy: ComparisonStrategy; -/** - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings - * */ -export declare const cosineStrategyAggressive: ComparisonStrategy; diff --git a/dist/esm/matchingStrategies/cosineSimilarity.js b/dist/esm/matchingStrategies/cosineSimilarity.js deleted file mode 100644 index f0623b3..0000000 --- a/dist/esm/matchingStrategies/cosineSimilarity.js +++ /dev/null @@ -1,87 +0,0 @@ -// reproduced from https://github.com/sumn2u/string-comparison/blob/master/jscosine.js -// https://sumn2u.medium.com/string-similarity-comparision-in-js-with-examples-4bae35f13968 -function termFreqMap(str) { - var words = str.split(' '); - var termFreq = {}; - words.forEach(function (w) { - termFreq[w] = (termFreq[w] || 0) + 1; - }); - return termFreq; -} -function addKeysToDict(map, dict) { - for (var key in map) { - dict[key] = true; - } -} -function termFreqMapToVector(map, dict) { - var termFreqVector = []; - for (var term in dict) { - termFreqVector.push(map[term] || 0); - } - return termFreqVector; -} -function vecDotProduct(vecA, vecB) { - var product = 0; - for (var i = 0; i < vecA.length; i++) { - product += vecA[i] * vecB[i]; - } - return product; -} -function vecMagnitude(vec) { - var sum = 0; - for (var i = 0; i < vec.length; i++) { - sum += vec[i] * vec[i]; - } - return Math.sqrt(sum); -} -function cosineSimilarity(vecA, vecB) { - return vecDotProduct(vecA, vecB) / (vecMagnitude(vecA) * vecMagnitude(vecB)); -} -export const calculateCosineSimilarity = (strA, strB) => { - var termFreqA = termFreqMap(strA); - var termFreqB = termFreqMap(strB); - var dict = {}; - addKeysToDict(termFreqA, dict); - addKeysToDict(termFreqB, dict); - var termFreqVecA = termFreqMapToVector(termFreqA, dict); - var termFreqVecB = termFreqMapToVector(termFreqB, dict); - return cosineSimilarity(termFreqVecA, termFreqVecB); -}; -const cosineBaseStrategy = { - name: 'cosine', - strategy: (valA, valB) => { - let res = calculateCosineSimilarity(valA, valB); - if (res > 0.99999) { - res = 1; - } - return { - score: res * 100, - rawScore: res - }; - } -}; -/** - * Compares whole tokens (words) within a string independent of order - * - * 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 - * - * If you'd like to use it even in these scenarios build your own strategy array using cosineStrategyAggressive instead of this one - * */ -export const cosineStrategy = { - ...cosineBaseStrategy, - isValid: (valA, valB) => { - // cosine only compares full tokens (words), rather than characters, in a string - // which makes its score very inaccurate when comparing low token-count strings (short sentences and/or words with typos) - // so disable its usage if there are less than 4 tokens - const valATokenLength = valA.split(' ').length; - const valBTokenLength = valB.split(' ').length; - return valATokenLength < 4 || valBTokenLength < 4; - } -}; -/** - * Always runs (strings are always valid) which may lead to inaccurate scores in low token-count strings - * */ -export const cosineStrategyAggressive = { - ...cosineBaseStrategy -}; -//# sourceMappingURL=cosineSimilarity.js.map \ No newline at end of file diff --git a/dist/esm/matchingStrategies/cosineSimilarity.js.map b/dist/esm/matchingStrategies/cosineSimilarity.js.map deleted file mode 100644 index eaef648..0000000 --- a/dist/esm/matchingStrategies/cosineSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"cosineSimilarity.js","sourceRoot":"","sources":["../../../src/matchingStrategies/cosineSimilarity.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,2FAA2F;AAa3F,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AAkB;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"} \ No newline at end of file diff --git a/dist/esm/matchingStrategies/diceSimilarity.d.ts b/dist/esm/matchingStrategies/diceSimilarity.d.ts deleted file mode 100644 index 65d0389..0000000 --- a/dist/esm/matchingStrategies/diceSimilarity.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateDiceSimilarity: (valA: string, valB: string) => number; -export declare const diceStrategy: ComparisonStrategy; diff --git a/dist/esm/matchingStrategies/diceSimilarity.js b/dist/esm/matchingStrategies/diceSimilarity.js deleted file mode 100644 index cd00b1a..0000000 --- a/dist/esm/matchingStrategies/diceSimilarity.js +++ /dev/null @@ -1,13 +0,0 @@ -import stringSimilarity from 'string-similarity'; -export const calculateDiceSimilarity = (valA, valB) => stringSimilarity.compareTwoStrings(valA, valB); -export const diceStrategy = { - name: 'dice', - strategy: (valA, valB) => { - const res = calculateDiceSimilarity(valA, valB); - return { - score: res * 100, - rawScore: res - }; - } -}; -//# sourceMappingURL=diceSimilarity.js.map \ No newline at end of file diff --git a/dist/esm/matchingStrategies/diceSimilarity.js.map b/dist/esm/matchingStrategies/diceSimilarity.js.map deleted file mode 100644 index cb4e84e..0000000 --- a/dist/esm/matchingStrategies/diceSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/esm/matchingStrategies/index.d.ts b/dist/esm/matchingStrategies/index.d.ts deleted file mode 100644 index 8c9b96f..0000000 --- a/dist/esm/matchingStrategies/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { levenStrategy } from "./levenSimilarity.js"; -import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; -import { diceStrategy } from "./diceSimilarity.js"; -import { ComparisonStrategy, ComparisonStrategyResultValue, ComparisonStrategyResultObject, StrategyFunc } from '../atomic.js'; -export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy, ComparisonStrategy, ComparisonStrategyResultObject, ComparisonStrategyResultValue, StrategyFunc }; diff --git a/dist/esm/matchingStrategies/index.js b/dist/esm/matchingStrategies/index.js deleted file mode 100644 index 2cdbf8c..0000000 --- a/dist/esm/matchingStrategies/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import { levenStrategy } from "./levenSimilarity.js"; -import { cosineStrategy, cosineStrategyAggressive } from "./cosineSimilarity.js"; -import { diceStrategy } from "./diceSimilarity.js"; -export { levenStrategy, cosineStrategy, cosineStrategyAggressive, diceStrategy }; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/matchingStrategies/index.js.map b/dist/esm/matchingStrategies/index.js.map deleted file mode 100644 index 5e4098b..0000000 --- a/dist/esm/matchingStrategies/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/esm/matchingStrategies/levenSimilarity.d.ts b/dist/esm/matchingStrategies/levenSimilarity.d.ts deleted file mode 100644 index 4dee4fe..0000000 --- a/dist/esm/matchingStrategies/levenSimilarity.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ComparisonStrategy, ComparisonStrategyResultObject } from "../atomic.js"; -export declare const calculateLevenSimilarity: (valA: string, valB: string) => number[]; -export declare const levenStrategy: ComparisonStrategy; diff --git a/dist/esm/matchingStrategies/levenSimilarity.js b/dist/esm/matchingStrategies/levenSimilarity.js deleted file mode 100644 index 3852db8..0000000 --- a/dist/esm/matchingStrategies/levenSimilarity.js +++ /dev/null @@ -1,33 +0,0 @@ -import leven from "leven"; -export const calculateLevenSimilarity = (valA, valB) => { - let longer; - let shorter; - if (valA.length > valB.length) { - longer = valA; - shorter = valB; - } - else { - longer = valB; - shorter = valA; - } - const distance = leven(longer, shorter); - // use the shorter length - // because if we have more move/change operations than the length of the shortest string than we have two unique strings - // and if we use the longer length the score actually gets *better* as the length gap gets larger (not what we want) - // -- cap at 100% diff - const diff = Math.min((distance / shorter.length) * 100, 100); - return [distance, 100 - diff]; -}; -const stratFunc = (valA, valB) => { - const res = calculateLevenSimilarity(valA, valB); - return { - rawScore: res[0], - distance: res[0], - score: res[1] - }; -}; -export const levenStrategy = { - name: 'leven', - strategy: stratFunc -}; -//# sourceMappingURL=levenSimilarity.js.map \ No newline at end of file diff --git a/dist/esm/matchingStrategies/levenSimilarity.js.map b/dist/esm/matchingStrategies/levenSimilarity.js.map deleted file mode 100644 index a8faf41..0000000 --- a/dist/esm/matchingStrategies/levenSimilarity.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/dist/esm/normalization/index.d.ts b/dist/esm/normalization/index.d.ts deleted file mode 100644 index 09d40c3..0000000 --- a/dist/esm/normalization/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { StringTransformFunc } from "../atomic.js"; -declare const lowercase: StringTransformFunc; -declare const trim: StringTransformFunc; -declare const replaceUnicode: StringTransformFunc; -declare const removePunctuation: StringTransformFunc; -declare const removeNonAlphanumeric: StringTransformFunc; -declare const removeWhitespace: StringTransformFunc; -declare const replaceMultiWhitespace: StringTransformFunc; -declare const transforms: { - lowercase: StringTransformFunc; - trim: StringTransformFunc; - replaceMultiWhitespace: StringTransformFunc; - replaceUnicode: StringTransformFunc; - removeWhitespace: StringTransformFunc; - removePunctuation: StringTransformFunc; -}; -declare const strDefaultTransforms: StringTransformFunc[]; -export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms }; diff --git a/dist/esm/normalization/index.js b/dist/esm/normalization/index.js deleted file mode 100644 index bc7ae0b..0000000 --- a/dist/esm/normalization/index.js +++ /dev/null @@ -1,28 +0,0 @@ -const PUNCTUATION_REGEX = new RegExp(/[`=(){}<>;',.~!@#$%^&*_+|:"?\-\\\[\]\/]/g); -const NON_ALPHANUMERIC_REGEX = new RegExp(/[^\w\s]|_/g); -const WHITESPACE_REGEX = new RegExp(/\s/g); -const MULTI_WHITESPACE_REGEX = new RegExp(/\s{2,}/g); -const lowercase = (str) => str.toLocaleLowerCase(); -const trim = (str) => str.trim(); -const replaceUnicode = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); -const removePunctuation = (str) => str.replace(PUNCTUATION_REGEX, ''); -const removeNonAlphanumeric = (str) => str.replace(NON_ALPHANUMERIC_REGEX, ''); -const removeWhitespace = (str) => str.replace(WHITESPACE_REGEX, ''); -const replaceMultiWhitespace = (str) => str.replace(MULTI_WHITESPACE_REGEX, ' '); -const transforms = { - lowercase, - trim, - replaceMultiWhitespace, - replaceUnicode, - removeWhitespace, - removePunctuation -}; -const strDefaultTransforms = [ - replaceUnicode, - removePunctuation, - trim, - replaceMultiWhitespace, - lowercase -]; -export { lowercase, trim, replaceUnicode, removePunctuation, removeWhitespace, removeNonAlphanumeric, replaceMultiWhitespace, transforms, strDefaultTransforms }; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/normalization/index.js.map b/dist/esm/normalization/index.js.map deleted file mode 100644 index 4817cb4..0000000 --- a/dist/esm/normalization/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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;AAChF,MAAM,IAAI,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AAC9D,MAAM,cAAc,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AAClH,MAAM,iBAAiB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnG,MAAM,qBAAqB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;AAC5G,MAAM,gBAAgB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACjG,MAAM,sBAAsB,GAAwB,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;AAE9G,MAAM,UAAU,GAAG;IACf,SAAS;IACT,IAAI;IACJ,sBAAsB;IACtB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;CACpB,CAAA;AAED,MAAM,oBAAoB,GAA0B;IAChD,cAAc;IACd,iBAAiB;IACjB,IAAI;IACJ,sBAAsB;IACtB,SAAS;CACZ,CAAC;AAEF,OAAO,EACH,SAAS,EACT,IAAI,EACJ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,oBAAoB,EACvB,CAAA"} \ No newline at end of file diff --git a/dist/esm/package.json b/dist/esm/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/dist/esm/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -}