[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.

Add rawScore to strategy output

FoxxMD (Apr 4, 2023, 3:43 PM EDT) d78cc6b4 5fa531a1

+66 -23
+19 -16
README.md
··· 20 20 21 21 const result = stringSameness('This is one sentence', 'This is another sentence'); 22 22 console.log(result); 23 - //{ 24 - // "strategies": { 25 - // "dice": { 26 - // "score": 66.66666666666666 27 - // }, 28 - // "leven": { 29 - // "distance": 5, 30 - // "score": 79.16666666666666 31 - // }, 32 - // "cosine": { 33 - // "score": 75 34 - // } 35 - // }, 36 - // "highScore": 73.6111111111111, 37 - // "highScoreWeighted": 83.58977247888106 38 - //} 23 + // { 24 + // "strategies": { 25 + // "dice": { 26 + // "rawScore": 0.6666, 27 + // "score": 66.66 28 + // }, 29 + // "leven": { 30 + // "rawScore": 5, 31 + // "distance": 5, 32 + // "score": 79.16 33 + // }, 34 + // "cosine": { 35 + // "rawScore": 0.75, 36 + // "score": 75 37 + // } 38 + // }, 39 + // "highScore": 73.61, 40 + // "highScoreWeighted": 83.58 41 + // } 39 42 ``` 40 43 41 44 # Options
+8 -1
dist/atomic.d.ts
··· 10 10 highScoreWeighted: number; 11 11 } 12 12 export interface ComparisonStrategyResultObject { 13 + /** 14 + * The normalized (0 to 100) score of this comparison 15 + * */ 13 16 score: number; 17 + /** 18 + * The raw value returned by the comparison (not normalized) 19 + * */ 20 + rawScore?: number; 14 21 [key: string]: any; 15 22 } 16 23 export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { ··· 30 37 * */ 31 38 strategy: StrategyFunc; 32 39 /** 33 - * An optional function that accepts to string arguments and returns whether this strategy should be used 40 + * An optional function that accepts two string arguments and returns whether this strategy should be used 34 41 * */ 35 42 isValid?: (strA: string, strB: string) => boolean; 36 43 }
+7 -1
dist/matchingStrategies/cosineSimilarity.js
··· 53 53 exports.calculateCosineSimilarity = calculateCosineSimilarity; 54 54 exports.cosineStrategy = { 55 55 name: 'cosine', 56 - strategy: (valA, valB) => (0, exports.calculateCosineSimilarity)(valA, valB) * 100 56 + strategy: (valA, valB) => { 57 + const res = (0, exports.calculateCosineSimilarity)(valA, valB); 58 + return { 59 + score: res * 100, 60 + rawScore: res 61 + }; 62 + } 57 63 };
+7 -1
dist/matchingStrategies/diceSimilarity.js
··· 9 9 exports.calculateDiceSimilarity = calculateDiceSimilarity; 10 10 exports.diceStrategy = { 11 11 name: 'dice', 12 - strategy: (valA, valB) => string_similarity_1.default.compareTwoStrings(valA, valB) * 100 12 + strategy: (valA, valB) => { 13 + const res = (0, exports.calculateDiceSimilarity)(valA, valB); 14 + return { 15 + score: res * 100, 16 + rawScore: res 17 + }; 18 + } 13 19 };
+1
dist/matchingStrategies/levenSimilarity.js
··· 24 24 const stratFunc = (valA, valB) => { 25 25 const res = (0, exports.calculateLevenSimilarity)(valA, valB); 26 26 return { 27 + rawScore: res[0], 27 28 distance: res[0], 28 29 score: res[1] 29 30 };
+1 -1
package.json
··· 1 1 { 2 2 "name": "@foxxmd/string-sameness", 3 - "version": "0.1.2", 3 + "version": "0.1.3", 4 4 "description": "determine how closely the same two strings are", 5 5 "repository": "https://github.com/foxxmd/string-sameness", 6 6 "author": "FoxxMD",
+8 -1
src/atomic.ts
··· 12 12 } 13 13 14 14 export interface ComparisonStrategyResultObject { 15 + /** 16 + * The normalized (0 to 100) score of this comparison 17 + * */ 15 18 score: number 19 + /** 20 + * The raw value returned by the comparison (not normalized) 21 + * */ 22 + rawScore?: number 16 23 17 24 [key: string]: any 18 25 } ··· 41 48 strategy: StrategyFunc 42 49 43 50 /** 44 - * An optional function that accepts to string arguments and returns whether this strategy should be used 51 + * An optional function that accepts two string arguments and returns whether this strategy should be used 45 52 * */ 46 53 isValid?: (strA: string, strB: string) => boolean 47 54 }
+7 -1
src/matchingStrategies/cosineSimilarity.ts
··· 71 71 72 72 export const cosineStrategy: ComparisonStrategy = { 73 73 name: 'cosine', 74 - strategy: (valA: string, valB: string) => calculateCosineSimilarity(valA, valB) * 100 74 + strategy: (valA: string, valB: string) => { 75 + const res = calculateCosineSimilarity(valA, valB); 76 + return { 77 + score: res * 100, 78 + rawScore: res 79 + } 80 + } 75 81 }
+7 -1
src/matchingStrategies/diceSimilarity.ts
··· 4 4 export const calculateDiceSimilarity = (valA: string, valB: string) => stringSimilarity.compareTwoStrings(valA, valB); 5 5 export const diceStrategy: ComparisonStrategy = { 6 6 name: 'dice', 7 - strategy: (valA: string, valB: string) => stringSimilarity.compareTwoStrings(valA, valB) * 100 7 + strategy: (valA: string, valB: string) => { 8 + const res = calculateDiceSimilarity(valA, valB); 9 + return { 10 + score: res * 100, 11 + rawScore: res 12 + } 13 + } 8 14 }
+1
src/matchingStrategies/levenSimilarity.ts
··· 20 20 const stratFunc = (valA: string, valB: string) => { 21 21 const res = calculateLevenSimilarity(valA, valB); 22 22 return { 23 + rawScore: res[0], 23 24 distance: res[0], 24 25 score: res[1] 25 26 };