(stringA, stringB)
| 31 | |
| 32 | // Calculate Dice coeff of 2 strings |
| 33 | function diceCoefficient(stringA, stringB) { |
| 34 | if (stringA === stringB) return 1 |
| 35 | else if (stringA.length < 2 || stringB.length < 2) return 0 |
| 36 | |
| 37 | const bigramsA = mapBigrams(stringA) |
| 38 | |
| 39 | const lengthA = stringA.length - 1 |
| 40 | const lengthB = stringB.length - 1 |
| 41 | |
| 42 | let dice = (2 * countCommonBigrams(bigramsA, stringB)) / (lengthA + lengthB) |
| 43 | |
| 44 | // cut 0.xxxxxx to 0.xx for simplicity |
| 45 | dice = Math.floor(dice * 100) / 100 |
| 46 | |
| 47 | return dice |
| 48 | } |
| 49 | |
| 50 | export { diceCoefficient } |
no test coverage detected