string-comparisons
Version:
A collection of string comparisons algorithms
1 lines • 24.8 kB
JavaScript
!function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var e=r();for(var n in e)("object"==typeof exports?exports:t)[n]=e[n]}}(this,(()=>(()=>{"use strict";var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,o(n.key),n)}}function o(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,r||"default");if("object"!=e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}t.r(r),t.d(r,{Cosine:()=>i,DamerauLevenshtein:()=>S,HammingDistance:()=>P,Jaccard:()=>p,Jaro:()=>f,JaroWrinker:()=>T,Levenshtein:()=>C,Ngram:()=>it,OptimalStringAlignment:()=>pt,Qgram:()=>yt,SmithWaterman:()=>x,SorensenDice:()=>J,SzymkiewiczSimpsonOverlap:()=>Z,Trigram:()=>H});const i=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"termFreqMap",value:function(t){var r=t.split(" "),e={};return r.forEach((function(t){e[t]=(e[t]||0)+1})),e}},{key:"addKeysToDict",value:function(t,r){for(var e in t)r[e]=!0}},{key:"termFreqMapToVector",value:function(t,r){var e=[];for(var n in r)e.push(t[n]||0);return e}},{key:"vecDotProduct",value:function(t,r){for(var e=0,n=0;n<t.length;n++)e+=t[n]*r[n];return e}},{key:"vecMagnitude",value:function(t){for(var r=0,e=0;e<t.length;e++)r+=t[e]*t[e];return Math.sqrt(r)}},{key:"calculateSimilarity",value:function(t,r){return this.vecDotProduct(t,r)/(this.vecMagnitude(t)*this.vecMagnitude(r))}},{key:"similarity",value:function(t,r){var e=this.termFreqMap(t),n=this.termFreqMap(r),o={};this.addKeysToDict(e,o),this.addKeysToDict(n,o);var i=this.termFreqMapToVector(e,o),u=this.termFreqMapToVector(n,o);return this.calculateSimilarity(i,u)}}],(r=null)&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function a(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,l(n.key),n)}}function l(t){var r=function(t,r){if("object"!=u(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==u(r)?r:r+""}const f=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){for(var e=Math.floor(Math.max(t.length,r.length)/2)-1,n=0,o=0,i=new Array(t.length).fill(!1),u=new Array(r.length).fill(!1),a=0;a<t.length;a++)for(var l=Math.max(0,a-e),f=Math.min(a+e+1,r.length),c=l;c<f;c++)if(!u[c]&&t[a]===r[c]){i[a]=!0,u[c]=!0,n++;break}if(0===n)return 0;for(var y=0,m=0;m<t.length;m++)if(i[m]){for(;!u[y];)y++;t[m]!==r[y]&&o++,y++}var s=n,b=o/2,p=(s/t.length+s/r.length+(s-b)/s)/3;return p}}],(r=null)&&a(t.prototype,r),e&&a(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function y(t){return function(t){if(Array.isArray(t))return m(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return m(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return m(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function s(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,b(n.key),n)}}function b(t){var r=function(t,r){if("object"!=c(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==c(r)?r:r+""}const p=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){var e=new Set(t),n=new Set(r),o=new Set(y(e).filter((function(t){return n.has(t)}))),i=new Set([].concat(y(e),y(n))),u=o.size/i.size;return u}}],(r=null)&&s(t.prototype,r),e&&s(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function v(t){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},v(t)}function g(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,h(n.key),n)}}function h(t){var r=function(t,r){if("object"!=v(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=v(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==v(r)?r:r+""}const S=function(){function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)}return r=t,n=[{key:"distance",value:function(t,r){for(var e=[],n=0;n<=t.length;n++)e[n]=[n];for(var o=0;o<=r.length;o++)e[0][o]=o;for(var i=1;i<=t.length;i++)for(var u=1;u<=r.length;u++){var a=t[i-1]===r[u-1]?0:1;e[i][u]=Math.min(e[i-1][u]+1,e[i][u-1]+1,e[i-1][u-1]+a),i>1&&u>1&&t[i-1]===r[u-2]&&t[i-2]===r[u-1]&&(e[i][u]=Math.min(e[i][u],e[i-2][u-2]+a))}return e[t.length][r.length]}},{key:"similarity",value:function(r,e){return 1-t.distance(r,e)/Math.max(r.length,e.length)}}],(e=null)&&g(r.prototype,e),n&&g(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,e,n}();function d(t){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},d(t)}function w(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,j(n.key),n)}}function j(t){var r=function(t,r){if("object"!=d(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=d(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==d(r)?r:r+""}const P=function(){function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)}return r=t,n=[{key:"calculate",value:function(t,r){if(t.length!==r.length)throw new Error("Strings must have the same length");for(var e=0,n=0;n<t.length;n++)t[n]!==r[n]&&e++;return e}},{key:"similarity",value:function(r,e){return 1-t.calculate(r,e)/r.length}}],(e=null)&&w(r.prototype,e),n&&w(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,e,n}();function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function k(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,O(n.key),n)}}function O(t){var r=function(t,r){if("object"!=A(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=A(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==A(r)?r:r+""}const T=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){var e=0;if(0===t.length||0===r.length)return 0;if(t===r)return 1;for(var n=Math.floor(Math.max(t.length,r.length)/2)-1,o=new Array(t.length).fill(!1),i=new Array(r.length).fill(!1),u=0;u<t.length;u++)for(var a=u>=n?u-n:0,l=u+n<=r.length?u+n:r.length-1,f=a;f<=l;f++)if(!o[u]&&!i[f]&&t[u]===r[f]){e++,o[u]=!0,i[f]=!0;break}if(0===e)return 0;for(var c=0,y=0,m=0;m<t.length;m++)if(o[m]){var s=void 0;for(s=c;s<r.length;s++)if(i[s]){c=s+1;break}t[m]!==r[s]&&y++}var b=(e/t.length+e/r.length+(e-y/2)/e)/3,p=0;if(b>.7){for(;t[p]===r[p]&&p<4;)p++;b+=.1*p*(1-b)}return b}}],(r=null)&&k(t.prototype,r),e&&k(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function E(t){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(t)}function M(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,I(n.key),n)}}function I(t){var r=function(t,r){if("object"!=E(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=E(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==E(r)?r:r+""}const C=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){if(0==t.length)return r.length;if(0==r.length)return t.length;for(var e=[],n=0;n<=r.length;n++)e[n]=[n];for(var o=0;o<=t.length;o++)e[0][o]=o;for(var i=1;i<=r.length;i++)for(var u=1;u<=t.length;u++)r.charAt(i-1)==t.charAt(u-1)?e[i][u]=e[i-1][u-1]:e[i][u]=Math.min(e[i-1][u-1]+1,Math.min(e[i][u-1]+1,e[i-1][u]+1));return e[r.length][t.length]}}],(r=null)&&M(t.prototype,r),e&&M(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function N(t){return N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},N(t)}function q(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,U(n.key),n)}}function U(t){var r=function(t,r){if("object"!=N(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=N(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==N(r)?r:r+""}const x=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){for(var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:-1,i=[],u=0;u<=t.length;u++){i[u]=[];for(var a=0;a<=r.length;a++)i[u][a]=0}for(var l=1;l<=t.length;l++)for(var f=1;f<=r.length;f++)i[l][f]=Math.max(0,i[l-1][f]+o,i[l][f-1]+o,i[l-1][f-1]+(t[l-1]===r[f-1]?e:n));for(var c=0,y=0;y<=t.length;y++)for(var m=0;m<=r.length;m++)i[y][m]>c&&(c=i[y][m]);return c}}],(r=null)&&q(t.prototype,r),e&&q(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function z(t){return z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},z(t)}function D(t){return function(t){if(Array.isArray(t))return F(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return F(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return F(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function F(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function $(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Q(n.key),n)}}function Q(t){var r=function(t,r){if("object"!=z(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==z(r)?r:r+""}const J=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"similarity",value:function(t,r){var e=new Set(t),n=new Set(r),o=2*D(e).filter((function(t){return n.has(t)})).length/(e.size+n.size);return o}}],(r=null)&&$(t.prototype,r),e&&$(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function K(t){return K="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},K(t)}function V(t){return function(t){if(Array.isArray(t))return L(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return L(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return L(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function L(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function W(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_(n.key),n)}}function _(t){var r=function(t,r){if("object"!=K(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=K(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==K(r)?r:r+""}const H=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"generateTrigrams",value:function(t){for(var r=[],e=0;e<t.length-2;e++)r.push(t.slice(e,e+3));return r}},{key:"similarity",value:function(t,r){var e=this.generateTrigrams(t),n=this.generateTrigrams(r),o=e.filter((function(t){return n.includes(t)})),i=V(new Set([].concat(V(e),V(n))));return 0===i.length?0:o.length/i.length}}],(r=null)&&W(t.prototype,r),e&&W(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function B(t){return B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},B(t)}function G(t){return function(t){if(Array.isArray(t))return R(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return R(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return R(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function X(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Y(n.key),n)}}function Y(t){var r=function(t,r){if("object"!=B(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=B(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==B(r)?r:r+""}const Z=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"overlap",value:function(t,r){if(!t||!r)throw new Error("Missing data for Szymkiewicz-Simpson Overlap coefficient calculation");var e=t.filter((function(t){return r.includes(t)})),n=new Set([].concat(G(t),G(r)));return e.length/n.size}}],(r=null)&&X(t.prototype,r),e&&X(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function tt(t){return tt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tt(t)}function rt(t){return function(t){if(Array.isArray(t))return et(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return et(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return et(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function et(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function nt(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,ot(n.key),n)}}function ot(t){var r=function(t,r){if("object"!=tt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=tt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==tt(r)?r:r+""}const it=function(){return t=function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t),this.n=r},(r=[{key:"calculateSimilarity",value:function(t,r){var e=this.getNgrams(t),n=this.getNgrams(r),o=this.getIntersection(e,n),i=this.getUnion(e,n);return o.length/i.length}},{key:"getNgrams",value:function(t){for(var r=[],e=0;e<t.length-this.n+1;e++)r.push(t.substring(e,e+this.n));return r}},{key:"getIntersection",value:function(t,r){return t.filter((function(t){return r.includes(t)}))}},{key:"getUnion",value:function(t,r){return rt(new Set([].concat(rt(t),rt(r))))}}])&&nt(t.prototype,r),e&&nt(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function ut(t){return ut="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ut(t)}function at(t){return function(t){if(Array.isArray(t))return lt(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(!t)return;if("string"==typeof t)return lt(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return lt(t,r)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function lt(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function ft(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,ct(n.key),n)}}function ct(t){var r=function(t,r){if("object"!=ut(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=ut(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==ut(r)?r:r+""}const yt=function(){return t=function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t),this.q=r},(r=[{key:"calculateSimilarity",value:function(t,r){var e=this.getQgrams(t),n=this.getQgrams(r),o=this.getIntersection(e,n),i=this.getUnion(e,n);return o.length/i.length}},{key:"getQgrams",value:function(t){for(var r=[],e=0;e<t.length-this.q+1;e++)r.push(t.substring(e,e+this.q));return r}},{key:"getIntersection",value:function(t,r){return t.filter((function(t){return r.includes(t)}))}},{key:"getUnion",value:function(t,r){return at(new Set([].concat(at(t),at(r))))}}])&&ft(t.prototype,r),e&&ft(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();function mt(t){return mt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},mt(t)}function st(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,bt(n.key),n)}}function bt(t){var r=function(t,r){if("object"!=mt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=mt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==mt(r)?r:r+""}const pt=function(){return t=function t(){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t)},e=[{key:"calculate",value:function(t,r){for(var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=t.length+1,o=r.length+1,i=[],u=0;u<n;u++)i[u]=new Array(o).fill(u*e);for(var a=0;a<o;a++)i[0][a]=a*e;for(var l=1;l<n;l++)for(var f=1;f<o;f++){var c=t[l-1]===r[f-1]?0:1;i[l][f]=Math.min(i[l-1][f]+e,i[l][f-1]+e,i[l-1][f-1]+c)}return i[n-1][o-1]}}],(r=null)&&st(t.prototype,r),e&&st(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,e}();return r})()));