/**
* Fuzzion
* Fuzzy / approximate string similarity metrics for PHP, JavaScript, Python
*
* @version: 1.0.0
* https://github.com/foo123/Fuzzion
*
**/
!function(e,r,t){"use strict";"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[r]=t.call(e)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(r)?define(r,["module"],function(r){return t.moduleUri=r.uri,t.call(e)}):r in e||(e[r]=t.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[r]})}("undefined"!=typeof self?self:this,"Fuzzion",function(r){"use strict";function e(){}e.VERSION="1.0.0",e.prototype={constructor:e,ident:function(r,e){return r===e?1:0},levenshtein:function(r,e){var t,n,o,f,i,a,u,c=r.length,h=e.length;if(0===c||0===h)return 0===c&&0===h?1:0;for(c<h&&(i=r,r=e,e=i,i=c,c=h,h=i),n=new Array(h+1),t=new Array(h+1),u=0;u<=h;++u)t[u]=u;for(a=1;a<=c;++a)for(i=t,t=n,n=i,t[0]=n[0]=a-1,o=r.charAt(a-1),u=1;u<=h;++u)f=e.charAt(u-1),t[u]=y(n[u]+1,t[u-1]+1,n[u-1]+(o===f?0:1));return 1-t[h]/c},damerau:function(r,e){var t,n,o,f,i,a,u,c,h=r.length,l=e.length;if(0===h||0===l)return 0===h&&0===l?1:0;for(h<l&&(i=r,r=e,e=i,i=h,h=l,l=i),n=new Array(l+1),t=new Array(l+1),u=0;u<=l;++u)t[u]=u;for(a=1;a<=h;++a)for(o=n.slice(),i=t,t=n,n=i,t[0]=n[0]=a-1,f=r.charAt(a-1),u=1;u<=l;++u)c=e.charAt(u-1),t[u]=y(n[u]+1,t[u-1]+1,n[u-1]+(c=f===c?0:1)),1<a&&1<u&&r.charAt(a-1)===e.charAt(u-2)&&r.charAt(a-2)===e.charAt(u-1)&&(t[u]=y(t[u],o[u-2]+c));return 1-t[l]/h},lcs:function(r,e){var t,n,o,f,i,a,u,c=r.length,h=e.length;if(0===c||0===h)return 0===c&&0===h?1:0;for(c<h&&(i=r,r=e,e=i,i=c,c=h,h=i),n=new Array(h),t=new Array(h),a=0;a<c;++a)for(i=t,t=n,n=i,o=r.charAt(a),u=0;u<h;++u)f=e.charAt(u),t[u]=o===f?(0===a||0===u?0:n[u-1])+1:v(0===u?0:t[u-1],0===a?0:n[u]);return 1-(c+h-2*t[h-1])/c},hamming:function(r,e){var t,n,o,f=r.length,i=e.length;if(0===f||0===i)return 0===f&&0===i?1:0;for(t=y(f,i),n=(f=v(f,i))-t,o=0;o<t;++o)r.charAt(o)!==e.charAt(o)&&++n;return 1-n/f},jaro:function(r,e){var t,n,o,f,i,a,u,c,h,l,A,g,d,s,p=r.length,m=e.length;if(0===p||0===m)return 0===p&&0===m?1:0;for(i=v(p,m)/2-1,a=new Array(p),u=new Array(m),l=h=c=0;l<p;++l)for(g=w(v(0,l-i)),d=w(y(l+i+1,m)),A=g;A<d;++A)if(!u[A]&&r.charAt(l)===e.charAt(A)){a[l]=!0,u[A]=!0,++c;break}if(0===c)n=0;else{for(l=A=0;l<p;++l)if(a[l]){for(;!u[A];)++A;r.charAt(l)!==e.charAt(A)&&++h,++A}n=(c/p+c/m+(c-(h/=2))/c)/3}if(n<.5)o=n;else{for(s=0,t=y(p,m),l=0;l<t&&r.charAt(l)===e.charAt(l);++l)++s;o=(f=y(.1,1/v(p,m))*s)+n*(1-f)}return o},jaccard:function(r,e){var t,n,o,f,i,a=r.length,u=e.length;if(0===a||0===u)return 0===a&&0===u?1:0;for(t={},f=o=n=0;f<a;++f)p(t,i=r.charAt(f))&&1===t[i]||(t[i]=1,++o);for(f=0;f<u;++f)p(t,i=e.charAt(f))&&1===t[i]?++n:++o;return n/o},overlap:function(r,e){var t,n,o,f,i=r.length,a=e.length;if(0===i||0===a)return 0===i&&0===a?1:0;for(t={},o=n=0;o<i;++o)p(t,f=r.charAt(o))&&1===t[f]||(t[f]=1);for(o=0;o<a;++o)p(t,f=e.charAt(o))&&1===t[f]&&++n;return n/y(i,a)},ngram:function(r,e,t){var n,o,f,i,a,u,c,h,l,A,g=r.length,d=e.length;if(0===g||0===d)return 0===g&&0===d?1:0;for(i in o=this.get_ngram(r,t=null==t?2:t),f=this.get_ngram(e,t),o[""]<f[""]&&(g=o,o=f,f=g),n=0,f)if(p(o,i)&&""!==i)for(c=(a=o[i]).length,h=(u=f[i]).length,A=l=0;l<c&&A<h;)t>=s(u[A]-a[l])&&++n,++l,++A;return 2*n/(o[""]+f[""])},get_ngram:function(r,e){for(var t,n=r.length-e+1,o={},f=0;f<n;++f)p(o,t=r.slice(f,f+e))||(o[t]=[]),o[t].push(f);return o[""]=n,o}};var t=Math,y=t.min,v=t.max,s=t.abs,w=t.floor,n=Object.prototype.hasOwnProperty;Object.prototype.toString;function p(r,e){return n.call(r,e)}return e});
|