diff --git a/builds/compromise-tokenize.js b/builds/compromise-tokenize.js index ffdfcf0d9..05c8fedf9 100644 --- a/builds/compromise-tokenize.js +++ b/builds/compromise-tokenize.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).nlp=e()}(this,(function(){"use strict";function t(e){return(t="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)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;rr?n:r)+1;if(Math.abs(r-n)>(i||100))return i||100;for(var o,s,a,u,c,h,l=[],f=0;f4)return r;u=s===(a=e[o-1])?0:1,c=l[v-1][o]+1,(h=l[v][o-1]+1)1&&o>1&&s===e[o-2]&&t[v-2]===a&&(h=l[v-2][o-2]+u)2&&void 0!==arguments[2]?arguments[2]:3;if(t===e)return 1;if(t.lengthe.fuzzy)return!0;if(!0===e.soft&&(i=B(e.word,t.root))>e.fuzzy)return!0}return e.word===t.clean||e.word===t.text||e.word===t.reduced}return void 0!==e.tag?!0===t.tags[e.tag]:void 0!==e.method?"function"==typeof t[e.method]&&!0===t[e.method]():void 0!==e.regex?e.regex.test(t.clean):void 0!==e.fastOr?!(!t.implicit||!0!==e.fastOr.hasOwnProperty(t.implicit))||(e.fastOr.hasOwnProperty(t.reduced)||e.fastOr.hasOwnProperty(t.text)):void 0!==e.choices&&("and"===e.operator?e.choices.every((function(e){return I(t,e,r,n)})):e.choices.some((function(e){return I(t,e,r,n)})))},z=I=function(t,e,r,n){var i=S(t,e,r,n);return!0===e.negative?!i:i},D={},_={doesMatch:function(t,e,r){return z(this,t,e,r)},isAcronym:function(){return b(this.text)},isImplicit:function(){return""===this.text&&Boolean(this.implicit)},isKnown:function(){return Object.keys(this.tags).some((function(t){return!0!==D[t]}))},setRoot:function(t){var e=t.transforms,r=this.implicit||this.clean;if(this.tags.Plural&&(r=e.toSingular(r,t)),this.tags.Verb&&!this.tags.Negative&&!this.tags.Infinitive){var n=null;this.tags.PastTense?n="PastTense":this.tags.Gerund?n="Gerund":this.tags.PresentTense?n="PresentTense":this.tags.Participle?n="Participle":this.tags.Actor&&(n="Actor"),r=e.toInfinitive(r,t,n)}this.root=r}},M=/[\s-]/,G=/^[A-Z-]+$/,q={textOut:function(t,e,r){t=t||{};var n=this.text,i=this.pre,o=this.post;return!0===t.reduced&&(n=this.reduced||""),!0===t.root&&(n=this.root||""),!0===t.implicit&&this.implicit&&(n=this.implicit||""),!0===t.normal&&(n=this.clean||this.text||""),!0===t.root&&(n=this.root||this.reduced||""),!0===t.unicode&&(n=p(n)),!0===t.titlecase&&(this.tags.ProperNoun&&!this.titleCase()||(this.tags.Acronym?n=n.toUpperCase():G.test(n)&&!this.tags.Acronym&&(n=n.toLowerCase()))),!0===t.lowercase&&(n=n.toLowerCase()),!0===t.acronyms&&this.tags.Acronym&&(n=n.replace(/\./g,"")),!0!==t.whitespace&&!0!==t.root||(i="",o=" ",!1!==M.test(this.post)&&!t.last||this.implicit||(o="")),!0!==t.punctuation||t.root||(!0===this.hasPost(".")?o="."+o:!0===this.hasPost("?")?o="?"+o:!0===this.hasPost("!")?o="!"+o:!0===this.hasPost(",")?o=","+o:!0===this.hasEllipses()&&(o="..."+o)),!0!==e&&(i=""),!0!==r&&(o=""),!0===t.abbreviations&&this.tags.Abbreviation&&(o=o.replace(/^\./,"")),i+n+o}},L={Auxiliary:1,Possessive:1},W=function(t,e){var r=Object.keys(t.tags),n=e.tags;return r=r.sort((function(t,e){return L[e]||!n[e]?-1:n[e]?n[t]?n[t].lineage.length>n[e].lineage.length?1:n[t].isA.length>n[e].isA.length?-1:0:0:1}))},U={text:!0,tags:!0,implicit:!0,whitespace:!0,clean:!1,id:!1,index:!1,offset:!1,bestTag:!1},R={json:function(t,e){t=t||{};var r={};return(t=Object.assign({},U,t)).text&&(r.text=this.text),t.normal&&(r.normal=this.clean),t.tags&&(r.tags=Object.keys(this.tags)),t.clean&&(r.clean=this.clean),(t.id||t.offset)&&(r.id=this.id),t.implicit&&null!==this.implicit&&(r.implicit=this.implicit),t.whitespace&&(r.pre=this.pre,r.post=this.post),t.bestTag&&(r.bestTag=W(this,e)[0]),r}},H=Object.assign({},N,$,_,q,R);function Q(){return"undefined"!=typeof window&&window.document}var Z=function(t,e){for(t=t.toString();t.length0&&void 0!==arguments[0]?arguments[0]:"";e(this,t),r=String(r);var n=F(r);this.text=n.text||"",this.clean=n.clean,this.reduced=n.reduced,this.root=null,this.implicit=null,this.pre=n.pre||"",this.post=n.post||"",this.tags={},this.prev=null,this.next=null,this.id=h(n.clean),this.isA="Term",n.alias&&(this.alias=n.alias)}return n(t,[{key:"set",value:function(t){var e=F(t);return this.text=e.text,this.clean=e.clean,this}}]),t}();st.prototype.clone=function(){var t=new st(this.text);return t.pre=this.pre,t.post=this.post,t.clean=this.clean,t.reduced=this.reduced,t.root=this.root,t.implicit=this.implicit,t.tags=Object.assign({},this.tags),t},Object.assign(st.prototype,H),Object.assign(st.prototype,ot);var at=st,ut={terms:function(t){if(0===this.length)return[];if(this.cache.terms)return void 0!==t?this.cache.terms[t]:this.cache.terms;for(var e=[this.pool.get(this.start)],r=0;r0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0;"string"==typeof t&&(t="normal"===t?{whitespace:!0,unicode:!0,lowercase:!0,punctuation:!0,acronyms:!0,abbreviations:!0,implicit:!0,normal:!0}:"clean"===t?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,normal:!0}:"reduced"===t?{punctuation:!1,titlecase:!1,lowercase:!0,whitespace:!0,unicode:!0,implicit:!0,reduced:!0}:"implicit"===t?{punctuation:!0,implicit:!0,whitespace:!0,trim:!0}:"root"===t?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,root:!0}:{});var n=this.terms(),i=!1;n[0]&&null===n[0].prev&&null===n[n.length-1].next&&(i=!0);var o=n.reduce((function(o,s,a){if(0===a&&""===s.text&&null!==s.implicit&&!t.implicit)return o;t.last=r&&a===n.length-1;var u=!0,c=!0;return!1===i&&(0===a&&e&&(u=!1),a===n.length-1&&r&&(c=!1)),o+s.textOut(t,u,c)}),"");return!0===i&&r&&(o=ct(o)),!0===t.trim&&(o=o.trim()),o}},lt={trim:function(){var t=this.terms();if(t.length>0){t[0].pre=t[0].pre.replace(/^\s+/,"");var e=t[t.length-1];e.post=e.post.replace(/\s+$/,"")}return this}},ft=/[.?!]\s*$/,pt=function(t,e){e[0].pre=t[0].pre;var r,n,i=t[t.length-1],o=e[e.length-1];o.post=(r=i.post,n=o.post,ft.test(n)?n+r.match(/\s*$/):r),i.post="",""===i.post&&(i.post+=" ")},vt=function(t,e,r){var n=t.terms(),i=e.terms();pt(n,i),function(t,e,r){var n=t[t.length-1],i=e[e.length-1],o=n.next;n.next=e[0].id,i.next=o,o&&(r.get(o).prev=i.id);var s=t[0].id;s&&(e[0].prev=s)}(n,i,t.pool);var o,s=[t],a=t.start,u=[r];return(u=u.concat(r.parents())).forEach((function(t){var e=t.list.filter((function(t){return t.hasId(a)}));s=s.concat(e)})),(s=(o=s).filter((function(t,e){return o.indexOf(t)===e}))).forEach((function(t){t.length+=e.length})),t.cache={},t},dt=/ /,mt=function(t,e,r){var n=t.start,i=e.terms();!function(t){var e=t[t.length-1];!1===dt.test(e.post)&&(e.post+=" ")}(i),function(t,e,r){var n=r[r.length-1];n.next=t.start;var i=t.pool,o=i.get(t.start);o.prev&&(i.get(o.prev).next=e.start),r[0].prev=t.terms(0).prev,t.terms(0).prev=n.id}(t,e,i);var o,s=[t],a=[r];return(a=a.concat(r.parents())).forEach((function(t){var r=t.list.filter((function(t){return t.hasId(n)||t.hasId(e.start)}));s=s.concat(r)})),(s=(o=s).filter((function(t,e){return o.indexOf(t)===e}))).forEach((function(t){t.length+=e.length,t.start===n&&(t.start=e.start),t.cache={}})),t},gt=function(t,e){var r=e.pool(),n=t.terms(),i=r.get(n[0].prev)||{},o=r.get(n[n.length-1].next)||{};n[0].implicit&&i.implicit&&(i.set(i.implicit),i.post+=" "),function(t,e,r,n){var i=t.parents();i.push(t),i.forEach((function(t){var i=t.list.find((function(t){return t.hasId(e)}));i&&(i.length-=r,i.start===e&&(i.start=n.id),i.cache={})})),t.list=t.list.filter((function(t){return!(!t.start||!t.length)}))}(e,t.start,t.length,o),i&&(i.next=o.id),o&&(o.prev=i.id)},bt={append:function(t,e){return vt(this,t,e),this},prepend:function(t,e){return mt(this,t,e),this},delete:function(t){return gt(this,t),this},replace:function(t,e){var r=this.length;vt(this,t,e);var n=this.buildFrom(this.start,this.length);n.length=r,gt(n,e)},splitOn:function(t){var e=this.terms(),r={before:null,match:null,after:null},n=e.findIndex((function(e){return e.id===t.start}));if(-1===n)return r;var i=e.slice(0,n);i.length>0&&(r.before=this.buildFrom(i[0].id,i.length));var o=e.slice(n,n+t.length);o.length>0&&(r.match=this.buildFrom(o[0].id,o.length));var s=e.slice(n+t.length,e.length);return s.length>0&&(r.after=this.buildFrom(s[0].id,s.length,this.pool)),r}},yt={json:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,r={};return t.text&&(r.text=this.text()),t.normal&&(r.normal=this.text("normal")),t.clean&&(r.clean=this.text("clean")),t.reduced&&(r.reduced=this.text("reduced")),t.implicit&&(r.implicit=this.text("implicit")),t.root&&(r.root=this.text("root")),t.trim&&(r.text&&(r.text=r.text.trim()),r.normal&&(r.normal=r.normal.trim()),r.reduced&&(r.reduced=r.reduced.trim())),t.terms&&(!0===t.terms&&(t.terms={}),r.terms=this.terms().map((function(r){return r.json(t.terms,e)}))),r}},At={lookAhead:function(t){t||(t=".*");var e=this.pool,r=[],n=this.terms();return function t(n){var i=e.get(n);i&&(r.push(i),i.prev&&t(i.next))}(n[n.length-1].next),0===r.length?[]:this.buildFrom(r[0].id,r.length).match(t)},lookBehind:function(t){t||(t=".*");var e=this.pool,r=[];return function t(n){var i=e.get(n);i&&(r.push(i),i.prev&&t(i.prev))}(e.get(this.start).prev),0===r.length?[]:this.buildFrom(r[r.length-1].id,r.length).match(t)}},wt=Object.assign({},ut,ht,lt,bt,yt,At),xt=function(t,e){if(0===e.length)return!0;for(var r=0;r0)return!0;if(!0===n.anything&&!0===n.negative)return!0}return!1},Pt=T((function(t,e){e.getGreedy=function(t,e){for(var r=Object.assign({},t.regs[t.r],{start:!1,end:!1}),n=t.t;t.t1&&void 0!==arguments[1]?arguments[1]:0,n=t.regs[t.r],i=!1,o=0;oe&&(e=r.length),n}))&&e},e.getGroup=function(t,e,r){if(t.groups[t.groupId])return t.groups[t.groupId];var n=t.terms[e].id;return t.groups[t.groupId]={group:String(r),start:n,length:0},t.groups[t.groupId]}})),jt=function(t,e,r,n){for(var i={t:0,terms:t,r:0,regs:e,groups:{},start_i:r,phrase_length:n,hasGroup:!1,groupId:null,previousGroup:null};i.ri.t)return null;if(!0===o.end&&i.start_i+i.t!==n)return null}if(!0===i.hasGroup){var d=Pt.getGroup(i,f,o.named);i.t>1&&o.greedy?d.length+=i.t-f:d.length++}}else{if(o.negative){var m=Object.assign({},o);if(m.negative=!1,!0===i.terms[i.t].doesMatch(m,i.start_i+i.t,i.phrase_length))return null}if(!0!==o.optional){if(i.terms[i.t].isImplicit()&&e[i.r-1]&&i.terms[i.t+1]){if(i.terms[i.t-1]&&i.terms[i.t-1].implicit===e[i.r-1].word)return null;if(i.terms[i.t+1].doesMatch(o,i.start_i+i.t,i.phrase_length)){i.t+=2;continue}}return null}}}else{var g=Pt.greedyTo(i,e[i.r+1]);if(void 0!==o.min&&g-i.to.max){i.t=i.t+o.max;continue}if(null===g)return null;!0===i.hasGroup&&(Pt.getGroup(i,i.t,o.named).length=g-i.t),i.t=g}}return{match:i.terms.slice(0,i.t),groups:i.groups}},Et=function(t,e,r){if(!r||0===r.length)return r;if(e.some((function(t){return t.end}))){var n=t[t.length-1];r=r.filter((function(t){return-1!==t.match.indexOf(n)}))}return r},Ot=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/g,kt=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g,Ct=/ /g,Ft=function(t){return t=(t=t.map((function(t){return t.trim()}))).filter((function(t){return t}))},Tt=function(t){var e=t.split(Ot),r=[];e.forEach((function(t){r=r.concat(t.split(kt))})),r=Ft(r);var n=[];return r.forEach((function(t){!function(t){return/^[\!\[\^]*(<[^<]*>)?\(/.test(t)&&/\)[\?\]\+\*\$~]*$/.test(t)}(t)&&!function(t){return/^[\!\[\^]*(<[^<]*>)?\//.test(t)&&/\/[\?\]\+\*\$~]*$/.test(t)}(t)?n=n.concat(t.split(Ct)):n.push(t)})),n=Ft(n)},Nt=/\{([0-9]+,?[0-9]*)\}/,$t=/&&/,Vt=new RegExp(/^< *?(\S+) *?>/),Bt=function(t){return t[t.length-1]},It=function(t){return t[0]},St=function(t){return t.substr(1)},zt=function(t){return t.substr(0,t.length-1)},Dt=function(t){return t=St(t),t=zt(t)},_t=function t(e){for(var r,n={},i=0;i<2;i+=1){if("$"===Bt(e)&&(n.end=!0,e=zt(e)),"^"===It(e)&&(n.start=!0,e=St(e)),("["===It(e)||"]"===Bt(e))&&(n.named=!0,"["===It(e)?n.groupType="]"===Bt(e)?"single":"start":n.groupType="end",e=(e=e.replace(/^\[/,"")).replace(/\]$/,""),"<"===It(e))){var o=Vt.exec(e);o.length>=2&&(n.named=o[1],e=e.replace(o[0],""))}if("+"===Bt(e)&&(n.greedy=!0,e=zt(e)),"*"!==e&&"*"===Bt(e)&&"\\*"!==e&&(n.greedy=!0,e=zt(e)),"?"===Bt(e)&&(n.optional=!0,e=zt(e)),"!"===It(e)&&(n.negative=!0,e=St(e)),"("===It(e)&&")"===Bt(e)){$t.test(e)?(n.choices=e.split($t),n.operator="and"):(n.choices=e.split("|"),n.operator="or"),n.choices[0]=St(n.choices[0]);var s=n.choices.length-1;n.choices[s]=zt(n.choices[s]),n.choices=n.choices.map((function(t){return t.trim()})),n.choices=n.choices.filter((function(t){return t})),n.choices=n.choices.map((function(e){return e.split(/ /g).map(t)})),e=""}if("/"===It(e)&&"/"===Bt(e))return e=Dt(e),n.regex=new RegExp(e),n;if("~"===It(e)&&"~"===Bt(e))return e=Dt(e),n.soft=!0,n.word=e,n}return!0===Nt.test(e)&&(e=e.replace(Nt,(function(t,e){var r=e.split(/,/g);return 1===r.length?(n.min=Number(r[0]),n.max=Number(r[0])):(n.min=Number(r[0]),n.max=Number(r[1]||999)),n.greedy=!0,n.optional=!0,""}))),"#"===It(e)?(n.tag=St(e),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===It(e)?(n.method=St(e),n):"."===e?(n.anything=!0,n):"*"===e?(n.anything=!0,n.greedy=!0,n.optional=!0,n):(e&&(e=(e=e.replace("\\*","*")).replace("\\.","."),n.word=e.toLowerCase()),n)},Mt=function(t){for(var e,r=!1,n=-1,i=0;i1&&void 0!==arguments[1]?arguments[1]:{},r=t.filter((function(t){return t.groupType})).length;return r>0&&(t=Mt(t)),e.fuzzy||(t=Gt(t)),t},Lt=function(t){return"[object Array]"===Object.prototype.toString.call(t)},Wt=function(t){return[{choices:t.map((function(t){return[{word:t}]})),operator:"or"}]},Ut=function(t){if(!t||!t.list||!t.list[0])return[];var e=[];return t.list.forEach((function(t){var r=[];t.terms().forEach((function(t){r.push(t.id)})),e.push(r)})),[{idBlocks:e}]},Rt=function(t,e){return!0===e.fuzzy&&(e.fuzzy=.85),"number"==typeof e.fuzzy&&(t=t.map((function(t){return e.fuzzy>0&&t.word&&(t.fuzzy=e.fuzzy),t.choices&&t.choices.forEach((function(t){t.forEach((function(t){t.fuzzy=e.fuzzy}))})),t}))),t},Ht=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null==e||""===e)return[];if("object"===t(e)){if(Lt(e)){if(0===e.length||!e[0])return[];if("object"===t(e[0]))return e;if("string"==typeof e[0])return Wt(e)}return e&&"Doc"===e.isA?Ut(e):[]}"number"==typeof e&&(e=String(e));var n=Tt(e);return n=n.map((function(t){return _t(t)})),n=qt(n,r),n=Rt(n,r)},Qt=function(t,e){for(var r=[],n=e[0].idBlocks,i=function(e){n.forEach((function(n){0!==n.length?n.every((function(r,n){return o=e,t[e+n].id===r}))&&(r.push({match:t.slice(e,e+n.length)}),e+=n.length-1):o=e})),o=e},o=0;o2&&void 0!==arguments[2]&&arguments[2];if("string"==typeof e&&(e=Ht(e)),!0===xt(t,e))return[];var n=e.filter((function(t){return!0!==t.optional&&!0!==t.negative})).length,i=t.terms(),o=[];if(e[0].idBlocks){var s=Qt(i,e);if(s&&s.length>0)return Et(i,e,s)}if(!0===e[0].start){var a=jt(i,e,0,i.length);return a&&a.match&&a.match.length>0&&(a.match=a.match.filter((function(t){return t})),o.push(a)),Et(i,e,o)}for(var u=0;ui.length);u+=1){var c=jt(i.slice(u),e,u,i.length);if(c&&c.match&&c.match.length>0&&(u+=c.match.length-1,c.match=c.match.filter((function(t){return t})),o.push(c),!0===r))return Et(i,e,o)}return Et(i,e,o)},Jt=function(t,e){var r={};Zt(t,e).forEach((function(t){t.match.forEach((function(t){r[t.id]=!0}))}));var n=t.terms(),i=[],o=[];return n.forEach((function(t){!0!==r[t.id]?o.push(t):o.length>0&&(i.push(o),o=[])})),o.length>0&&i.push(o),i},Yt={match:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=Zt(this,t,r);return n=n.map((function(t){var r=t.match,n=t.groups,i=e.buildFrom(r[0].id,r.length,n);return i.cache.terms=r,i}))},has:function(t){return Zt(this,t,!0).length>0},not:function(t){var e=this,r=Jt(this,t);return r=r.map((function(t){return e.buildFrom(t[0].id,t.length)}))},canBe:function(t,e){for(var r=this,n=[],i=this.terms(),o=!1,s=0;s0})).map((function(t){return r.buildFrom(t[0].id,t.length)}))}},Kt=function t(r,n,i){e(this,t),this.start=r,this.length=n,this.isA="Phrase",Object.defineProperty(this,"pool",{enumerable:!1,writable:!0,value:i}),Object.defineProperty(this,"cache",{enumerable:!1,writable:!0,value:{}}),Object.defineProperty(this,"groups",{enumerable:!1,writable:!0,value:{}})};Kt.prototype.buildFrom=function(t,e,r){var n=new Kt(t,e,this.pool);return r&&Object.keys(r).length>0?n.groups=r:n.groups=this.groups,n},Object.assign(Kt.prototype,Yt),Object.assign(Kt.prototype,wt);var Xt={term:"terms"};Object.keys(Xt).forEach((function(t){return Kt.prototype[t]=Kt.prototype[Xt[t]]}));var te=Kt,ee=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e(this,t),Object.defineProperty(this,"words",{enumerable:!1,value:r})}return n(t,[{key:"add",value:function(t){return this.words[t.id]=t,this}},{key:"get",value:function(t){return this.words[t]}},{key:"remove",value:function(t){delete this.words[t]}},{key:"merge",value:function(t){return Object.assign(this.words,t.words),this}},{key:"stats",value:function(){return{words:Object.keys(this.words).length}}}]),t}();ee.prototype.clone=function(){var t=this,e=Object.keys(this.words).reduce((function(e,r){var n=t.words[r].clone();return e[n.id]=n,e}),{});return new ee(e)};var re=ee,ne=function(t){t.forEach((function(e,r){r>0&&(e.prev=t[r-1].id),t[r+1]&&(e.next=t[r+1].id)}))},ie=/(\S.+?[.!?\u203D\u2E18\u203C\u2047-\u2049])(?=\s+|$)/g,oe=/\S/,se=/[ .][A-Z]\.? *$/i,ae=/(?:\u2026|\.{2,}) *$/,ue=/((?:\r?\n|\r)+)/,ce=/[a-z0-9\u00C0-\u00FF\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/i,he=/^\s+/,le=function(t,e){if(!0===se.test(t))return!1;if(!0===ae.test(t))return!1;if(!1===ce.test(t))return!1;var r=t.replace(/[.!?\u203D\u2E18\u203C\u2047-\u2049] *$/,"").split(" "),n=r[r.length-1].toLowerCase();return!e.hasOwnProperty(n)},fe=function(t,e){var r=e.cache.abbreviations;t=t||"";var n=[],i=[];if(!(t=String(t))||"string"!=typeof t||!1===oe.test(t))return n;for(var o=function(t){for(var e=[],r=t.split(ue),n=0;n0&&(n.push(c),i[u]="")}if(0===n.length)return[t];for(var h=1;h0?(e[e.length-1]+=o,e.push(a)):e.push(o+a),o=""):o+=a}return o&&(0===e.length&&(e[0]=""),e[e.length-1]+=o),e=(e=function(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,n=null;"string"!=typeof t&&("number"==typeof t?t=String(t):we(t)&&(n=t)),n=(n=n||fe(t,e)).map((function(t){return Ae(t)})),r=r||new re;var i=n.map((function(t){t=t.map((function(t){var e=new at(t);return r.add(e),e})),ne(t);var e=new te(t[0].id,t.length,r);return e.cache.terms=t,e}));return i},Pe=function(t,e){var r=new re;return t.map((function(t,n){var i=t.terms.map((function(i,o){var s=new at(i.text);return s.pre=void 0!==i.pre?i.pre:"",void 0===i.post&&(i.post=" ",o>=t.terms.length-1&&(i.post=". ",n>=t.terms.length-1&&(i.post="."))),s.post=void 0!==i.post?i.post:" ",i.tags&&i.tags.forEach((function(t){return s.tag(t,"",e)})),r.add(s),s}));return ne(i),new te(i[0].id,i.length,r)}))},je=["Person","Place","Organization"],Ee={Noun:{notA:["Verb","Adjective","Adverb"]},Singular:{isA:"Noun",notA:"Plural"},ProperNoun:{isA:"Noun"},Person:{isA:["ProperNoun","Singular"],notA:["Place","Organization","Date"]},FirstName:{isA:"Person"},MaleName:{isA:"FirstName",notA:["FemaleName","LastName"]},FemaleName:{isA:"FirstName",notA:["MaleName","LastName"]},LastName:{isA:"Person",notA:["FirstName"]},NickName:{isA:"Person",notA:["FirstName","LastName"]},Honorific:{isA:"Noun",notA:["FirstName","LastName","Value"]},Place:{isA:"Singular",notA:["Person","Organization"]},Country:{isA:["Place","ProperNoun"],notA:["City"]},City:{isA:["Place","ProperNoun"],notA:["Country"]},Region:{isA:["Place","ProperNoun"]},Address:{isA:"Place"},Organization:{isA:["Singular","ProperNoun"],notA:["Person","Place"]},SportsTeam:{isA:"Organization"},School:{isA:"Organization"},Company:{isA:"Organization"},Plural:{isA:"Noun",notA:["Singular"]},Uncountable:{isA:"Noun"},Pronoun:{isA:"Noun",notA:je},Actor:{isA:"Noun",notA:je},Activity:{isA:"Noun",notA:["Person","Place"]},Unit:{isA:"Noun",notA:je},Demonym:{isA:["Noun","ProperNoun"],notA:je},Possessive:{isA:"Noun"}},Oe={Verb:{notA:["Noun","Adjective","Adverb","Value"]},PresentTense:{isA:"Verb",notA:["PastTense","FutureTense"]},Infinitive:{isA:"PresentTense",notA:["PastTense","Gerund"]},Imperative:{isA:"Infinitive"},Gerund:{isA:"PresentTense",notA:["PastTense","Copula","FutureTense"]},PastTense:{isA:"Verb",notA:["FutureTense"]},FutureTense:{isA:"Verb"},Copula:{isA:"Verb"},Modal:{isA:"Verb",notA:["Infinitive"]},PerfectTense:{isA:"Verb",notA:"Gerund"},Pluperfect:{isA:"Verb"},Participle:{isA:"PastTense"},PhrasalVerb:{isA:"Verb"},Particle:{isA:"PhrasalVerb"},Auxiliary:{notA:["Noun","Adjective","Value"]}},ke={Value:{notA:["Verb","Adjective","Adverb"]},Ordinal:{isA:"Value",notA:["Cardinal"]},Cardinal:{isA:"Value",notA:["Ordinal"]},Fraction:{isA:"Value",notA:["Noun"]},RomanNumeral:{isA:"Cardinal",notA:["Ordinal","TextValue"]},TextValue:{isA:"Value",notA:["NumericValue"]},NumericValue:{isA:"Value",notA:["TextValue"]},Money:{isA:"Cardinal"},Percent:{isA:"Value"}},Ce=["Noun","Verb","Adjective","Adverb","Value","QuestionWord"],Fe={Adjective:{notA:["Noun","Verb","Adverb","Value"]},Comparable:{isA:["Adjective"]},Comparative:{isA:["Adjective"]},Superlative:{isA:["Adjective"],notA:["Comparative"]},NumberRange:{isA:["Contraction"]},Adverb:{notA:["Noun","Verb","Adjective","Value"]},Date:{notA:["Verb","Adverb","Preposition","Adjective"]},Month:{isA:["Date","Singular"],notA:["Year","WeekDay","Time"]},WeekDay:{isA:["Date","Noun"]},Timezone:{isA:["Date","Noun"],notA:["Adjective","ProperNoun"]},Time:{isA:["Date"],notA:["AtMention"]},Determiner:{notA:Ce},Conjunction:{notA:Ce},Preposition:{notA:Ce},QuestionWord:{notA:["Determiner"]},Currency:{isA:["Noun"]},Expression:{notA:["Noun","Adjective","Verb","Adverb"]},Abbreviation:{},Url:{notA:["HashTag","PhoneNumber","Verb","Adjective","Value","AtMention","Email"]},PhoneNumber:{notA:["HashTag","Verb","Adjective","Value","AtMention","Email"]},HashTag:{},AtMention:{isA:["Noun"],notA:["HashTag","Verb","Adjective","Value","Email"]},Emoji:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Emoticon:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Email:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Acronym:{notA:["Plural","RomanNumeral"]},Negative:{notA:["Noun","Adjective","Value"]},Condition:{notA:["Verb","Adjective","Noun","Value"]}},Te={Noun:"blue",Verb:"green",Negative:"green",Date:"red",Value:"red",Adjective:"magenta",Preposition:"cyan",Conjunction:"cyan",Determiner:"cyan",Adverb:"cyan"},Ne=function(t){return Object.keys(t).forEach((function(e){t[e].color?t[e].color=t[e].color:Te[e]?t[e].color=Te[e]:t[e].isA.some((function(r){return!!Te[r]&&(t[e].color=Te[r],!0)}))})),t},$e=function(t){return Object.keys(t).forEach((function(e){for(var r=t[e],n=r.isA.length,i=0;i1&&(r.hasCompound[o[0]]=!0),void 0===Me[i]?void 0!==e[n]?("string"==typeof e[n]&&(e[n]=[e[n]]),"string"==typeof i?e[n].push(i):e[n]=e[n].concat(i)):e[n]=i:Me[i](e,n,r)}))},qe=function(t){var e=Object.assign({},De);return Object.keys(De).forEach((function(r){var n=De[r];Object.keys(n).forEach((function(t){n[t]=r})),Ge(n,e,t)})),e},Le=Ge,We=function(t){for(var e=t.irregulars.nouns,r=Object.keys(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:{};"string"!=typeof e&&"number"!=typeof e&&null!==e||(e={group:e});var r=Ht(t,e);if(0===r.length)return this.buildFrom([]);if(!1===Xe(this,r))return this.buildFrom([]);var n=this.list.reduce((function(t,e){return t.concat(e.match(r))}),[]);return void 0!==e.group&&null!==e.group&&""!==e.group?this.buildFrom(n).groups(e.group):this.buildFrom(n)},e.not=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e);if(0===r.length||!1===Xe(this,r))return this;var n=this.list.reduce((function(t,e){return t.concat(e.not(r))}),[]);return this.buildFrom(n)},e.matchOne=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e);if(!1===Xe(this,r))return this.buildFrom([]);for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e);if(!1===Xe(this,r))return this.buildFrom([]);var n=this.list.filter((function(t){return!0===t.has(r)}));return this.buildFrom(n)},e.ifNo=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e),n=this.list.filter((function(t){return!1===t.has(r)}));return this.buildFrom(n)},e.has=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e);return!1!==Xe(this,r)&&this.list.some((function(t){return!0===t.has(r)}))},e.lookAhead=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t||(t=".*");var r=Ht(t,e),n=[];return this.list.forEach((function(t){n=n.concat(t.lookAhead(r))})),n=n.filter((function(t){return t})),this.buildFrom(n)},e.lookAfter=e.lookAhead,e.lookBehind=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t||(t=".*");var r=Ht(t,e),n=[];return this.list.forEach((function(t){n=n.concat(t.lookBehind(r))})),n=n.filter((function(t){return t})),this.buildFrom(n)},e.lookBefore=e.lookBehind,e.before=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e),n=this.if(r).list,i=n.map((function(t){var e=t.terms().map((function(t){return t.id})),n=t.match(r)[0],i=e.indexOf(n.start);return 0===i||-1===i?null:t.buildFrom(t.start,i)}));return i=i.filter((function(t){return null!==t})),this.buildFrom(i)},e.after=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Ht(t,e),n=this.if(r).list,i=n.map((function(t){var e=t.terms(),n=e.map((function(t){return t.id})),i=t.match(r)[0],o=n.indexOf(i.start);if(-1===o||!e[o+i.length])return null;var s=e[o+i.length].id,a=t.length-o-i.length;return t.buildFrom(s,a)}));return i=i.filter((function(t){return null!==t})),this.buildFrom(i)},e.hasAfter=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookAfter(t,e).found}))},e.hasBefore=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookBefore(t,e).found}))}})),er=function(t,e,r,n){var i=[];"string"==typeof t&&(i=t.split(" ")),e.list.forEach((function(o){var s=o.terms();!0===r&&(s=s.filter((function(r){return r.canBe(t,e.world)}))),s.forEach((function(r,o){i.length>1?i[o]&&"."!==i[o]&&r.tag(i[o],n,e.world):r.tag(t,n,e.world)}))}))},rr={tag:function(t,e){return t?(er(t,this,!1,e),this):this},tagSafe:function(t,e){return t?(er(t,this,!0,e),this):this},unTag:function(t,e){var r=this;return this.list.forEach((function(n){n.terms().forEach((function(n){return n.unTag(t,e,r.world)}))})),this},canBe:function(t){if(!t)return this;var e=this.world,r=this.list.reduce((function(r,n){return r.concat(n.canBe(t,e))}),[]);return this.buildFrom(r)}},nr={map:function(e){var r=this;if(!e)return this;var n=this.list.map((function(t,n){var i=r.buildFrom([t]);i.from=null;var o=e(i,n);return o&&o.list&&o.list[0]?o.list[0]:o}));return 0===(n=n.filter((function(t){return t}))).length?this.buildFrom(n):"object"!==t(n[0])||"Phrase"!==n[0].isA?n:this.buildFrom(n)},forEach:function(t,e){var r=this;return t?(this.list.forEach((function(n,i){var o=r.buildFrom([n]);!0===e&&(o.from=null),t(o,i)})),this):this},filter:function(t){var e=this;if(!t)return this;var r=this.list.filter((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)}));return this.buildFrom(r)},find:function(t){var e=this;if(!t)return this;var r=this.list.find((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)}));return r?this.buildFrom([r]):void 0},some:function(t){var e=this;return t?this.list.some((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)})):this},random:function(t){if(!this.found)return this;var e=Math.floor(Math.random()*this.list.length);if(void 0===t){var r=[this.list[e]];return this.buildFrom(r)}return e+t>this.length&&(e=(e=this.length-t)<0?0:e),this.slice(e,e+t)}},ir=function(t){return t.split(/[ -]/g)},or=function(t,e,r){for(var n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r={};return t.forEach((function(t,n){var i=!0;void 0!==e[n]&&(i=e[n]),t=(t=(t||"").toLowerCase()).replace(/[,;.!?]+$/,"");var o=ir(t).map((function(t){return t.trim()}));r[o[0]]=r[o[0]]||{},1===o.length?r[o[0]].value=i:(r[o[0]].more=r[o[0]].more||[],r[o[0]].more.push({rest:o.slice(1),value:i}))})),r}(t,e),i=[],o=function(t){for(var e=r.list[t],o=e.terms().map((function(t){return t.reduced})),s=function(t){void 0!==n[o[t]]&&(void 0!==n[o[t]].more&&n[o[t]].more.forEach((function(r){void 0!==o[t+r.rest.length]&&(!0===r.rest.every((function(e,r){return e===o[t+r+1]}))&&i.push({id:e.terms()[t].id,value:r.value,length:r.rest.length+1}))})),void 0!==n[o[t]].value&&i.push({id:e.terms()[t].id,value:n[o[t]].value,length:1}))},a=0;a1&&void 0!==arguments[1]?arguments[1]:{};return e?(!0===n&&(n={keepTags:!0}),!1===n&&(n={keepTags:!1}),n=n||{},this.uncache(),this.list.forEach((function(i){var o,s=e;if("function"==typeof e&&(s=e(i)),s&&"object"===t(s)&&"Doc"===s.isA)o=s.list,r.pool().merge(s.pool());else{if("string"!=typeof s)return;!1!==n.keepCase&&i.terms(0).isTitleCase()&&(s=ur(s)),o=xe(s,r.world,r.pool());var a=r.buildFrom(o);a.tagger(),o=a.list}if(!0===n.keepTags){var u=i.json({terms:{tags:!0}}).terms;o[0].terms().forEach((function(t,e){u[e]&&t.tagSafe(u[e].tags,"keptTag",r.world)}))}i.replace(o[0],r)})),this):this.delete()},replace:function(t,e,r){return void 0===e?this.replaceWith(t,r):(this.match(t).replaceWith(e,r),this)}},hr=T((function(t,e){var r=function(t){return t&&"[object Object]"===Object.prototype.toString.call(t)},n=function(t,e){var r=xe(t,e.world)[0],n=e.buildFrom([r]);return n.tagger(),e.list=n.list,e};e.append=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e?this.found?(this.uncache(),this.list.forEach((function(n){var i;r(e)&&"Doc"===e.isA?i=e.list[0].clone():"string"==typeof e&&(i=xe(e,t.world,t.pool())[0]),t.buildFrom([i]).tagger(),n.append(i,t)})),this):n(e,this):this},e.insertAfter=e.append,e.insertAt=e.append,e.prepend=function(t){var e=this;return t?this.found?(this.uncache(),this.list.forEach((function(n){var i;r(t)&&"Doc"===t.isA?i=t.list[0].clone():"string"==typeof t&&(i=xe(t,e.world,e.pool())[0]),e.buildFrom([i]).tagger(),n.prepend(i,e)})),this):n(t,this):this},e.insertBefore=e.prepend,e.concat=function(){this.uncache();for(var t=this.list.slice(0),e=0;e0&&void 0!==arguments[0]?arguments[0]:{};if("number"==typeof e&&this.list[e])return this.list[e].json(r);!0===(e=n(e)).root&&this.list.forEach((function(e){e.terms().forEach((function(e){null===e.root&&e.setRoot(t.world)}))}));var i=this.list.map((function(r){return r.json(e,t.world)}));if((e.terms.offset||e.offset||e.terms.index||e.index)&&pr(this,i,e),e.frequency||e.freq||e.count){var o={};this.list.forEach((function(t){var e=t.text("reduced");o[e]=o[e]||0,o[e]+=1})),this.list.forEach((function(t,e){i[e].count=o[t.text("reduced")]}))}if(e.unique){var s={};i=i.filter((function(t){return!0!==s[t.reduced]&&(s[t.reduced]=!0,!0)}))}return i},e.data=e.json})),dr=T((function(t){var e="",r=function(t,e){for(t=t.toString();t.lengthe.count?-1:t.countn?1:0},length:function(t,e){var r=t.text().trim().length,n=e.text().trim().length;return rn?-1:0},wordCount:function(t,e){var r=t.wordCount(),n=e.wordCount();return rn?-1:0}};br.alphabetical=br.alpha,br.wordcount=br.wordCount;var yr={index:!0,sequence:!0,seq:!0,sequential:!0,chron:!0,chronological:!0},Ar={sort:function(t){return"freq"===(t=t||"alpha")||"frequency"===t||"topk"===t?(r={},n={case:!0,punctuation:!1,whitespace:!0,unicode:!0},(e=this).list.forEach((function(t){var e=t.text(n);r[e]=r[e]||0,r[e]+=1})),e.list.sort((function(t,e){var i=r[t.text(n)],o=r[e.text(n)];return io?-1:0})),e):yr.hasOwnProperty(t)?function(t){var e={};return t.json({terms:{offset:!0}}).forEach((function(t){e[t.terms[0].id]=t.terms[0].offset.start})),t.list=t.list.sort((function(t,r){return e[t.start]>e[r.start]?1:e[t.start]0){i+=s;continue}}if(void 0===r[o]||!0!==r.hasOwnProperty(o))if(o===t[i].reduced||!0!==r.hasOwnProperty(t[i].reduced)){if(!0===Dr.test(o)){var a=o.replace(Dr,"");!0===r.hasOwnProperty(a)&&t[i].tag(r[a],"noprefix-lexicon",e)}}else t[i].tag(r[t[i].reduced],"lexicon",e);else t[i].tag(r[o],"lexicon",e)}return t},Gr=function(t){var e=t.termList();return Mr(e,t.world),t.world.taggers.forEach((function(e){e(t)})),t},qr=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"stripPeriods",value:function(){return this.termList().forEach((function(t){!0===t.tags.Abbreviation&&t.next&&(t.post=t.post.replace(/^\./,""));var e=t.text.replace(/\./,"");t.set(e)})),this}},{key:"addPeriods",value:function(){return this.termList().forEach((function(t){t.post=t.post.replace(/^\./,""),t.post="."+t.post})),this}}]),o}(t);return r.prototype.unwrap=r.prototype.stripPeriods,t.prototype.abbreviations=function(t){var e=this.match("#Abbreviation");return"number"==typeof t&&(e=e.get(t)),new r(e.list,this,this.world)},t},Lr=/\./,Wr=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"stripPeriods",value:function(){return this.termList().forEach((function(t){var e=t.text.replace(/\./g,"");t.set(e)})),this}},{key:"addPeriods",value:function(){return this.termList().forEach((function(t){var e=t.text.replace(/\./g,"");e=e.split("").join("."),!1===Lr.test(t.post)&&(e+="."),t.set(e)})),this}}]),o}(t);return r.prototype.unwrap=r.prototype.stripPeriods,r.prototype.strip=r.prototype.stripPeriods,t.prototype.acronyms=function(t){var e=this.match("#Acronym");return"number"==typeof t&&(e=e.get(t)),new r(e.list,this,this.world)},t},Ur=function(t){return t.prototype.clauses=function(e){var r=this.if("@hasComma").notIf("@hasComma @hasComma").notIf("@hasComma . .? (and|or) .").notIf("(#City && @hasComma) #Country").notIf("(#WeekDay && @hasComma) #Date").notIf("(#Date && @hasComma) #Year").notIf("@hasComma (too|also)$").match("@hasComma"),n=this.splitAfter(r),i=n.quotations(),o=(n=n.splitOn(i)).parentheses(),s=(n=n.splitOn(o)).if("#Copula #Adjective #Conjunction (#Pronoun|#Determiner) #Verb").match("#Conjunction"),a=(n=n.splitBefore(s)).if("if .{2,9} then .").match("then"),u=(n=(n=(n=(n=(n=(n=n.splitBefore(a)).splitBefore("as well as .")).splitBefore("such as .")).splitBefore("in addition to .")).splitAfter("@hasSemicolon")).splitAfter("@hasDash")).filter((function(t){return t.wordCount()>5&&t.match("#Verb+").length>=2}));if(u.found){var c=u.splitAfter("#Noun .* #Verb .* #Noun+");n=n.splitOn(c.eq(0))}return"number"==typeof e&&(n=n.get(e)),new t(n.list,this,this.world)},t},Rr=function(t){var r=function(t){i(o,t);var r=u(o);function o(t,n,i){var s;return e(this,o),(s=r.call(this,t,n,i)).contracted=null,s}return n(o,[{key:"expand",value:function(){return this.list.forEach((function(t){var e=t.terms(),r=e[0].isTitleCase();e.forEach((function(t,r){t.set(t.implicit||t.text),t.implicit=void 0,r1&&void 0!==arguments[1]?arguments[1]:{},n=this.match("(#City && @hasComma) (#Region|#Country)"),i=this.not(n).splitAfter("@hasComma"),o=(i=i.concat(n)).quotations();return o.found&&(i=i.splitOn(o.eq(0))),i=i.match("#Noun+ (of|by)? the? #Noun+?"),!0!==e.keep_anaphora&&(i=(i=(i=(i=i.not("#Pronoun")).not("(there|these)")).not("(#Month|#WeekDay)")).not("(my|our|your|their|her|his)")),i=i.not("(of|for|by|the)$"),"number"==typeof t&&(i=i.get(t)),new r(i.list,this,this.world)},t},un=/\(/,cn=/\)/,hn=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"unwrap",value:function(){return this.list.forEach((function(t){var e=t.terms(0);e.pre=e.pre.replace(un,"");var r=t.lastTerm();r.post=r.post.replace(cn,"")})),this}}]),o}(t);return t.prototype.parentheses=function(t){var e=[];return this.list.forEach((function(t){for(var r=t.terms(),n=0;n0}}),Object.defineProperty(this,"length",{get:function(){return o.list.length}}),Object.defineProperty(this,"isA",{get:function(){return"Doc"}})}return n(t,[{key:"tagger",value:function(){return Gr(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),t}();Fn.prototype.buildFrom=function(t){return t=t.map((function(t){return t.clone(!0)})),new Fn(t,this,this.world)},Fn.prototype.fromText=function(t){var e=xe(t,this.world,this.pool());return this.buildFrom(e)},Object.assign(Fn.prototype,Cn.misc),Object.assign(Fn.prototype,Cn.selections),kn(Fn);var Tn={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(Tn).forEach((function(t){return Fn.prototype[t]=Fn.prototype[Tn[t]]}));var Nn=Fn;return function t(e){var r=e,n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0;e&&r.addWords(e);var n=xe(t,r),i=new Nn(n,null,r);return i.tagger(),i};return n.tokenize=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0,n=r;e&&((n=n.clone()).words={},n.addWords(e));var i=xe(t,n),o=new Nn(i,null,n);return(e||o.world.taggers.length>0)&&Gr(o),o},n.extend=function(t){return t(Nn,r,this,te,at,re),this},n.fromJSON=function(t){var e=Pe(t,r);return new Nn(e,null,r)},n.clone=function(){return t(r.clone())},n.verbose=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return r.verbose(t),this},n.world=function(){return r},n.parseMatch=function(t,e){return Ht(t,e)},n.version="13.10.3",n.import=n.load,n.plugin=n.extend,n}(new Je)})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).nlp=e()}(this,(function(){"use strict";function t(e){return(t="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)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;rr?n:r)+1;if(Math.abs(r-n)>(i||100))return i||100;for(var o,s,a,u,c,h,l=[],f=0;f4)return r;u=s===(a=e[o-1])?0:1,c=l[v-1][o]+1,(h=l[v][o-1]+1)1&&o>1&&s===e[o-2]&&t[v-2]===a&&(h=l[v-2][o-2]+u)2&&void 0!==arguments[2]?arguments[2]:3;if(t===e)return 1;if(t.lengthe.fuzzy)return!0;if(!0===e.soft&&(i=B(e.word,t.root))>e.fuzzy)return!0}return e.word===t.clean||e.word===t.text||e.word===t.reduced}return void 0!==e.tag?!0===t.tags[e.tag]:void 0!==e.method?"function"==typeof t[e.method]&&!0===t[e.method]():void 0!==e.regex?e.regex.test(t.clean):void 0!==e.fastOr?!(!t.implicit||!0!==e.fastOr.hasOwnProperty(t.implicit))||(e.fastOr.hasOwnProperty(t.reduced)||e.fastOr.hasOwnProperty(t.text)):void 0!==e.choices&&("and"===e.operator?e.choices.every((function(e){return I(t,e,r,n)})):e.choices.some((function(e){return I(t,e,r,n)})))},z=I=function(t,e,r,n){var i=S(t,e,r,n);return!0===e.negative?!i:i},D={},_={doesMatch:function(t,e,r){return z(this,t,e,r)},isAcronym:function(){return b(this.text)},isImplicit:function(){return""===this.text&&Boolean(this.implicit)},isKnown:function(){return Object.keys(this.tags).some((function(t){return!0!==D[t]}))},setRoot:function(t){var e=t.transforms,r=this.implicit||this.clean;if(this.tags.Plural&&(r=e.toSingular(r,t)),this.tags.Verb&&!this.tags.Negative&&!this.tags.Infinitive){var n=null;this.tags.PastTense?n="PastTense":this.tags.Gerund?n="Gerund":this.tags.PresentTense?n="PresentTense":this.tags.Participle?n="Participle":this.tags.Actor&&(n="Actor"),r=e.toInfinitive(r,t,n)}this.root=r}},M=/[\s-]/,G=/^[A-Z-]+$/,q={textOut:function(t,e,r){t=t||{};var n=this.text,i=this.pre,o=this.post;return!0===t.reduced&&(n=this.reduced||""),!0===t.root&&(n=this.root||""),!0===t.implicit&&this.implicit&&(n=this.implicit||""),!0===t.normal&&(n=this.clean||this.text||""),!0===t.root&&(n=this.root||this.reduced||""),!0===t.unicode&&(n=p(n)),!0===t.titlecase&&(this.tags.ProperNoun&&!this.titleCase()||(this.tags.Acronym?n=n.toUpperCase():G.test(n)&&!this.tags.Acronym&&(n=n.toLowerCase()))),!0===t.lowercase&&(n=n.toLowerCase()),!0===t.acronyms&&this.tags.Acronym&&(n=n.replace(/\./g,"")),!0!==t.whitespace&&!0!==t.root||(i="",o=" ",!1!==M.test(this.post)&&!t.last||this.implicit||(o="")),!0!==t.punctuation||t.root||(!0===this.hasPost(".")?o="."+o:!0===this.hasPost("?")?o="?"+o:!0===this.hasPost("!")?o="!"+o:!0===this.hasPost(",")?o=","+o:!0===this.hasEllipses()&&(o="..."+o)),!0!==e&&(i=""),!0!==r&&(o=""),!0===t.abbreviations&&this.tags.Abbreviation&&(o=o.replace(/^\./,"")),i+n+o}},L={Auxiliary:1,Possessive:1},W=function(t,e){var r=Object.keys(t.tags),n=e.tags;return r=r.sort((function(t,e){return L[e]||!n[e]?-1:n[e]?n[t]?n[t].lineage.length>n[e].lineage.length?1:n[t].isA.length>n[e].isA.length?-1:0:0:1}))},U={text:!0,tags:!0,implicit:!0,whitespace:!0,clean:!1,id:!1,index:!1,offset:!1,bestTag:!1},R={json:function(t,e){t=t||{};var r={};return(t=Object.assign({},U,t)).text&&(r.text=this.text),t.normal&&(r.normal=this.clean),t.tags&&(r.tags=Object.keys(this.tags)),t.clean&&(r.clean=this.clean),(t.id||t.offset)&&(r.id=this.id),t.implicit&&null!==this.implicit&&(r.implicit=this.implicit),t.whitespace&&(r.pre=this.pre,r.post=this.post),t.bestTag&&(r.bestTag=W(this,e)[0]),r}},H=Object.assign({},N,$,_,q,R);function Q(){return"undefined"!=typeof window&&window.document}var Z=function(t,e){for(t=t.toString();t.length0&&void 0!==arguments[0]?arguments[0]:"";e(this,t),r=String(r);var n=F(r);this.text=n.text||"",this.clean=n.clean,this.reduced=n.reduced,this.root=null,this.implicit=null,this.pre=n.pre||"",this.post=n.post||"",this.tags={},this.prev=null,this.next=null,this.id=h(n.clean),this.isA="Term",n.alias&&(this.alias=n.alias)}return n(t,[{key:"set",value:function(t){var e=F(t);return this.text=e.text,this.clean=e.clean,this}}]),t}();st.prototype.clone=function(){var t=new st(this.text);return t.pre=this.pre,t.post=this.post,t.clean=this.clean,t.reduced=this.reduced,t.root=this.root,t.implicit=this.implicit,t.tags=Object.assign({},this.tags),t},Object.assign(st.prototype,H),Object.assign(st.prototype,ot);var at=st,ut={terms:function(t){if(0===this.length)return[];if(this.cache.terms)return void 0!==t?this.cache.terms[t]:this.cache.terms;for(var e=[this.pool.get(this.start)],r=0;r0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0;"string"==typeof t&&(t="normal"===t?{whitespace:!0,unicode:!0,lowercase:!0,punctuation:!0,acronyms:!0,abbreviations:!0,implicit:!0,normal:!0}:"clean"===t?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,normal:!0}:"reduced"===t?{punctuation:!1,titlecase:!1,lowercase:!0,whitespace:!0,unicode:!0,implicit:!0,reduced:!0}:"implicit"===t?{punctuation:!0,implicit:!0,whitespace:!0,trim:!0}:"root"===t?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,root:!0}:{});var n=this.terms(),i=!1;n[0]&&null===n[0].prev&&null===n[n.length-1].next&&(i=!0);var o=n.reduce((function(o,s,a){if(0===a&&""===s.text&&null!==s.implicit&&!t.implicit)return o;t.last=r&&a===n.length-1;var u=!0,c=!0;return!1===i&&(0===a&&e&&(u=!1),a===n.length-1&&r&&(c=!1)),o+s.textOut(t,u,c)}),"");return!0===i&&r&&(o=ct(o)),!0===t.trim&&(o=o.trim()),o}},lt={trim:function(){var t=this.terms();if(t.length>0){t[0].pre=t[0].pre.replace(/^\s+/,"");var e=t[t.length-1];e.post=e.post.replace(/\s+$/,"")}return this}},ft=/[.?!]\s*$/,pt=function(t,e){e[0].pre=t[0].pre;var r,n,i=t[t.length-1],o=e[e.length-1];o.post=(r=i.post,n=o.post,ft.test(n)?n+r.match(/\s*$/):r),i.post="",""===i.post&&(i.post+=" ")},vt=function(t,e,r){var n=t.terms(),i=e.terms();pt(n,i),function(t,e,r){var n=t[t.length-1],i=e[e.length-1],o=n.next;n.next=e[0].id,i.next=o,o&&(r.get(o).prev=i.id);var s=t[0].id;s&&(e[0].prev=s)}(n,i,t.pool);var o,s=[t],a=t.start,u=[r];return(u=u.concat(r.parents())).forEach((function(t){var e=t.list.filter((function(t){return t.hasId(a)}));s=s.concat(e)})),(s=(o=s).filter((function(t,e){return o.indexOf(t)===e}))).forEach((function(t){t.length+=e.length})),t.cache={},t},dt=/ /,mt=function(t,e,r){var n=t.start,i=e.terms();!function(t){var e=t[t.length-1];!1===dt.test(e.post)&&(e.post+=" ")}(i),function(t,e,r){var n=r[r.length-1];n.next=t.start;var i=t.pool,o=i.get(t.start);o.prev&&(i.get(o.prev).next=e.start),r[0].prev=t.terms(0).prev,t.terms(0).prev=n.id}(t,e,i);var o,s=[t],a=[r];return(a=a.concat(r.parents())).forEach((function(t){var r=t.list.filter((function(t){return t.hasId(n)||t.hasId(e.start)}));s=s.concat(r)})),(s=(o=s).filter((function(t,e){return o.indexOf(t)===e}))).forEach((function(t){t.length+=e.length,t.start===n&&(t.start=e.start),t.cache={}})),t},gt=function(t,e){var r=e.pool(),n=t.terms(),i=r.get(n[0].prev)||{},o=r.get(n[n.length-1].next)||{};n[0].implicit&&i.implicit&&(i.set(i.implicit),i.post+=" "),function(t,e,r,n){var i=t.parents();i.push(t),i.forEach((function(t){var i=t.list.find((function(t){return t.hasId(e)}));i&&(i.length-=r,i.start===e&&(i.start=n.id),i.cache={})})),t.list=t.list.filter((function(t){return!(!t.start||!t.length)}))}(e,t.start,t.length,o),i&&(i.next=o.id),o&&(o.prev=i.id)},bt={append:function(t,e){return vt(this,t,e),this},prepend:function(t,e){return mt(this,t,e),this},delete:function(t){return gt(this,t),this},replace:function(t,e){var r=this.length;vt(this,t,e);var n=this.buildFrom(this.start,this.length);n.length=r,gt(n,e)},splitOn:function(t){var e=this.terms(),r={before:null,match:null,after:null},n=e.findIndex((function(e){return e.id===t.start}));if(-1===n)return r;var i=e.slice(0,n);i.length>0&&(r.before=this.buildFrom(i[0].id,i.length));var o=e.slice(n,n+t.length);o.length>0&&(r.match=this.buildFrom(o[0].id,o.length));var s=e.slice(n+t.length,e.length);return s.length>0&&(r.after=this.buildFrom(s[0].id,s.length,this.pool)),r}},yt={json:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,r={};return t.text&&(r.text=this.text()),t.normal&&(r.normal=this.text("normal")),t.clean&&(r.clean=this.text("clean")),t.reduced&&(r.reduced=this.text("reduced")),t.implicit&&(r.implicit=this.text("implicit")),t.root&&(r.root=this.text("root")),t.trim&&(r.text&&(r.text=r.text.trim()),r.normal&&(r.normal=r.normal.trim()),r.reduced&&(r.reduced=r.reduced.trim())),t.terms&&(!0===t.terms&&(t.terms={}),r.terms=this.terms().map((function(r){return r.json(t.terms,e)}))),r}},At={lookAhead:function(t){t||(t=".*");var e=this.pool,r=[],n=this.terms();return function t(n){var i=e.get(n);i&&(r.push(i),i.prev&&t(i.next))}(n[n.length-1].next),0===r.length?[]:this.buildFrom(r[0].id,r.length).match(t)},lookBehind:function(t){t||(t=".*");var e=this.pool,r=[];return function t(n){var i=e.get(n);i&&(r.push(i),i.prev&&t(i.prev))}(e.get(this.start).prev),0===r.length?[]:this.buildFrom(r[r.length-1].id,r.length).match(t)}},wt=Object.assign({},ut,ht,lt,bt,yt,At),xt=function(t,e){if(0===e.length)return!0;for(var r=0;r0)return!0;if(!0===n.anything&&!0===n.negative)return!0}return!1},Pt=T((function(t,e){e.getGreedy=function(t,e){for(var r=Object.assign({},t.regs[t.r],{start:!1,end:!1}),n=t.t;t.t1&&void 0!==arguments[1]?arguments[1]:0,n=t.regs[t.r],i=!1,o=0;oe&&(e=r.length),n}))&&e},e.getGroup=function(t,e,r){if(t.groups[t.groupId])return t.groups[t.groupId];var n=t.terms[e].id;return t.groups[t.groupId]={group:String(r),start:n,length:0},t.groups[t.groupId]}})),jt=function(t,e,r,n){for(var i={t:0,terms:t,r:0,regs:e,groups:{},start_i:r,phrase_length:n,hasGroup:!1,groupId:null,previousGroup:null};i.ri.t)return null;if(!0===o.end&&i.start_i+i.t!==n)return null}if(!0===i.hasGroup){var d=Pt.getGroup(i,f,o.named);i.t>1&&o.greedy?d.length+=i.t-f:d.length++}}else{if(o.negative){var m=Object.assign({},o);if(m.negative=!1,!0===i.terms[i.t].doesMatch(m,i.start_i+i.t,i.phrase_length))return null}if(!0!==o.optional){if(i.terms[i.t].isImplicit()&&e[i.r-1]&&i.terms[i.t+1]){if(i.terms[i.t-1]&&i.terms[i.t-1].implicit===e[i.r-1].word)return null;if(i.terms[i.t+1].doesMatch(o,i.start_i+i.t,i.phrase_length)){i.t+=2;continue}}return null}}}else{var g=Pt.greedyTo(i,e[i.r+1]);if(void 0!==o.min&&g-i.to.max){i.t=i.t+o.max;continue}if(null===g)return null;!0===i.hasGroup&&(Pt.getGroup(i,i.t,o.named).length=g-i.t),i.t=g}}return{match:i.terms.slice(0,i.t),groups:i.groups}},Et=function(t,e,r){if(!r||0===r.length)return r;if(e.some((function(t){return t.end}))){var n=t[t.length-1];r=r.filter((function(t){return-1!==t.match.indexOf(n)}))}return r},Ot=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/,kt=/([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/,Ct=/ /g,Ft=function(t){return/^[\!\[\^]*(<[^<]*>)?\//.test(t)&&/\/[\?\]\+\*\$~]*$/.test(t)},Tt=function(t){return t=(t=t.map((function(t){return t.trim()}))).filter((function(t){return t}))},Nt=function(t){var e=t.split(Ot),r=[];e.forEach((function(t){Ft(t)?r.push(t):r=r.concat(t.split(kt))})),r=Tt(r);var n=[];return r.forEach((function(t){!function(t){return/^[\!\[\^]*(<[^<]*>)?\(/.test(t)&&/\)[\?\]\+\*\$~]*$/.test(t)}(t)?Ft(t)?n.push(t):n=n.concat(t.split(Ct)):n.push(t)})),n=Tt(n)},$t=/\{([0-9]+,?[0-9]*)\}/,Vt=/&&/,Bt=new RegExp(/^< *?(\S+) *?>/),It=function(t){return t[t.length-1]},St=function(t){return t[0]},zt=function(t){return t.substr(1)},Dt=function(t){return t.substr(0,t.length-1)},_t=function(t){return t=zt(t),t=Dt(t)},Mt=function t(e){for(var r,n={},i=0;i<2;i+=1){if("$"===It(e)&&(n.end=!0,e=Dt(e)),"^"===St(e)&&(n.start=!0,e=zt(e)),("["===St(e)||"]"===It(e))&&(n.named=!0,"["===St(e)?n.groupType="]"===It(e)?"single":"start":n.groupType="end",e=(e=e.replace(/^\[/,"")).replace(/\]$/,""),"<"===St(e))){var o=Bt.exec(e);o.length>=2&&(n.named=o[1],e=e.replace(o[0],""))}if("+"===It(e)&&(n.greedy=!0,e=Dt(e)),"*"!==e&&"*"===It(e)&&"\\*"!==e&&(n.greedy=!0,e=Dt(e)),"?"===It(e)&&(n.optional=!0,e=Dt(e)),"!"===St(e)&&(n.negative=!0,e=zt(e)),"("===St(e)&&")"===It(e)){Vt.test(e)?(n.choices=e.split(Vt),n.operator="and"):(n.choices=e.split("|"),n.operator="or"),n.choices[0]=zt(n.choices[0]);var s=n.choices.length-1;n.choices[s]=Dt(n.choices[s]),n.choices=n.choices.map((function(t){return t.trim()})),n.choices=n.choices.filter((function(t){return t})),n.choices=n.choices.map((function(e){return e.split(/ /g).map(t)})),e=""}if("/"===St(e)&&"/"===It(e))return e=_t(e),n.regex=new RegExp(e),n;if("~"===St(e)&&"~"===It(e))return e=_t(e),n.soft=!0,n.word=e,n}return!0===$t.test(e)&&(e=e.replace($t,(function(t,e){var r=e.split(/,/g);return 1===r.length?(n.min=Number(r[0]),n.max=Number(r[0])):(n.min=Number(r[0]),n.max=Number(r[1]||999)),n.greedy=!0,n.optional=!0,""}))),"#"===St(e)?(n.tag=zt(e),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===St(e)?(n.method=zt(e),n):"."===e?(n.anything=!0,n):"*"===e?(n.anything=!0,n.greedy=!0,n.optional=!0,n):(e&&(e=(e=e.replace("\\*","*")).replace("\\.","."),n.word=e.toLowerCase()),n)},Gt=function(t){for(var e,r=!1,n=-1,i=0;i1&&void 0!==arguments[1]?arguments[1]:{},r=t.filter((function(t){return t.groupType})).length;return r>0&&(t=Gt(t)),e.fuzzy||(t=qt(t)),t},Wt=function(t){return"[object Array]"===Object.prototype.toString.call(t)},Ut=function(t){return[{choices:t.map((function(t){return[{word:t}]})),operator:"or"}]},Rt=function(t){if(!t||!t.list||!t.list[0])return[];var e=[];return t.list.forEach((function(t){var r=[];t.terms().forEach((function(t){r.push(t.id)})),e.push(r)})),[{idBlocks:e}]},Ht=function(t,e){return!0===e.fuzzy&&(e.fuzzy=.85),"number"==typeof e.fuzzy&&(t=t.map((function(t){return e.fuzzy>0&&t.word&&(t.fuzzy=e.fuzzy),t.choices&&t.choices.forEach((function(t){t.forEach((function(t){t.fuzzy=e.fuzzy}))})),t}))),t},Qt=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null==e||""===e)return[];if("object"===t(e)){if(Wt(e)){if(0===e.length||!e[0])return[];if("object"===t(e[0]))return e;if("string"==typeof e[0])return Ut(e)}return e&&"Doc"===e.isA?Rt(e):[]}"number"==typeof e&&(e=String(e));var n=Nt(e);return n=n.map((function(t){return Mt(t)})),n=Lt(n,r),n=Ht(n,r)},Zt=function(t,e){for(var r=[],n=e[0].idBlocks,i=function(e){n.forEach((function(n){0!==n.length?n.every((function(r,n){return o=e,t[e+n].id===r}))&&(r.push({match:t.slice(e,e+n.length)}),e+=n.length-1):o=e})),o=e},o=0;o2&&void 0!==arguments[2]&&arguments[2];if("string"==typeof e&&(e=Qt(e)),!0===xt(t,e))return[];var n=e.filter((function(t){return!0!==t.optional&&!0!==t.negative})).length,i=t.terms(),o=[];if(e[0].idBlocks){var s=Zt(i,e);if(s&&s.length>0)return Et(i,e,s)}if(!0===e[0].start){var a=jt(i,e,0,i.length);return a&&a.match&&a.match.length>0&&(a.match=a.match.filter((function(t){return t})),o.push(a)),Et(i,e,o)}for(var u=0;ui.length);u+=1){var c=jt(i.slice(u),e,u,i.length);if(c&&c.match&&c.match.length>0&&(u+=c.match.length-1,c.match=c.match.filter((function(t){return t})),o.push(c),!0===r))return Et(i,e,o)}return Et(i,e,o)},Yt=function(t,e){var r={};Jt(t,e).forEach((function(t){t.match.forEach((function(t){r[t.id]=!0}))}));var n=t.terms(),i=[],o=[];return n.forEach((function(t){!0!==r[t.id]?o.push(t):o.length>0&&(i.push(o),o=[])})),o.length>0&&i.push(o),i},Kt={match:function(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=Jt(this,t,r);return n=n.map((function(t){var r=t.match,n=t.groups,i=e.buildFrom(r[0].id,r.length,n);return i.cache.terms=r,i}))},has:function(t){return Jt(this,t,!0).length>0},not:function(t){var e=this,r=Yt(this,t);return r=r.map((function(t){return e.buildFrom(t[0].id,t.length)}))},canBe:function(t,e){for(var r=this,n=[],i=this.terms(),o=!1,s=0;s0})).map((function(t){return r.buildFrom(t[0].id,t.length)}))}},Xt=function t(r,n,i){e(this,t),this.start=r,this.length=n,this.isA="Phrase",Object.defineProperty(this,"pool",{enumerable:!1,writable:!0,value:i}),Object.defineProperty(this,"cache",{enumerable:!1,writable:!0,value:{}}),Object.defineProperty(this,"groups",{enumerable:!1,writable:!0,value:{}})};Xt.prototype.buildFrom=function(t,e,r){var n=new Xt(t,e,this.pool);return r&&Object.keys(r).length>0?n.groups=r:n.groups=this.groups,n},Object.assign(Xt.prototype,Kt),Object.assign(Xt.prototype,wt);var te={term:"terms"};Object.keys(te).forEach((function(t){return Xt.prototype[t]=Xt.prototype[te[t]]}));var ee=Xt,re=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e(this,t),Object.defineProperty(this,"words",{enumerable:!1,value:r})}return n(t,[{key:"add",value:function(t){return this.words[t.id]=t,this}},{key:"get",value:function(t){return this.words[t]}},{key:"remove",value:function(t){delete this.words[t]}},{key:"merge",value:function(t){return Object.assign(this.words,t.words),this}},{key:"stats",value:function(){return{words:Object.keys(this.words).length}}}]),t}();re.prototype.clone=function(){var t=this,e=Object.keys(this.words).reduce((function(e,r){var n=t.words[r].clone();return e[n.id]=n,e}),{});return new re(e)};var ne=re,ie=function(t){t.forEach((function(e,r){r>0&&(e.prev=t[r-1].id),t[r+1]&&(e.next=t[r+1].id)}))},oe=/(\S.+?[.!?\u203D\u2E18\u203C\u2047-\u2049])(?=\s+|$)/g,se=/\S/,ae=/[ .][A-Z]\.? *$/i,ue=/(?:\u2026|\.{2,}) *$/,ce=/((?:\r?\n|\r)+)/,he=/[a-z0-9\u00C0-\u00FF\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/i,le=/^\s+/,fe=function(t,e){if(!0===ae.test(t))return!1;if(!0===ue.test(t))return!1;if(!1===he.test(t))return!1;var r=t.replace(/[.!?\u203D\u2E18\u203C\u2047-\u2049] *$/,"").split(" "),n=r[r.length-1].toLowerCase();return!e.hasOwnProperty(n)},pe=function(t,e){var r=e.cache.abbreviations;t=t||"";var n=[],i=[];if(!(t=String(t))||"string"!=typeof t||!1===se.test(t))return n;for(var o=function(t){for(var e=[],r=t.split(ce),n=0;n0&&(n.push(c),i[u]="")}if(0===n.length)return[t];for(var h=1;h0?(e[e.length-1]+=o,e.push(a)):e.push(o+a),o=""):o+=a}return o&&(0===e.length&&(e[0]=""),e[e.length-1]+=o),e=(e=function(t){for(var e=1;e0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,n=null;"string"!=typeof t&&("number"==typeof t?t=String(t):xe(t)&&(n=t)),n=(n=n||pe(t,e)).map((function(t){return we(t)})),r=r||new ne;var i=n.map((function(t){t=t.map((function(t){var e=new at(t);return r.add(e),e})),ie(t);var e=new ee(t[0].id,t.length,r);return e.cache.terms=t,e}));return i},je=function(t,e){var r=new ne;return t.map((function(t,n){var i=t.terms.map((function(i,o){var s=new at(i.text);return s.pre=void 0!==i.pre?i.pre:"",void 0===i.post&&(i.post=" ",o>=t.terms.length-1&&(i.post=". ",n>=t.terms.length-1&&(i.post="."))),s.post=void 0!==i.post?i.post:" ",i.tags&&i.tags.forEach((function(t){return s.tag(t,"",e)})),r.add(s),s}));return ie(i),new ee(i[0].id,i.length,r)}))},Ee=["Person","Place","Organization"],Oe={Noun:{notA:["Verb","Adjective","Adverb"]},Singular:{isA:"Noun",notA:"Plural"},ProperNoun:{isA:"Noun"},Person:{isA:["ProperNoun","Singular"],notA:["Place","Organization","Date"]},FirstName:{isA:"Person"},MaleName:{isA:"FirstName",notA:["FemaleName","LastName"]},FemaleName:{isA:"FirstName",notA:["MaleName","LastName"]},LastName:{isA:"Person",notA:["FirstName"]},NickName:{isA:"Person",notA:["FirstName","LastName"]},Honorific:{isA:"Noun",notA:["FirstName","LastName","Value"]},Place:{isA:"Singular",notA:["Person","Organization"]},Country:{isA:["Place","ProperNoun"],notA:["City"]},City:{isA:["Place","ProperNoun"],notA:["Country"]},Region:{isA:["Place","ProperNoun"]},Address:{isA:"Place"},Organization:{isA:["Singular","ProperNoun"],notA:["Person","Place"]},SportsTeam:{isA:"Organization"},School:{isA:"Organization"},Company:{isA:"Organization"},Plural:{isA:"Noun",notA:["Singular"]},Uncountable:{isA:"Noun"},Pronoun:{isA:"Noun",notA:Ee},Actor:{isA:"Noun",notA:Ee},Activity:{isA:"Noun",notA:["Person","Place"]},Unit:{isA:"Noun",notA:Ee},Demonym:{isA:["Noun","ProperNoun"],notA:Ee},Possessive:{isA:"Noun"}},ke={Verb:{notA:["Noun","Adjective","Adverb","Value"]},PresentTense:{isA:"Verb",notA:["PastTense","FutureTense"]},Infinitive:{isA:"PresentTense",notA:["PastTense","Gerund"]},Imperative:{isA:"Infinitive"},Gerund:{isA:"PresentTense",notA:["PastTense","Copula","FutureTense"]},PastTense:{isA:"Verb",notA:["FutureTense"]},FutureTense:{isA:"Verb"},Copula:{isA:"Verb"},Modal:{isA:"Verb",notA:["Infinitive"]},PerfectTense:{isA:"Verb",notA:"Gerund"},Pluperfect:{isA:"Verb"},Participle:{isA:"PastTense"},PhrasalVerb:{isA:"Verb"},Particle:{isA:"PhrasalVerb"},Auxiliary:{notA:["Noun","Adjective","Value"]}},Ce={Value:{notA:["Verb","Adjective","Adverb"]},Ordinal:{isA:"Value",notA:["Cardinal"]},Cardinal:{isA:"Value",notA:["Ordinal"]},Fraction:{isA:"Value",notA:["Noun"]},RomanNumeral:{isA:"Cardinal",notA:["Ordinal","TextValue"]},TextValue:{isA:"Value",notA:["NumericValue"]},NumericValue:{isA:"Value",notA:["TextValue"]},Money:{isA:"Cardinal"},Percent:{isA:"Value"}},Fe=["Noun","Verb","Adjective","Adverb","Value","QuestionWord"],Te={Adjective:{notA:["Noun","Verb","Adverb","Value"]},Comparable:{isA:["Adjective"]},Comparative:{isA:["Adjective"]},Superlative:{isA:["Adjective"],notA:["Comparative"]},NumberRange:{isA:["Contraction"]},Adverb:{notA:["Noun","Verb","Adjective","Value"]},Date:{notA:["Verb","Adverb","Preposition","Adjective"]},Month:{isA:["Date","Singular"],notA:["Year","WeekDay","Time"]},WeekDay:{isA:["Date","Noun"]},Timezone:{isA:["Date","Noun"],notA:["Adjective","ProperNoun"]},Time:{isA:["Date"],notA:["AtMention"]},Determiner:{notA:Fe},Conjunction:{notA:Fe},Preposition:{notA:Fe},QuestionWord:{notA:["Determiner"]},Currency:{isA:["Noun"]},Expression:{notA:["Noun","Adjective","Verb","Adverb"]},Abbreviation:{},Url:{notA:["HashTag","PhoneNumber","Verb","Adjective","Value","AtMention","Email"]},PhoneNumber:{notA:["HashTag","Verb","Adjective","Value","AtMention","Email"]},HashTag:{},AtMention:{isA:["Noun"],notA:["HashTag","Verb","Adjective","Value","Email"]},Emoji:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Emoticon:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Email:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Acronym:{notA:["Plural","RomanNumeral"]},Negative:{notA:["Noun","Adjective","Value"]},Condition:{notA:["Verb","Adjective","Noun","Value"]}},Ne={Noun:"blue",Verb:"green",Negative:"green",Date:"red",Value:"red",Adjective:"magenta",Preposition:"cyan",Conjunction:"cyan",Determiner:"cyan",Adverb:"cyan"},$e=function(t){return Object.keys(t).forEach((function(e){t[e].color?t[e].color=t[e].color:Ne[e]?t[e].color=Ne[e]:t[e].isA.some((function(r){return!!Ne[r]&&(t[e].color=Ne[r],!0)}))})),t},Ve=function(t){return Object.keys(t).forEach((function(e){for(var r=t[e],n=r.isA.length,i=0;i1&&(r.hasCompound[o[0]]=!0),void 0===Ge[i]?void 0!==e[n]?("string"==typeof e[n]&&(e[n]=[e[n]]),"string"==typeof i?e[n].push(i):e[n]=e[n].concat(i)):e[n]=i:Ge[i](e,n,r)}))},Le=function(t){var e=Object.assign({},_e);return Object.keys(_e).forEach((function(r){var n=_e[r];Object.keys(n).forEach((function(t){n[t]=r})),qe(n,e,t)})),e},We=qe,Ue=function(t){for(var e=t.irregulars.nouns,r=Object.keys(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:{};"string"!=typeof e&&"number"!=typeof e&&null!==e||(e={group:e});var r=Qt(t,e);if(0===r.length)return this.buildFrom([]);if(!1===tr(this,r))return this.buildFrom([]);var n=this.list.reduce((function(t,e){return t.concat(e.match(r))}),[]);return void 0!==e.group&&null!==e.group&&""!==e.group?this.buildFrom(n).groups(e.group):this.buildFrom(n)},e.not=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e);if(0===r.length||!1===tr(this,r))return this;var n=this.list.reduce((function(t,e){return t.concat(e.not(r))}),[]);return this.buildFrom(n)},e.matchOne=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e);if(!1===tr(this,r))return this.buildFrom([]);for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e);if(!1===tr(this,r))return this.buildFrom([]);var n=this.list.filter((function(t){return!0===t.has(r)}));return this.buildFrom(n)},e.ifNo=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e),n=this.list.filter((function(t){return!1===t.has(r)}));return this.buildFrom(n)},e.has=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e);return!1!==tr(this,r)&&this.list.some((function(t){return!0===t.has(r)}))},e.lookAhead=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t||(t=".*");var r=Qt(t,e),n=[];return this.list.forEach((function(t){n=n.concat(t.lookAhead(r))})),n=n.filter((function(t){return t})),this.buildFrom(n)},e.lookAfter=e.lookAhead,e.lookBehind=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t||(t=".*");var r=Qt(t,e),n=[];return this.list.forEach((function(t){n=n.concat(t.lookBehind(r))})),n=n.filter((function(t){return t})),this.buildFrom(n)},e.lookBefore=e.lookBehind,e.before=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e),n=this.if(r).list,i=n.map((function(t){var e=t.terms().map((function(t){return t.id})),n=t.match(r)[0],i=e.indexOf(n.start);return 0===i||-1===i?null:t.buildFrom(t.start,i)}));return i=i.filter((function(t){return null!==t})),this.buildFrom(i)},e.after=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Qt(t,e),n=this.if(r).list,i=n.map((function(t){var e=t.terms(),n=e.map((function(t){return t.id})),i=t.match(r)[0],o=n.indexOf(i.start);if(-1===o||!e[o+i.length])return null;var s=e[o+i.length].id,a=t.length-o-i.length;return t.buildFrom(s,a)}));return i=i.filter((function(t){return null!==t})),this.buildFrom(i)},e.hasAfter=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookAfter(t,e).found}))},e.hasBefore=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookBefore(t,e).found}))}})),rr=function(t,e,r,n){var i=[];"string"==typeof t&&(i=t.split(" ")),e.list.forEach((function(o){var s=o.terms();!0===r&&(s=s.filter((function(r){return r.canBe(t,e.world)}))),s.forEach((function(r,o){i.length>1?i[o]&&"."!==i[o]&&r.tag(i[o],n,e.world):r.tag(t,n,e.world)}))}))},nr={tag:function(t,e){return t?(rr(t,this,!1,e),this):this},tagSafe:function(t,e){return t?(rr(t,this,!0,e),this):this},unTag:function(t,e){var r=this;return this.list.forEach((function(n){n.terms().forEach((function(n){return n.unTag(t,e,r.world)}))})),this},canBe:function(t){if(!t)return this;var e=this.world,r=this.list.reduce((function(r,n){return r.concat(n.canBe(t,e))}),[]);return this.buildFrom(r)}},ir={map:function(e){var r=this;if(!e)return this;var n=this.list.map((function(t,n){var i=r.buildFrom([t]);i.from=null;var o=e(i,n);return o&&o.list&&o.list[0]?o.list[0]:o}));return 0===(n=n.filter((function(t){return t}))).length?this.buildFrom(n):"object"!==t(n[0])||"Phrase"!==n[0].isA?n:this.buildFrom(n)},forEach:function(t,e){var r=this;return t?(this.list.forEach((function(n,i){var o=r.buildFrom([n]);!0===e&&(o.from=null),t(o,i)})),this):this},filter:function(t){var e=this;if(!t)return this;var r=this.list.filter((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)}));return this.buildFrom(r)},find:function(t){var e=this;if(!t)return this;var r=this.list.find((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)}));return r?this.buildFrom([r]):void 0},some:function(t){var e=this;return t?this.list.some((function(r,n){var i=e.buildFrom([r]);return i.from=null,t(i,n)})):this},random:function(t){if(!this.found)return this;var e=Math.floor(Math.random()*this.list.length);if(void 0===t){var r=[this.list[e]];return this.buildFrom(r)}return e+t>this.length&&(e=(e=this.length-t)<0?0:e),this.slice(e,e+t)}},or=function(t){return t.split(/[ -]/g)},sr=function(t,e,r){for(var n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r={};return t.forEach((function(t,n){var i=!0;void 0!==e[n]&&(i=e[n]),t=(t=(t||"").toLowerCase()).replace(/[,;.!?]+$/,"");var o=or(t).map((function(t){return t.trim()}));r[o[0]]=r[o[0]]||{},1===o.length?r[o[0]].value=i:(r[o[0]].more=r[o[0]].more||[],r[o[0]].more.push({rest:o.slice(1),value:i}))})),r}(t,e),i=[],o=function(t){for(var e=r.list[t],o=e.terms().map((function(t){return t.reduced})),s=function(t){void 0!==n[o[t]]&&(void 0!==n[o[t]].more&&n[o[t]].more.forEach((function(r){void 0!==o[t+r.rest.length]&&(!0===r.rest.every((function(e,r){return e===o[t+r+1]}))&&i.push({id:e.terms()[t].id,value:r.value,length:r.rest.length+1}))})),void 0!==n[o[t]].value&&i.push({id:e.terms()[t].id,value:n[o[t]].value,length:1}))},a=0;a1&&void 0!==arguments[1]?arguments[1]:{};return e?(!0===n&&(n={keepTags:!0}),!1===n&&(n={keepTags:!1}),n=n||{},this.uncache(),this.list.forEach((function(i){var o,s=e;if("function"==typeof e&&(s=e(i)),s&&"object"===t(s)&&"Doc"===s.isA)o=s.list,r.pool().merge(s.pool());else{if("string"!=typeof s)return;!1!==n.keepCase&&i.terms(0).isTitleCase()&&(s=cr(s)),o=Pe(s,r.world,r.pool());var a=r.buildFrom(o);a.tagger(),o=a.list}if(!0===n.keepTags){var u=i.json({terms:{tags:!0}}).terms;o[0].terms().forEach((function(t,e){u[e]&&t.tagSafe(u[e].tags,"keptTag",r.world)}))}i.replace(o[0],r)})),this):this.delete()},replace:function(t,e,r){return void 0===e?this.replaceWith(t,r):(this.match(t).replaceWith(e,r),this)}},lr=T((function(t,e){var r=function(t){return t&&"[object Object]"===Object.prototype.toString.call(t)},n=function(t,e){var r=Pe(t,e.world)[0],n=e.buildFrom([r]);return n.tagger(),e.list=n.list,e};e.append=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return e?this.found?(this.uncache(),this.list.forEach((function(n){var i;r(e)&&"Doc"===e.isA?i=e.list[0].clone():"string"==typeof e&&(i=Pe(e,t.world,t.pool())[0]),t.buildFrom([i]).tagger(),n.append(i,t)})),this):n(e,this):this},e.insertAfter=e.append,e.insertAt=e.append,e.prepend=function(t){var e=this;return t?this.found?(this.uncache(),this.list.forEach((function(n){var i;r(t)&&"Doc"===t.isA?i=t.list[0].clone():"string"==typeof t&&(i=Pe(t,e.world,e.pool())[0]),e.buildFrom([i]).tagger(),n.prepend(i,e)})),this):n(t,this):this},e.insertBefore=e.prepend,e.concat=function(){this.uncache();for(var t=this.list.slice(0),e=0;e0&&void 0!==arguments[0]?arguments[0]:{};if("number"==typeof e&&this.list[e])return this.list[e].json(r);!0===(e=n(e)).root&&this.list.forEach((function(e){e.terms().forEach((function(e){null===e.root&&e.setRoot(t.world)}))}));var i=this.list.map((function(r){return r.json(e,t.world)}));if((e.terms.offset||e.offset||e.terms.index||e.index)&&vr(this,i,e),e.frequency||e.freq||e.count){var o={};this.list.forEach((function(t){var e=t.text("reduced");o[e]=o[e]||0,o[e]+=1})),this.list.forEach((function(t,e){i[e].count=o[t.text("reduced")]}))}if(e.unique){var s={};i=i.filter((function(t){return!0!==s[t.reduced]&&(s[t.reduced]=!0,!0)}))}return i},e.data=e.json})),mr=T((function(t){var e="",r=function(t,e){for(t=t.toString();t.lengthe.count?-1:t.countn?1:0},length:function(t,e){var r=t.text().trim().length,n=e.text().trim().length;return rn?-1:0},wordCount:function(t,e){var r=t.wordCount(),n=e.wordCount();return rn?-1:0}};yr.alphabetical=yr.alpha,yr.wordcount=yr.wordCount;var Ar={index:!0,sequence:!0,seq:!0,sequential:!0,chron:!0,chronological:!0},wr={sort:function(t){return"freq"===(t=t||"alpha")||"frequency"===t||"topk"===t?(r={},n={case:!0,punctuation:!1,whitespace:!0,unicode:!0},(e=this).list.forEach((function(t){var e=t.text(n);r[e]=r[e]||0,r[e]+=1})),e.list.sort((function(t,e){var i=r[t.text(n)],o=r[e.text(n)];return io?-1:0})),e):Ar.hasOwnProperty(t)?function(t){var e={};return t.json({terms:{offset:!0}}).forEach((function(t){e[t.terms[0].id]=t.terms[0].offset.start})),t.list=t.list.sort((function(t,r){return e[t.start]>e[r.start]?1:e[t.start]0){i+=s;continue}}if(void 0===r[o]||!0!==r.hasOwnProperty(o))if(o===t[i].reduced||!0!==r.hasOwnProperty(t[i].reduced)){if(!0===_r.test(o)){var a=o.replace(_r,"");!0===r.hasOwnProperty(a)&&t[i].tag(r[a],"noprefix-lexicon",e)}}else t[i].tag(r[t[i].reduced],"lexicon",e);else t[i].tag(r[o],"lexicon",e)}return t},qr=function(t){var e=t.termList();return Gr(e,t.world),t.world.taggers.forEach((function(e){e(t)})),t},Lr=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"stripPeriods",value:function(){return this.termList().forEach((function(t){!0===t.tags.Abbreviation&&t.next&&(t.post=t.post.replace(/^\./,""));var e=t.text.replace(/\./,"");t.set(e)})),this}},{key:"addPeriods",value:function(){return this.termList().forEach((function(t){t.post=t.post.replace(/^\./,""),t.post="."+t.post})),this}}]),o}(t);return r.prototype.unwrap=r.prototype.stripPeriods,t.prototype.abbreviations=function(t){var e=this.match("#Abbreviation");return"number"==typeof t&&(e=e.get(t)),new r(e.list,this,this.world)},t},Wr=/\./,Ur=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"stripPeriods",value:function(){return this.termList().forEach((function(t){var e=t.text.replace(/\./g,"");t.set(e)})),this}},{key:"addPeriods",value:function(){return this.termList().forEach((function(t){var e=t.text.replace(/\./g,"");e=e.split("").join("."),!1===Wr.test(t.post)&&(e+="."),t.set(e)})),this}}]),o}(t);return r.prototype.unwrap=r.prototype.stripPeriods,r.prototype.strip=r.prototype.stripPeriods,t.prototype.acronyms=function(t){var e=this.match("#Acronym");return"number"==typeof t&&(e=e.get(t)),new r(e.list,this,this.world)},t},Rr=function(t){return t.prototype.clauses=function(e){var r=this.if("@hasComma").notIf("@hasComma @hasComma").notIf("@hasComma . .? (and|or) .").notIf("(#City && @hasComma) #Country").notIf("(#WeekDay && @hasComma) #Date").notIf("(#Date && @hasComma) #Year").notIf("@hasComma (too|also)$").match("@hasComma"),n=this.splitAfter(r),i=n.quotations(),o=(n=n.splitOn(i)).parentheses(),s=(n=n.splitOn(o)).if("#Copula #Adjective #Conjunction (#Pronoun|#Determiner) #Verb").match("#Conjunction"),a=(n=n.splitBefore(s)).if("if .{2,9} then .").match("then"),u=(n=(n=(n=(n=(n=(n=n.splitBefore(a)).splitBefore("as well as .")).splitBefore("such as .")).splitBefore("in addition to .")).splitAfter("@hasSemicolon")).splitAfter("@hasDash")).filter((function(t){return t.wordCount()>5&&t.match("#Verb+").length>=2}));if(u.found){var c=u.splitAfter("#Noun .* #Verb .* #Noun+");n=n.splitOn(c.eq(0))}return"number"==typeof e&&(n=n.get(e)),new t(n.list,this,this.world)},t},Hr=function(t){var r=function(t){i(o,t);var r=u(o);function o(t,n,i){var s;return e(this,o),(s=r.call(this,t,n,i)).contracted=null,s}return n(o,[{key:"expand",value:function(){return this.list.forEach((function(t){var e=t.terms(),r=e[0].isTitleCase();e.forEach((function(t,r){t.set(t.implicit||t.text),t.implicit=void 0,r1&&void 0!==arguments[1]?arguments[1]:{},n=this.match("(#City && @hasComma) (#Region|#Country)"),i=this.not(n).splitAfter("@hasComma"),o=(i=i.concat(n)).quotations();return o.found&&(i=i.splitOn(o.eq(0))),i=i.match("#Noun+ (of|by)? the? #Noun+?"),!0!==e.keep_anaphora&&(i=(i=(i=(i=i.not("#Pronoun")).not("(there|these)")).not("(#Month|#WeekDay)")).not("(my|our|your|their|her|his)")),i=i.not("(of|for|by|the)$"),"number"==typeof t&&(i=i.get(t)),new r(i.list,this,this.world)},t},cn=/\(/,hn=/\)/,ln=function(t){var r=function(t){i(o,t);var r=u(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"unwrap",value:function(){return this.list.forEach((function(t){var e=t.terms(0);e.pre=e.pre.replace(cn,"");var r=t.lastTerm();r.post=r.post.replace(hn,"")})),this}}]),o}(t);return t.prototype.parentheses=function(t){var e=[];return this.list.forEach((function(t){for(var r=t.terms(),n=0;n0}}),Object.defineProperty(this,"length",{get:function(){return o.list.length}}),Object.defineProperty(this,"isA",{get:function(){return"Doc"}})}return n(t,[{key:"tagger",value:function(){return qr(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),t}();Tn.prototype.buildFrom=function(t){return t=t.map((function(t){return t.clone(!0)})),new Tn(t,this,this.world)},Tn.prototype.fromText=function(t){var e=Pe(t,this.world,this.pool());return this.buildFrom(e)},Object.assign(Tn.prototype,Fn.misc),Object.assign(Tn.prototype,Fn.selections),Cn(Tn);var Nn={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(Nn).forEach((function(t){return Tn.prototype[t]=Tn.prototype[Nn[t]]}));var $n=Tn;return function t(e){var r=e,n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0;e&&r.addWords(e);var n=Pe(t,r),i=new $n(n,null,r);return i.tagger(),i};return n.tokenize=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0,n=r;e&&((n=n.clone()).words={},n.addWords(e));var i=Pe(t,n),o=new $n(i,null,n);return(e||o.world.taggers.length>0)&&qr(o),o},n.extend=function(t){return t($n,r,this,ee,at,ne),this},n.fromJSON=function(t){var e=je(t,r);return new $n(e,null,r)},n.clone=function(){return t(r.clone())},n.verbose=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return r.verbose(t),this},n.world=function(){return r},n.parseMatch=function(t,e){return Qt(t,e)},n.version="13.10.4",n.import=n.load,n.plugin=n.extend,n}(new Ye)})); diff --git a/builds/compromise.js b/builds/compromise.js index d31c37d7d..77de75310 100644 --- a/builds/compromise.js +++ b/builds/compromise.js @@ -1,4 +1,4 @@ -/* compromise 13.10.3 MIT */ +/* compromise 13.10.4 MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : @@ -2597,9 +2597,9 @@ // prefixes: ! [ ^ // [\!\[\^]* // match 'foo /yes/' and not 'foo/no/bar' - var bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/g; // match '(yes) but not foo(no)bar' + var bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/; // match '(yes) but not foo(no)bar' - var byParentheses = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g; // okay + var byParentheses = /([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/; // okay var byWord = / /g; @@ -2627,6 +2627,11 @@ var res = []; // parse by (blocks), next arr.forEach(function (str) { + if (isReg(str)) { + res.push(str); + return; + } + res = res.concat(str.split(byParentheses)); }); res = cleanUp(res); // split by spaces, now @@ -2645,7 +2650,7 @@ return _final; }; - var _01ParseBlocks = parseBlocks; // console.log(parseBlocks(`[#Value] [(mark|rand|won|rub|ore)] foo`)) + var _01ParseBlocks = parseBlocks; // console.log('(one two) (upto) [#Date+]'.split(byParentheses)) /* break-down a match expression into this: { @@ -3861,7 +3866,7 @@ var fromJSON_1 = fromJSON; - var _version = '13.10.3'; + var _version = '13.10.4'; var entity = ['Person', 'Place', 'Organization']; var nouns$1 = { diff --git a/builds/compromise.min.js b/builds/compromise.min.js index 3930eb5ca..9ee40197a 100644 --- a/builds/compromise.min.js +++ b/builds/compromise.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).nlp=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;rr?n:r)+1;if(Math.abs(r-n)>(a||100))return a||100;for(var i,o,s,u,l,c,h=[],d=0;d4)return r;u=o===(s=t[i-1])?0:1,l=h[p-1][i]+1,(c=h[p][i-1]+1)1&&i>1&&o===t[i-2]&&e[p-2]===s&&(c=h[p-2][i-2]+u)2&&void 0!==arguments[2]?arguments[2]:3;if(e===t)return 1;if(e.lengtht.fuzzy)return!0;if(!0===t.soft&&(a=B(t.word,e.root))>t.fuzzy)return!0}return t.word===e.clean||t.word===e.text||t.word===e.reduced}return void 0!==t.tag?!0===e.tags[t.tag]:void 0!==t.method?"function"==typeof e[t.method]&&!0===e[t.method]():void 0!==t.regex?t.regex.test(e.clean):void 0!==t.fastOr?!(!e.implicit||!0!==t.fastOr.hasOwnProperty(e.implicit))||(t.fastOr.hasOwnProperty(e.reduced)||t.fastOr.hasOwnProperty(e.text)):void 0!==t.choices&&("and"===t.operator?t.choices.every((function(t){return O(e,t,r,n)})):t.choices.some((function(t){return O(e,t,r,n)})))},z=O=function(e,t,r,n){var a=G(e,t,r,n);return!0===t.negative?!a:a},T={},V={doesMatch:function(e,t,r){return z(this,e,t,r)},isAcronym:function(){return b(this.text)},isImplicit:function(){return""===this.text&&Boolean(this.implicit)},isKnown:function(){return Object.keys(this.tags).some((function(e){return!0!==T[e]}))},setRoot:function(e){var t=e.transforms,r=this.implicit||this.clean;if(this.tags.Plural&&(r=t.toSingular(r,e)),this.tags.Verb&&!this.tags.Negative&&!this.tags.Infinitive){var n=null;this.tags.PastTense?n="PastTense":this.tags.Gerund?n="Gerund":this.tags.PresentTense?n="PresentTense":this.tags.Participle?n="Participle":this.tags.Actor&&(n="Actor"),r=t.toInfinitive(r,e,n)}this.root=r}},J=/[\s-]/,M=/^[A-Z-]+$/,L={textOut:function(e,t,r){e=e||{};var n=this.text,a=this.pre,i=this.post;return!0===e.reduced&&(n=this.reduced||""),!0===e.root&&(n=this.root||""),!0===e.implicit&&this.implicit&&(n=this.implicit||""),!0===e.normal&&(n=this.clean||this.text||""),!0===e.root&&(n=this.root||this.reduced||""),!0===e.unicode&&(n=g(n)),!0===e.titlecase&&(this.tags.ProperNoun&&!this.titleCase()||(this.tags.Acronym?n=n.toUpperCase():M.test(n)&&!this.tags.Acronym&&(n=n.toLowerCase()))),!0===e.lowercase&&(n=n.toLowerCase()),!0===e.acronyms&&this.tags.Acronym&&(n=n.replace(/\./g,"")),!0!==e.whitespace&&!0!==e.root||(a="",i=" ",!1!==J.test(this.post)&&!e.last||this.implicit||(i="")),!0!==e.punctuation||e.root||(!0===this.hasPost(".")?i="."+i:!0===this.hasPost("?")?i="?"+i:!0===this.hasPost("!")?i="!"+i:!0===this.hasPost(",")?i=","+i:!0===this.hasEllipses()&&(i="..."+i)),!0!==t&&(a=""),!0!==r&&(i=""),!0===e.abbreviations&&this.tags.Abbreviation&&(i=i.replace(/^\./,"")),a+n+i}},S={Auxiliary:1,Possessive:1},_=function(e,t){var r=Object.keys(e.tags),n=t.tags;return r=r.sort((function(e,t){return S[t]||!n[t]?-1:n[t]?n[e]?n[e].lineage.length>n[t].lineage.length?1:n[e].isA.length>n[t].isA.length?-1:0:0:1}))},K={text:!0,tags:!0,implicit:!0,whitespace:!0,clean:!1,id:!1,index:!1,offset:!1,bestTag:!1},q={json:function(e,t){e=e||{};var r={};return(e=Object.assign({},K,e)).text&&(r.text=this.text),e.normal&&(r.normal=this.clean),e.tags&&(r.tags=Object.keys(this.tags)),e.clean&&(r.clean=this.clean),(e.id||e.offset)&&(r.id=this.id),e.implicit&&null!==this.implicit&&(r.implicit=this.implicit),e.whitespace&&(r.pre=this.pre,r.post=this.post),e.bestTag&&(r.bestTag=_(this,t)[0]),r}},R=Object.assign({},x,C,V,L,q);function W(){return"undefined"!=typeof window&&window.document}var U=function(e,t){for(e=e.toString();e.length0&&void 0!==arguments[0]?arguments[0]:"";t(this,e),r=String(r);var n=N(r);this.text=n.text||"",this.clean=n.clean,this.reduced=n.reduced,this.root=null,this.implicit=null,this.pre=n.pre||"",this.post=n.post||"",this.tags={},this.prev=null,this.next=null,this.id=c(n.clean),this.isA="Term",n.alias&&(this.alias=n.alias)}return n(e,[{key:"set",value:function(e){var t=N(e);return this.text=t.text,this.clean=t.clean,this}}]),e}();oe.prototype.clone=function(){var e=new oe(this.text);return e.pre=this.pre,e.post=this.post,e.clean=this.clean,e.reduced=this.reduced,e.root=this.root,e.implicit=this.implicit,e.tags=Object.assign({},this.tags),e},Object.assign(oe.prototype,R),Object.assign(oe.prototype,ie);var se=oe,ue={terms:function(e){if(0===this.length)return[];if(this.cache.terms)return void 0!==e?this.cache.terms[e]:this.cache.terms;for(var t=[this.pool.get(this.start)],r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0;"string"==typeof e&&(e="normal"===e?{whitespace:!0,unicode:!0,lowercase:!0,punctuation:!0,acronyms:!0,abbreviations:!0,implicit:!0,normal:!0}:"clean"===e?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,normal:!0}:"reduced"===e?{punctuation:!1,titlecase:!1,lowercase:!0,whitespace:!0,unicode:!0,implicit:!0,reduced:!0}:"implicit"===e?{punctuation:!0,implicit:!0,whitespace:!0,trim:!0}:"root"===e?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,root:!0}:{});var n=this.terms(),a=!1;n[0]&&null===n[0].prev&&null===n[n.length-1].next&&(a=!0);var i=n.reduce((function(i,o,s){if(0===s&&""===o.text&&null!==o.implicit&&!e.implicit)return i;e.last=r&&s===n.length-1;var u=!0,l=!0;return!1===a&&(0===s&&t&&(u=!1),s===n.length-1&&r&&(l=!1)),i+o.textOut(e,u,l)}),"");return!0===a&&r&&(i=le(i)),!0===e.trim&&(i=i.trim()),i}},he={trim:function(){var e=this.terms();if(e.length>0){e[0].pre=e[0].pre.replace(/^\s+/,"");var t=e[e.length-1];t.post=t.post.replace(/\s+$/,"")}return this}},de=/[.?!]\s*$/,ge=function(e,t){t[0].pre=e[0].pre;var r,n,a=e[e.length-1],i=t[t.length-1];i.post=(r=a.post,n=i.post,de.test(n)?n+r.match(/\s*$/):r),a.post="",""===a.post&&(a.post+=" ")},pe=function(e,t,r){var n=e.terms(),a=t.terms();ge(n,a),function(e,t,r){var n=e[e.length-1],a=t[t.length-1],i=n.next;n.next=t[0].id,a.next=i,i&&(r.get(i).prev=a.id);var o=e[0].id;o&&(t[0].prev=o)}(n,a,e.pool);var i=[e],o=e.start,s=[r];return(s=s.concat(r.parents())).forEach((function(e){var t=e.list.filter((function(e){return e.hasId(o)}));i=i.concat(t)})),(i=function(e){return e.filter((function(t,r){return e.indexOf(t)===r}))}(i)).forEach((function(e){e.length+=t.length})),e.cache={},e},me=/ /,fe=function(e,t,r){var n=e.start,a=t.terms();!function(e){var t=e[e.length-1];!1===me.test(t.post)&&(t.post+=" ")}(a),function(e,t,r){var n=r[r.length-1];n.next=e.start;var a=e.pool,i=a.get(e.start);i.prev&&(a.get(i.prev).next=t.start),r[0].prev=e.terms(0).prev,e.terms(0).prev=n.id}(e,t,a);var i=[e],o=[r];return(o=o.concat(r.parents())).forEach((function(e){var r=e.list.filter((function(e){return e.hasId(n)||e.hasId(t.start)}));i=i.concat(r)})),(i=function(e){return e.filter((function(t,r){return e.indexOf(t)===r}))}(i)).forEach((function(e){e.length+=t.length,e.start===n&&(e.start=t.start),e.cache={}})),e},ve=function(e,t){var r=t.pool(),n=e.terms(),a=r.get(n[0].prev)||{},i=r.get(n[n.length-1].next)||{};n[0].implicit&&a.implicit&&(a.set(a.implicit),a.post+=" "),function(e,t,r,n){var a=e.parents();a.push(e),a.forEach((function(e){var a=e.list.find((function(e){return e.hasId(t)}));a&&(a.length-=r,a.start===t&&(a.start=n.id),a.cache={})})),e.list=e.list.filter((function(e){return!(!e.start||!e.length)}))}(t,e.start,e.length,i),a&&(a.next=i.id),i&&(i.prev=a.id)},be={append:function(e,t){return pe(this,e,t),this},prepend:function(e,t){return fe(this,e,t),this},delete:function(e){return ve(this,e),this},replace:function(e,t){var r=this.length;pe(this,e,t);var n=this.buildFrom(this.start,this.length);n.length=r,ve(n,t)},splitOn:function(e){var t=this.terms(),r={before:null,match:null,after:null},n=t.findIndex((function(t){return t.id===e.start}));if(-1===n)return r;var a=t.slice(0,n);a.length>0&&(r.before=this.buildFrom(a[0].id,a.length));var i=t.slice(n,n+e.length);i.length>0&&(r.match=this.buildFrom(i[0].id,i.length));var o=t.slice(n+e.length,t.length);return o.length>0&&(r.after=this.buildFrom(o[0].id,o.length,this.pool)),r}},ye={json:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r={};return e.text&&(r.text=this.text()),e.normal&&(r.normal=this.text("normal")),e.clean&&(r.clean=this.text("clean")),e.reduced&&(r.reduced=this.text("reduced")),e.implicit&&(r.implicit=this.text("implicit")),e.root&&(r.root=this.text("root")),e.trim&&(r.text&&(r.text=r.text.trim()),r.normal&&(r.normal=r.normal.trim()),r.reduced&&(r.reduced=r.reduced.trim())),e.terms&&(!0===e.terms&&(e.terms={}),r.terms=this.terms().map((function(r){return r.json(e.terms,t)}))),r}},we={lookAhead:function(e){e||(e=".*");var t=this.pool,r=[],n=this.terms();return function e(n){var a=t.get(n);a&&(r.push(a),a.prev&&e(a.next))}(n[n.length-1].next),0===r.length?[]:this.buildFrom(r[0].id,r.length).match(e)},lookBehind:function(e){e||(e=".*");var t=this.pool,r=[];return function e(n){var a=t.get(n);a&&(r.push(a),a.prev&&e(a.prev))}(t.get(this.start).prev),0===r.length?[]:this.buildFrom(r[r.length-1].id,r.length).match(e)}},ke=Object.assign({},ue,ce,he,be,ye,we),Ae=function(e,t){if(0===t.length)return!0;for(var r=0;r0)return!0;if(!0===n.anything&&!0===n.negative)return!0}return!1},De=I((function(e,t){t.getGreedy=function(e,t){for(var r=Object.assign({},e.regs[e.r],{start:!1,end:!1}),n=e.t;e.t1&&void 0!==arguments[1]?arguments[1]:0,n=e.regs[e.r],a=!1,i=0;it&&(t=r.length),n}))&&t},t.getGroup=function(e,t,r){if(e.groups[e.groupId])return e.groups[e.groupId];var n=e.terms[t].id;return e.groups[e.groupId]={group:String(r),start:n,length:0},e.groups[e.groupId]}})),$e=function(e,t,r,n){for(var a={t:0,terms:e,r:0,regs:t,groups:{},start_i:r,phrase_length:n,hasGroup:!1,groupId:null,previousGroup:null};a.ra.t)return null;if(!0===i.end&&a.start_i+a.t!==n)return null}if(!0===a.hasGroup){var m=De.getGroup(a,d,i.named);a.t>1&&i.greedy?m.length+=a.t-d:m.length++}}else{if(i.negative){var f=Object.assign({},i);if(f.negative=!1,!0===a.terms[a.t].doesMatch(f,a.start_i+a.t,a.phrase_length))return null}if(!0!==i.optional){if(a.terms[a.t].isImplicit()&&t[a.r-1]&&a.terms[a.t+1]){if(a.terms[a.t-1]&&a.terms[a.t-1].implicit===t[a.r-1].word)return null;if(a.terms[a.t+1].doesMatch(i,a.start_i+a.t,a.phrase_length)){a.t+=2;continue}}return null}}}else{var v=De.greedyTo(a,t[a.r+1]);if(void 0!==i.min&&v-a.ti.max){a.t=a.t+i.max;continue}if(null===v)return null;!0===a.hasGroup&&(De.getGroup(a,a.t,i.named).length=v-a.t),a.t=v}}return{match:a.terms.slice(0,a.t),groups:a.groups}},Pe=function(e,t,r){if(!r||0===r.length)return r;if(t.some((function(e){return e.end}))){var n=e[e.length-1];r=r.filter((function(e){return-1!==e.match.indexOf(n)}))}return r},He=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/g,je=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g,Ee=/ /g,Ne=function(e){return e=(e=e.map((function(e){return e.trim()}))).filter((function(e){return e}))},Ie=function(e){var t=e.split(He),r=[];t.forEach((function(e){r=r.concat(e.split(je))})),r=Ne(r);var n=[];return r.forEach((function(e){!function(e){return/^[\!\[\^]*(<[^<]*>)?\(/.test(e)&&/\)[\?\]\+\*\$~]*$/.test(e)}(e)&&!function(e){return/^[\!\[\^]*(<[^<]*>)?\//.test(e)&&/\/[\?\]\+\*\$~]*$/.test(e)}(e)?n=n.concat(e.split(Ee)):n.push(e)})),n=Ne(n)},xe=/\{([0-9]+,?[0-9]*)\}/,Ce=/&&/,Fe=new RegExp(/^< *?(\S+) *?>/),Be=function(e){return e[e.length-1]},Oe=function(e){return e[0]},Ge=function(e){return e.substr(1)},ze=function(e){return e.substr(0,e.length-1)},Te=function(e){return e=Ge(e),e=ze(e)},Ve=function e(t){for(var r,n={},a=0;a<2;a+=1){if("$"===Be(t)&&(n.end=!0,t=ze(t)),"^"===Oe(t)&&(n.start=!0,t=Ge(t)),("["===Oe(t)||"]"===Be(t))&&(n.named=!0,"["===Oe(t)?n.groupType="]"===Be(t)?"single":"start":n.groupType="end",t=(t=t.replace(/^\[/,"")).replace(/\]$/,""),"<"===Oe(t))){var i=Fe.exec(t);i.length>=2&&(n.named=i[1],t=t.replace(i[0],""))}if("+"===Be(t)&&(n.greedy=!0,t=ze(t)),"*"!==t&&"*"===Be(t)&&"\\*"!==t&&(n.greedy=!0,t=ze(t)),"?"===Be(t)&&(n.optional=!0,t=ze(t)),"!"===Oe(t)&&(n.negative=!0,t=Ge(t)),"("===Oe(t)&&")"===Be(t)){Ce.test(t)?(n.choices=t.split(Ce),n.operator="and"):(n.choices=t.split("|"),n.operator="or"),n.choices[0]=Ge(n.choices[0]);var o=n.choices.length-1;n.choices[o]=ze(n.choices[o]),n.choices=n.choices.map((function(e){return e.trim()})),n.choices=n.choices.filter((function(e){return e})),n.choices=n.choices.map((function(t){return t.split(/ /g).map(e)})),t=""}if("/"===Oe(t)&&"/"===Be(t))return t=Te(t),n.regex=new RegExp(t),n;if("~"===Oe(t)&&"~"===Be(t))return t=Te(t),n.soft=!0,n.word=t,n}return!0===xe.test(t)&&(t=t.replace(xe,(function(e,t){var r=t.split(/,/g);return 1===r.length?(n.min=Number(r[0]),n.max=Number(r[0])):(n.min=Number(r[0]),n.max=Number(r[1]||999)),n.greedy=!0,n.optional=!0,""}))),"#"===Oe(t)?(n.tag=Ge(t),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===Oe(t)?(n.method=Ge(t),n):"."===t?(n.anything=!0,n):"*"===t?(n.anything=!0,n.greedy=!0,n.optional=!0,n):(t&&(t=(t=t.replace("\\*","*")).replace("\\.","."),n.word=t.toLowerCase()),n)},Je=function(e){for(var t,r=!1,n=-1,a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.filter((function(e){return e.groupType})).length;return r>0&&(e=Je(e)),t.fuzzy||(e=Me(e)),e},Se=function(e){return"[object Array]"===Object.prototype.toString.call(e)},_e=function(e){return[{choices:e.map((function(e){return[{word:e}]})),operator:"or"}]},Ke=function(e){if(!e||!e.list||!e.list[0])return[];var t=[];return e.list.forEach((function(e){var r=[];e.terms().forEach((function(e){r.push(e.id)})),t.push(r)})),[{idBlocks:t}]},qe=function(e,t){return!0===t.fuzzy&&(t.fuzzy=.85),"number"==typeof t.fuzzy&&(e=e.map((function(e){return t.fuzzy>0&&e.word&&(e.fuzzy=t.fuzzy),e.choices&&e.choices.forEach((function(e){e.forEach((function(e){e.fuzzy=t.fuzzy}))})),e}))),e},Re=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null==t||""===t)return[];if("object"===e(t)){if(Se(t)){if(0===t.length||!t[0])return[];if("object"===e(t[0]))return t;if("string"==typeof t[0])return _e(t)}return t&&"Doc"===t.isA?Ke(t):[]}"number"==typeof t&&(t=String(t));var n=Ie(t);return n=n.map((function(e){return Ve(e)})),n=Le(n,r),n=qe(n,r)},We=function(e,t){for(var r=[],n=t[0].idBlocks,a=function(t){n.forEach((function(n){0!==n.length?n.every((function(r,n){return i=t,e[t+n].id===r}))&&(r.push({match:e.slice(t,t+n.length)}),t+=n.length-1):i=t})),i=t},i=0;i2&&void 0!==arguments[2]&&arguments[2];if("string"==typeof t&&(t=Re(t)),!0===Ae(e,t))return[];var n=t.filter((function(e){return!0!==e.optional&&!0!==e.negative})).length,a=e.terms(),i=[];if(t[0].idBlocks){var o=We(a,t);if(o&&o.length>0)return Pe(a,t,o)}if(!0===t[0].start){var s=$e(a,t,0,a.length);return s&&s.match&&s.match.length>0&&(s.match=s.match.filter((function(e){return e})),i.push(s)),Pe(a,t,i)}for(var u=0;ua.length);u+=1){var l=$e(a.slice(u),t,u,a.length);if(l&&l.match&&l.match.length>0&&(u+=l.match.length-1,l.match=l.match.filter((function(e){return e})),i.push(l),!0===r))return Pe(a,t,i)}return Pe(a,t,i)},Qe=function(e,t){var r={};Ue(e,t).forEach((function(e){e.match.forEach((function(e){r[e.id]=!0}))}));var n=e.terms(),a=[],i=[];return n.forEach((function(e){!0!==r[e.id]?i.push(e):i.length>0&&(a.push(i),i=[])})),i.length>0&&a.push(i),a},Ze={match:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=Ue(this,e,r);return n=n.map((function(e){var r=e.match,n=e.groups,a=t.buildFrom(r[0].id,r.length,n);return a.cache.terms=r,a}))},has:function(e){return Ue(this,e,!0).length>0},not:function(e){var t=this,r=Qe(this,e);return r=r.map((function(e){return t.buildFrom(e[0].id,e.length)}))},canBe:function(e,t){for(var r=this,n=[],a=this.terms(),i=!1,o=0;o0})).map((function(e){return r.buildFrom(e[0].id,e.length)}))}},Xe=function e(r,n,a){t(this,e),this.start=r,this.length=n,this.isA="Phrase",Object.defineProperty(this,"pool",{enumerable:!1,writable:!0,value:a}),Object.defineProperty(this,"cache",{enumerable:!1,writable:!0,value:{}}),Object.defineProperty(this,"groups",{enumerable:!1,writable:!0,value:{}})};Xe.prototype.buildFrom=function(e,t,r){var n=new Xe(e,t,this.pool);return r&&Object.keys(r).length>0?n.groups=r:n.groups=this.groups,n},Object.assign(Xe.prototype,Ze),Object.assign(Xe.prototype,ke);var Ye={term:"terms"};Object.keys(Ye).forEach((function(e){return Xe.prototype[e]=Xe.prototype[Ye[e]]}));var et=Xe,tt=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t(this,e),Object.defineProperty(this,"words",{enumerable:!1,value:r})}return n(e,[{key:"add",value:function(e){return this.words[e.id]=e,this}},{key:"get",value:function(e){return this.words[e]}},{key:"remove",value:function(e){delete this.words[e]}},{key:"merge",value:function(e){return Object.assign(this.words,e.words),this}},{key:"stats",value:function(){return{words:Object.keys(this.words).length}}}]),e}();tt.prototype.clone=function(){var e=this,t=Object.keys(this.words).reduce((function(t,r){var n=e.words[r].clone();return t[n.id]=n,t}),{});return new tt(t)};var rt=tt,nt=function(e){e.forEach((function(t,r){r>0&&(t.prev=e[r-1].id),e[r+1]&&(t.next=e[r+1].id)}))},at=/(\S.+?[.!?\u203D\u2E18\u203C\u2047-\u2049])(?=\s+|$)/g,it=/\S/,ot=/[ .][A-Z]\.? *$/i,st=/(?:\u2026|\.{2,}) *$/,ut=/((?:\r?\n|\r)+)/,lt=/[a-z0-9\u00C0-\u00FF\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/i,ct=/^\s+/,ht=function(e,t){if(!0===ot.test(e))return!1;if(!0===st.test(e))return!1;if(!1===lt.test(e))return!1;var r=e.replace(/[.!?\u203D\u2E18\u203C\u2047-\u2049] *$/,"").split(" "),n=r[r.length-1].toLowerCase();return!t.hasOwnProperty(n)},dt=function(e,t){var r=t.cache.abbreviations;e=e||"";var n=[],a=[];if(!(e=String(e))||"string"!=typeof e||!1===it.test(e))return n;for(var i=function(e){for(var t=[],r=e.split(ut),n=0;n0&&(n.push(l),a[u]="")}if(0===n.length)return[e];for(var c=1;c0?(t[t.length-1]+=i,t.push(s)):t.push(i+s),i=""):i+=s}return i&&(0===t.length&&(t[0]=""),t[t.length-1]+=i),t=(t=function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,n=null;"string"!=typeof e&&("number"==typeof e?e=String(e):kt(e)&&(n=e)),n=(n=n||dt(e,t)).map((function(e){return wt(e)})),r=r||new rt;var a=n.map((function(e){e=e.map((function(e){var t=new se(e);return r.add(t),t})),nt(e);var t=new et(e[0].id,e.length,r);return t.cache.terms=e,t}));return a},Dt=function(e,t){var r=new rt;return e.map((function(e,n){var a=e.terms.map((function(a,i){var o=new se(a.text);return o.pre=void 0!==a.pre?a.pre:"",void 0===a.post&&(a.post=" ",i>=e.terms.length-1&&(a.post=". ",n>=e.terms.length-1&&(a.post="."))),o.post=void 0!==a.post?a.post:" ",a.tags&&a.tags.forEach((function(e){return o.tag(e,"",t)})),r.add(o),o}));return nt(a),new et(a[0].id,a.length,r)}))},$t=["Person","Place","Organization"],Pt={Noun:{notA:["Verb","Adjective","Adverb"]},Singular:{isA:"Noun",notA:"Plural"},ProperNoun:{isA:"Noun"},Person:{isA:["ProperNoun","Singular"],notA:["Place","Organization","Date"]},FirstName:{isA:"Person"},MaleName:{isA:"FirstName",notA:["FemaleName","LastName"]},FemaleName:{isA:"FirstName",notA:["MaleName","LastName"]},LastName:{isA:"Person",notA:["FirstName"]},NickName:{isA:"Person",notA:["FirstName","LastName"]},Honorific:{isA:"Noun",notA:["FirstName","LastName","Value"]},Place:{isA:"Singular",notA:["Person","Organization"]},Country:{isA:["Place","ProperNoun"],notA:["City"]},City:{isA:["Place","ProperNoun"],notA:["Country"]},Region:{isA:["Place","ProperNoun"]},Address:{isA:"Place"},Organization:{isA:["Singular","ProperNoun"],notA:["Person","Place"]},SportsTeam:{isA:"Organization"},School:{isA:"Organization"},Company:{isA:"Organization"},Plural:{isA:"Noun",notA:["Singular"]},Uncountable:{isA:"Noun"},Pronoun:{isA:"Noun",notA:$t},Actor:{isA:"Noun",notA:$t},Activity:{isA:"Noun",notA:["Person","Place"]},Unit:{isA:"Noun",notA:$t},Demonym:{isA:["Noun","ProperNoun"],notA:$t},Possessive:{isA:"Noun"}},Ht={Verb:{notA:["Noun","Adjective","Adverb","Value"]},PresentTense:{isA:"Verb",notA:["PastTense","FutureTense"]},Infinitive:{isA:"PresentTense",notA:["PastTense","Gerund"]},Imperative:{isA:"Infinitive"},Gerund:{isA:"PresentTense",notA:["PastTense","Copula","FutureTense"]},PastTense:{isA:"Verb",notA:["FutureTense"]},FutureTense:{isA:"Verb"},Copula:{isA:"Verb"},Modal:{isA:"Verb",notA:["Infinitive"]},PerfectTense:{isA:"Verb",notA:"Gerund"},Pluperfect:{isA:"Verb"},Participle:{isA:"PastTense"},PhrasalVerb:{isA:"Verb"},Particle:{isA:"PhrasalVerb"},Auxiliary:{notA:["Noun","Adjective","Value"]}},jt={Value:{notA:["Verb","Adjective","Adverb"]},Ordinal:{isA:"Value",notA:["Cardinal"]},Cardinal:{isA:"Value",notA:["Ordinal"]},Fraction:{isA:"Value",notA:["Noun"]},RomanNumeral:{isA:"Cardinal",notA:["Ordinal","TextValue"]},TextValue:{isA:"Value",notA:["NumericValue"]},NumericValue:{isA:"Value",notA:["TextValue"]},Money:{isA:"Cardinal"},Percent:{isA:"Value"}},Et=["Noun","Verb","Adjective","Adverb","Value","QuestionWord"],Nt={Adjective:{notA:["Noun","Verb","Adverb","Value"]},Comparable:{isA:["Adjective"]},Comparative:{isA:["Adjective"]},Superlative:{isA:["Adjective"],notA:["Comparative"]},NumberRange:{isA:["Contraction"]},Adverb:{notA:["Noun","Verb","Adjective","Value"]},Date:{notA:["Verb","Adverb","Preposition","Adjective"]},Month:{isA:["Date","Singular"],notA:["Year","WeekDay","Time"]},WeekDay:{isA:["Date","Noun"]},Timezone:{isA:["Date","Noun"],notA:["Adjective","ProperNoun"]},Time:{isA:["Date"],notA:["AtMention"]},Determiner:{notA:Et},Conjunction:{notA:Et},Preposition:{notA:Et},QuestionWord:{notA:["Determiner"]},Currency:{isA:["Noun"]},Expression:{notA:["Noun","Adjective","Verb","Adverb"]},Abbreviation:{},Url:{notA:["HashTag","PhoneNumber","Verb","Adjective","Value","AtMention","Email"]},PhoneNumber:{notA:["HashTag","Verb","Adjective","Value","AtMention","Email"]},HashTag:{},AtMention:{isA:["Noun"],notA:["HashTag","Verb","Adjective","Value","Email"]},Emoji:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Emoticon:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Email:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Acronym:{notA:["Plural","RomanNumeral"]},Negative:{notA:["Noun","Adjective","Value"]},Condition:{notA:["Verb","Adjective","Noun","Value"]}},It={Noun:"blue",Verb:"green",Negative:"green",Date:"red",Value:"red",Adjective:"magenta",Preposition:"cyan",Conjunction:"cyan",Determiner:"cyan",Adverb:"cyan"},xt=function(e){return Object.keys(e).forEach((function(t){e[t].color?e[t].color=e[t].color:It[t]?e[t].color=It[t]:e[t].isA.some((function(r){return!!It[r]&&(e[t].color=It[r],!0)}))})),e},Ct=function(e){return Object.keys(e).forEach((function(t){for(var r=e[t],n=r.isA.length,a=0;a=0;i--,a*=36){var o=e.charCodeAt(i)-48;o>10&&(o-=7),t+=o*a}return t},Lt=function(e,t,r){var n=Mt(t);return n1&&(r.hasCompound[i[0]]=!0),void 0===qt[a]?void 0!==t[n]?("string"==typeof t[n]&&(t[n]=[t[n]]),"string"==typeof a?t[n].push(a):t[n]=t[n].concat(a)):t[n]=a:qt[a](t,n,r)}))},Wt=function(e){var t=Object.assign({},Kt);return Object.keys(Tt).forEach((function(r){var n=_t(Tt[r]);Object.keys(n).forEach((function(e){n[e]=r})),Rt(n,t,e)})),t},Ut=Rt,Qt=function(e){for(var t=e.irregulars.nouns,r=Object.keys(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:"",t=e[e.length-1];if(!0===nr.hasOwnProperty(t))for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r={};return t&&t.irregulars&&!0===t.irregulars.verbs.hasOwnProperty(e)&&(r=Object.assign({},t.irregulars.verbs[e])),void 0===(r=Object.assign({},or(e),r)).Gerund&&(r.Gerund=ur.Gerund(e)),void 0===r.PastTense&&(r.PastTense=ur.PastTense(e)),void 0===r.PresentTense&&(r.PresentTense=ur.PresentTense(e)),r},cr=[/ght$/,/nge$/,/ough$/,/ain$/,/uel$/,/[au]ll$/,/ow$/,/oud$/,/...p$/],hr=[/ary$/],dr={nice:"nicest",late:"latest",hard:"hardest",inner:"innermost",outer:"outermost",far:"furthest",worse:"worst",bad:"worst",good:"best",big:"biggest",large:"largest"},gr=[{reg:/y$/i,repl:"iest"},{reg:/([aeiou])t$/i,repl:"$1ttest"},{reg:/([aeou])de$/i,repl:"$1dest"},{reg:/nge$/i,repl:"ngest"},{reg:/([aeiou])te$/i,repl:"$1test"}],pr=[/ght$/,/nge$/,/ough$/,/ain$/,/uel$/,/[au]ll$/,/ow$/,/old$/,/oud$/,/e[ae]p$/],mr=[/ary$/,/ous$/],fr={grey:"greyer",gray:"grayer",green:"greener",yellow:"yellower",red:"redder",good:"better",well:"better",bad:"worse",sad:"sadder",big:"bigger"},vr=[{reg:/y$/i,repl:"ier"},{reg:/([aeiou])t$/i,repl:"$1tter"},{reg:/([aeou])de$/i,repl:"$1der"},{reg:/nge$/i,repl:"nger"}],br={toSuperlative:function(e){if(dr.hasOwnProperty(e))return dr[e];for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r=t.irregulars.nouns;if(r.hasOwnProperty(e))return r[e];var n=Ar(e);return null!==n?n:kr.test(e)?e+"es":e+"s"},$r=[[/([^v])ies$/i,"$1y"],[/ises$/i,"isis"],[/(kn|[^o]l|w)ives$/i,"$1ife"],[/^((?:ca|e|ha|(?:our|them|your)?se|she|wo)l|lea|loa|shea|thie)ves$/i,"$1f"],[/^(dwar|handkerchie|hoo|scar|whar)ves$/i,"$1f"],[/(antenn|formul|nebul|vertebr|vit)ae$/i,"$1a"],[/(octop|vir|radi|nucle|fung|cact|stimul)(i)$/i,"$1us"],[/(buffal|tomat|tornad)(oes)$/i,"$1o"],[/(eas)es$/i,"$1e"],[/(..[aeiou]s)es$/i,"$1"],[/(vert|ind|cort)(ices)$/i,"$1ex"],[/(matr|append)(ices)$/i,"$1ix"],[/(x|ch|ss|sh|z|o)es$/i,"$1"],[/men$/i,"man"],[/(n)ews$/i,"$1ews"],[/([ti])a$/i,"$1um"],[/([^aeiouy]|qu)ies$/i,"$1y"],[/(s)eries$/i,"$1eries"],[/(m)ovies$/i,"$1ovie"],[/([m|l])ice$/i,"$1ouse"],[/(cris|ax|test)es$/i,"$1is"],[/(alias|status)es$/i,"$1"],[/(ss)$/i,"$1"],[/(ics)$/i,"$1"],[/s$/i,""]],Pr=function(e,t){var r,n=t.irregulars.nouns,a=(r=n,Object.keys(r).reduce((function(e,t){return e[r[t]]=t,e}),{}));if(a.hasOwnProperty(e))return a[e];for(var i=0;i<$r.length;i++)if(!0===$r[i][0].test(e))return e=e.replace($r[i][0],$r[i][1]);return e},Hr={Participle:[{reg:/own$/i,to:"ow"},{reg:/(.)un([g|k])$/i,to:"$1in$2"}],Actor:[{reg:/(er)er$/i,to:"$1"}],PresentTense:[{reg:/(..)(ies)$/i,to:"$1y"},{reg:/(tch|sh)es$/i,to:"$1"},{reg:/(ss|zz)es$/i,to:"$1"},{reg:/([tzlshicgrvdnkmu])es$/i,to:"$1e"},{reg:/(n[dtk]|c[kt]|[eo]n|i[nl]|er|a[ytrl])s$/i,to:"$1"},{reg:/(ow)s$/i,to:"$1"},{reg:/(op)s$/i,to:"$1"},{reg:/([eirs])ts$/i,to:"$1t"},{reg:/(ll)s$/i,to:"$1"},{reg:/(el)s$/i,to:"$1"},{reg:/(ip)es$/i,to:"$1e"},{reg:/ss$/i,to:"ss"},{reg:/s$/i,to:""}],Gerund:[{reg:/(..)(p|d|t|g){2}ing$/i,to:"$1$2"},{reg:/(ll|ss|zz)ing$/i,to:"$1"},{reg:/([^aeiou])ying$/i,to:"$1y"},{reg:/([^ae]i.)ing$/i,to:"$1e"},{reg:/(ea[dklnrtv])ing$/i,to:"$1"},{reg:/(ch|sh)ing$/i,to:"$1"},{reg:/(z)ing$/i,to:"$1e"},{reg:/(a[gdkvtc])ing$/i,to:"$1e"},{reg:/(u[rtcbn])ing$/i,to:"$1e"},{reg:/([^o]o[bdknprv])ing$/i,to:"$1e"},{reg:/([tbckg]l)ing$/i,to:"$1e"},{reg:/(c|s)ing$/i,to:"$1e"},{reg:/(..)ing$/i,to:"$1"}],PastTense:[{reg:/(ued)$/i,to:"ue"},{reg:/a([^aeiouy])ed$/i,to:"a$1e"},{reg:/([aeiou]zz)ed$/i,to:"$1"},{reg:/(e|i)lled$/i,to:"$1ll"},{reg:/(.)(sh|ch)ed$/i,to:"$1$2"},{reg:/(tl|gl)ed$/i,to:"$1e"},{reg:/(um?pt?)ed$/i,to:"$1"},{reg:/(ss)ed$/i,to:"$1"},{reg:/pped$/i,to:"p"},{reg:/tted$/i,to:"t"},{reg:/(..)gged$/i,to:"$1g"},{reg:/(..)lked$/i,to:"$1lk"},{reg:/([^aeiouy][aeiou])ked$/i,to:"$1ke"},{reg:/(.[aeiou])led$/i,to:"$1l"},{reg:/(..)(h|ion|n[dt]|ai.|[cs]t|pp|all|ss|tt|int|ail|ld|en|oo.|er|k|pp|w|ou.|rt|ght|rm)ed$/i,to:"$1$2"},{reg:/(.ut)ed$/i,to:"$1e"},{reg:/(.pt)ed$/i,to:"$1"},{reg:/(us)ed$/i,to:"$1e"},{reg:/(dd)ed$/i,to:"$1"},{reg:/(..[^aeiouy])ed$/i,to:"$1e"},{reg:/(..)ied$/i,to:"$1y"},{reg:/(.o)ed$/i,to:"$1o"},{reg:/(..i)ed$/i,to:"$1"},{reg:/(.a[^aeiou])ed$/i,to:"$1"},{reg:/([aeiou][^aeiou])ed$/i,to:"$1e"},{reg:/([rl])ew$/i,to:"$1ow"},{reg:/([pl])t$/i,to:"$1t"}]},jr={Gerund:["ing"],Actor:["erer"],Infinitive:["ate","ize","tion","rify","then","ress","ify","age","nce","ect","ise","ine","ish","ace","ash","ure","tch","end","ack","and","ute","ade","ock","ite","ase","ose","use","ive","int","nge","lay","est","ain","ant","ent","eed","er","le","own","unk","ung","en"],PastTense:["ed","lt","nt","pt","ew","ld"],PresentTense:["rks","cks","nks","ngs","mps","tes","zes","ers","les","acks","ends","ands","ocks","lays","eads","lls","els","ils","ows","nds","ays","ams","ars","ops","ffs","als","urs","lds","ews","ips","es","ts","ns"]},Er=jr=Object.keys(jr).reduce((function(e,t){return jr[t].forEach((function(r){return e[r]=t})),e}),{}),Nr={nouns:{addendum:"addenda",alga:"algae",alumna:"alumnae",alumnus:"alumni",analysis:"analyses",antenna:"antennae",appendix:"appendices",avocado:"avocados",axis:"axes",bacillus:"bacilli",barracks:"barracks",beau:"beaux",bus:"buses",cactus:"cacti",chateau:"chateaux",child:"children",circus:"circuses",clothes:"clothes",corpus:"corpora",criterion:"criteria",curriculum:"curricula",database:"databases",deer:"deer",diagnosis:"diagnoses",echo:"echoes",embargo:"embargoes",epoch:"epochs",foot:"feet",formula:"formulae",fungus:"fungi",genus:"genera",goose:"geese",halo:"halos",hippopotamus:"hippopotami",index:"indices",larva:"larvae",leaf:"leaves",libretto:"libretti",loaf:"loaves",man:"men",matrix:"matrices",memorandum:"memoranda",modulus:"moduli",mosquito:"mosquitoes",mouse:"mice",nebula:"nebulae",nucleus:"nuclei",octopus:"octopi",opus:"opera",ovum:"ova",ox:"oxen",parenthesis:"parentheses",person:"people",phenomenon:"phenomena",prognosis:"prognoses",quiz:"quizzes",radius:"radii",referendum:"referenda",rodeo:"rodeos",sex:"sexes",shoe:"shoes",sombrero:"sombreros",stimulus:"stimuli",stomach:"stomachs",syllabus:"syllabi",synopsis:"synopses",tableau:"tableaux",thesis:"theses",thief:"thieves",tooth:"teeth",tornado:"tornados",tuxedo:"tuxedos",vertebra:"vertebrae"},verbs:rr},Ir={conjugate:lr,adjectives:yr,toPlural:Dr,toSingular:Pr,toInfinitive:function(e,t,r){if(!e)return"";if(!0===t.words.hasOwnProperty(e))for(var n=t.irregulars.verbs,a=Object.keys(n),i=0;i1&&void 0!==arguments[1]?arguments[1]:{};"string"!=typeof t&&"number"!=typeof t&&null!==t||(t={group:t});var r=Re(e,t);if(0===r.length)return this.buildFrom([]);if(!1===zr(this,r))return this.buildFrom([]);var n=this.list.reduce((function(e,t){return e.concat(t.match(r))}),[]);return void 0!==t.group&&null!==t.group&&""!==t.group?this.buildFrom(n).groups(t.group):this.buildFrom(n)},t.not=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t);if(0===r.length||!1===zr(this,r))return this;var n=this.list.reduce((function(e,t){return e.concat(t.not(r))}),[]);return this.buildFrom(n)},t.matchOne=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t);if(!1===zr(this,r))return this.buildFrom([]);for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t);if(!1===zr(this,r))return this.buildFrom([]);var n=this.list.filter((function(e){return!0===e.has(r)}));return this.buildFrom(n)},t.ifNo=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t),n=this.list.filter((function(e){return!1===e.has(r)}));return this.buildFrom(n)},t.has=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t);return!1!==zr(this,r)&&this.list.some((function(e){return!0===e.has(r)}))},t.lookAhead=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e||(e=".*");var r=Re(e,t),n=[];return this.list.forEach((function(e){n=n.concat(e.lookAhead(r))})),n=n.filter((function(e){return e})),this.buildFrom(n)},t.lookAfter=t.lookAhead,t.lookBehind=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e||(e=".*");var r=Re(e,t),n=[];return this.list.forEach((function(e){n=n.concat(e.lookBehind(r))})),n=n.filter((function(e){return e})),this.buildFrom(n)},t.lookBefore=t.lookBehind,t.before=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t),n=this.if(r).list,a=n.map((function(e){var t=e.terms().map((function(e){return e.id})),n=e.match(r)[0],a=t.indexOf(n.start);return 0===a||-1===a?null:e.buildFrom(e.start,a)}));return a=a.filter((function(e){return null!==e})),this.buildFrom(a)},t.after=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Re(e,t),n=this.if(r).list,a=n.map((function(e){var t=e.terms(),n=t.map((function(e){return e.id})),a=e.match(r)[0],i=n.indexOf(a.start);if(-1===i||!t[i+a.length])return null;var o=t[i+a.length].id,s=e.length-i-a.length;return e.buildFrom(o,s)}));return a=a.filter((function(e){return null!==e})),this.buildFrom(a)},t.hasAfter=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookAfter(e,t).found}))},t.hasBefore=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookBefore(e,t).found}))}})),Vr=function(e,t,r,n){var a=[];"string"==typeof e&&(a=e.split(" ")),t.list.forEach((function(i){var o=i.terms();!0===r&&(o=o.filter((function(r){return r.canBe(e,t.world)}))),o.forEach((function(r,i){a.length>1?a[i]&&"."!==a[i]&&r.tag(a[i],n,t.world):r.tag(e,n,t.world)}))}))},Jr={tag:function(e,t){return e?(Vr(e,this,!1,t),this):this},tagSafe:function(e,t){return e?(Vr(e,this,!0,t),this):this},unTag:function(e,t){var r=this;return this.list.forEach((function(n){n.terms().forEach((function(n){return n.unTag(e,t,r.world)}))})),this},canBe:function(e){if(!e)return this;var t=this.world,r=this.list.reduce((function(r,n){return r.concat(n.canBe(e,t))}),[]);return this.buildFrom(r)}},Mr={map:function(t){var r=this;if(!t)return this;var n=this.list.map((function(e,n){var a=r.buildFrom([e]);a.from=null;var i=t(a,n);return i&&i.list&&i.list[0]?i.list[0]:i}));return 0===(n=n.filter((function(e){return e}))).length?this.buildFrom(n):"object"!==e(n[0])||"Phrase"!==n[0].isA?n:this.buildFrom(n)},forEach:function(e,t){var r=this;return e?(this.list.forEach((function(n,a){var i=r.buildFrom([n]);!0===t&&(i.from=null),e(i,a)})),this):this},filter:function(e){var t=this;if(!e)return this;var r=this.list.filter((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)}));return this.buildFrom(r)},find:function(e){var t=this;if(!e)return this;var r=this.list.find((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)}));return r?this.buildFrom([r]):void 0},some:function(e){var t=this;return e?this.list.some((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)})):this},random:function(e){if(!this.found)return this;var t=Math.floor(Math.random()*this.list.length);if(void 0===e){var r=[this.list[t]];return this.buildFrom(r)}return t+e>this.length&&(t=(t=this.length-e)<0?0:t),this.slice(t,t+e)}},Lr=function(e){return e.split(/[ -]/g)},Sr=function(e,t,r){for(var n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r={};return e.forEach((function(e,n){var a=!0;void 0!==t[n]&&(a=t[n]),e=(e=(e||"").toLowerCase()).replace(/[,;.!?]+$/,"");var i=Lr(e).map((function(e){return e.trim()}));r[i[0]]=r[i[0]]||{},1===i.length?r[i[0]].value=a:(r[i[0]].more=r[i[0]].more||[],r[i[0]].more.push({rest:i.slice(1),value:a}))})),r}(e,t),a=[],i=function(e){for(var t=r.list[e],i=t.terms().map((function(e){return e.reduced})),o=function(e){void 0!==n[i[e]]&&(void 0!==n[i[e]].more&&n[i[e]].more.forEach((function(r){void 0!==i[e+r.rest.length]&&(!0===r.rest.every((function(t,r){return t===i[e+r+1]}))&&a.push({id:t.terms()[e].id,value:r.value,length:r.rest.length+1}))})),void 0!==n[i[e]].value&&a.push({id:t.terms()[e].id,value:n[i[e]].value,length:1}))},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return t?(!0===n&&(n={keepTags:!0}),!1===n&&(n={keepTags:!1}),n=n||{},this.uncache(),this.list.forEach((function(a){var i,o=t;if("function"==typeof t&&(o=t(a)),o&&"object"===e(o)&&"Doc"===o.isA)i=o.list,r.pool().merge(o.pool());else{if("string"!=typeof o)return;!1!==n.keepCase&&a.terms(0).isTitleCase()&&(o=qr(o)),i=At(o,r.world,r.pool());var s=r.buildFrom(i);s.tagger(),i=s.list}if(!0===n.keepTags){var u=a.json({terms:{tags:!0}}).terms;i[0].terms().forEach((function(e,t){u[t]&&e.tagSafe(u[t].tags,"keptTag",r.world)}))}a.replace(i[0],r)})),this):this.delete()},replace:function(e,t,r){return void 0===t?this.replaceWith(e,r):(this.match(e).replaceWith(t,r),this)}},Wr=I((function(e,t){var r=function(e){return e&&"[object Object]"===Object.prototype.toString.call(e)},n=function(e,t){var r=At(e,t.world)[0],n=t.buildFrom([r]);return n.tagger(),t.list=n.list,t};t.append=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return t?this.found?(this.uncache(),this.list.forEach((function(n){var a;r(t)&&"Doc"===t.isA?a=t.list[0].clone():"string"==typeof t&&(a=At(t,e.world,e.pool())[0]),e.buildFrom([a]).tagger(),n.append(a,e)})),this):n(t,this):this},t.insertAfter=t.append,t.insertAt=t.append,t.prepend=function(e){var t=this;return e?this.found?(this.uncache(),this.list.forEach((function(n){var a;r(e)&&"Doc"===e.isA?a=e.list[0].clone():"string"==typeof e&&(a=At(e,t.world,t.pool())[0]),t.buildFrom([a]).tagger(),n.prepend(a,t)})),this):n(e,this):this},t.insertBefore=t.prepend,t.concat=function(){this.uncache();for(var e=this.list.slice(0),t=0;t0&&void 0!==arguments[0]?arguments[0]:{};if("number"==typeof t&&this.list[t])return this.list[t].json(r);!0===(t=n(t)).root&&this.list.forEach((function(t){t.terms().forEach((function(t){null===t.root&&t.setRoot(e.world)}))}));var a=this.list.map((function(r){return r.json(t,e.world)}));if((t.terms.offset||t.offset||t.terms.index||t.index)&&Zr(this,a,t),t.frequency||t.freq||t.count){var i={};this.list.forEach((function(e){var t=e.text("reduced");i[t]=i[t]||0,i[t]+=1})),this.list.forEach((function(e,t){a[t].count=i[e.text("reduced")]}))}if(t.unique){var o={};a=a.filter((function(e){return!0!==o[e.reduced]&&(o[e.reduced]=!0,!0)}))}return a},t.data=t.json})),Yr=I((function(e){var t="",r=function(e,t){for(e=e.toString();e.lengtht.count?-1:e.countn?1:0},length:function(e,t){var r=e.text().trim().length,n=t.text().trim().length;return rn?-1:0},wordCount:function(e,t){var r=e.wordCount(),n=t.wordCount();return rn?-1:0}};rn.alphabetical=rn.alpha,rn.wordcount=rn.wordCount;var nn={index:!0,sequence:!0,seq:!0,sequential:!0,chron:!0,chronological:!0},an={sort:function(e){return"freq"===(e=e||"alpha")||"frequency"===e||"topk"===e?(r={},n={case:!0,punctuation:!1,whitespace:!0,unicode:!0},(t=this).list.forEach((function(e){var t=e.text(n);r[t]=r[t]||0,r[t]+=1})),t.list.sort((function(e,t){var a=r[e.text(n)],i=r[t.text(n)];return ai?-1:0})),t):nn.hasOwnProperty(e)?function(e){var t={};return e.json({terms:{offset:!0}}).forEach((function(e){t[e.terms[0].id]=e.terms[0].offset.start})),e.list=e.list.sort((function(e,r){return t[e.start]>t[r.start]?1:t[e.start]0){a+=o;continue}}if(void 0===r[i]||!0!==r.hasOwnProperty(i))if(i===e[a].reduced||!0!==r.hasOwnProperty(e[a].reduced)){if(!0===Dn.test(i)){var s=i.replace(Dn,"");!0===r.hasOwnProperty(s)&&e[a].tag(r[s],"noprefix-lexicon",t)}}else e[a].tag(r[e[a].reduced],"lexicon",t);else e[a].tag(r[i],"lexicon",t)}return e},Hn=/[\'‘’‛‵′`´]$/,jn=/^(m|k|cm|km|m)\/(s|h|hr)$/,En=[[/^[\w\.]+@[\w\.]+\.[a-z]{2,3}$/,"Email"],[/^#[a-z0-9_\u00C0-\u00FF]{2,}$/,"HashTag"],[/^@1?[0-9](am|pm)$/i,"Time"],[/^@1?[0-9]:[0-9]{2}(am|pm)?$/i,"Time"],[/^@\w{2,}$/,"AtMention"],[/^(https?:\/\/|www\.)\w+\.[a-z]{2,3}/,"Url"],[/^[\w./]+\.(com|net|gov|org|ly|edu|info|biz|ru|jp|de|in|uk|br)/,"Url"],[/^'[0-9]{2}$/,"Year"],[/^[012]?[0-9](:[0-5][0-9])(:[0-5][0-9])$/,"Time"],[/^[012]?[0-9](:[0-5][0-9])?(:[0-5][0-9])? ?(am|pm)$/i,"Time"],[/^[012]?[0-9](:[0-5][0-9])(:[0-5][0-9])? ?(am|pm)?$/i,"Time"],[/^[PMCE]ST$/,"Time"],[/^utc ?[+-]?[0-9]+?$/,"Time"],[/^[a-z0-9]*? o\'?clock$/,"Time"],[/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}/i,"Date"],[/^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,4}$/,"Date"],[/^[0-9]{1,4}\/[0-9]{1,2}\/[0-9]{1,4}$/,"Date"],[/^[0-9]{1,4}-[a-z]{2,9}-[0-9]{1,4}$/i,"Date"],[/^gmt[+-][0-9][0-9]?$/i,"Timezone"],[/^utc[+-][0-9][0-9]?$/i,"Timezone"],[/^ma?c\'.*/,"LastName"],[/^o\'[drlkn].*/,"LastName"],[/^ma?cd[aeiou]/,"LastName"],[/^(lol)+[sz]$/,"Expression"],[/^woo+a*?h?$/,"Expression"],[/^(un|de|re)\\-[a-z\u00C0-\u00FF]{2}/,"Verb"],[/^[0-9]{1,4}\.[0-9]{1,2}\.[0-9]{1,4}$/,"Date"],[/^[0-9]{3}-[0-9]{4}$/,"PhoneNumber"],[/^(\+?[0-9][ -])?[0-9]{3}[ -]?[0-9]{3}-[0-9]{4}$/,"PhoneNumber"],[/^[-+]?[\$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6][-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?(k|m|b|bn)?\+?$/,["Money","Value"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?[\$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6]\+?$/,["Money","Value"]],[/^[-+]?[\$£]?[0-9]([0-9,.])+?(usd|eur|jpy|gbp|cad|aud|chf|cny|hkd|nzd|kr|rub)$/i,["Money","Value"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?\+?$/,["Cardinal","NumericValue"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?(st|nd|rd|r?th)$/,["Ordinal","NumericValue"]],[/^\.[0-9]+\+?$/,["Cardinal","NumericValue"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?%\+?$/,["Percent","Cardinal","NumericValue"]],[/^\.[0-9]+%$/,["Percent","Cardinal","NumericValue"]],[/^[0-9]{1,4}\/[0-9]{1,4}(st|nd|rd|th)?s?$/,["Fraction","NumericValue"]],[/^[0-9.]{1,2}[-–][0-9]{1,2}$/,["Value","NumberRange"]],[/^[0-9.]{1,3}(st|nd|rd|th)?[-–][0-9\.]{1,3}(st|nd|rd|th)?$/,"NumberRange"],[/^[0-9.]+([a-z]{1,4})$/,"Value"]],Nn=/^[IVXLCDM]{2,}$/,In=/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,xn="Adjective",Cn="Infinitive",Fn="PresentTense",Bn="Singular",On="PastTense",Gn="Adverb",zn="Expression",Tn="Actor",Vn="Verb",Jn="Noun",Mn="LastName",Ln={a:[[/.[aeiou]na$/,Jn],[/.[oau][wvl]ska$/,Mn],[/.[^aeiou]ica$/,Bn],[/^([hyj]a)+$/,zn]],c:[[/.[^aeiou]ic$/,xn]],d:[[/[aeiou](pp|ll|ss|ff|gg|tt|rr|bb|nn|mm)ed$/,On],[/.[aeo]{2}[bdgmnprvz]ed$/,On],[/.[aeiou][sg]hed$/,On],[/.[aeiou]red$/,On],[/.[aeiou]r?ried$/,On],[/.[bcdgtr]led$/,On],[/.[aoui]f?led$/,On],[/.[iao]sed$/,On],[/[aeiou]n?[cs]ed$/,On],[/[aeiou][rl]?[mnf]ed$/,On],[/[aeiou][ns]?c?ked$/,On],[/[aeiou][nl]?ged$/,On],[/.[tdbwxz]ed$/,On],[/[^aeiou][aeiou][tvx]ed$/,On],[/.[cdlmnprstv]ied$/,On],[/[^aeiou]ard$/,Bn],[/[aeiou][^aeiou]id$/,xn],[/.[vrl]id$/,xn]],e:[[/.[lnr]ize$/,Cn],[/.[^aeiou]ise$/,Cn],[/.[aeiou]te$/,Cn],[/.[^aeiou][ai]ble$/,xn],[/.[^aeiou]eable$/,xn],[/.[ts]ive$/,xn]],h:[[/.[^aeiouf]ish$/,xn],[/.v[iy]ch$/,Mn],[/^ug?h+$/,zn],[/^uh[ -]?oh$/,zn]],i:[[/.[oau][wvl]ski$/,Mn]],k:[[/^(k){2}$/,zn]],l:[[/.[gl]ial$/,xn],[/.[^aeiou]ful$/,xn],[/.[nrtumcd]al$/,xn],[/.[^aeiou][ei]al$/,xn]],m:[[/.[^aeiou]ium$/,Bn],[/[^aeiou]ism$/,Bn],[/^h*u*m+$/,zn],[/^\d+ ?[ap]m$/,"Date"]],n:[[/.[lsrnpb]ian$/,xn],[/[^aeiou]ician$/,Tn],[/[aeiou][ktrp]in$/,"Gerund"]],o:[[/^no+$/,zn],[/^(yo)+$/,zn],[/^woo+[pt]?$/,zn]],r:[[/.[bdfklmst]ler$/,"Noun"],[/[aeiou][pns]er$/,Bn],[/[^i]fer$/,Cn],[/.[^aeiou][ao]pher$/,Tn],[/.[lk]er$/,"Noun"],[/.ier$/,"Comparative"]],t:[[/.[di]est$/,"Superlative"],[/.[icldtgrv]ent$/,xn],[/[aeiou].*ist$/,xn],[/^[a-z]et$/,Vn]],s:[[/.[^aeiou]ises$/,Fn],[/.[rln]ates$/,Fn],[/.[^z]ens$/,Vn],[/.[lstrn]us$/,Bn],[/.[aeiou]sks$/,Fn],[/.[aeiou]kes$/,Fn],[/[aeiou][^aeiou]is$/,Bn],[/[a-z]\'s$/,Jn],[/^yes+$/,zn]],v:[[/.[^aeiou][ai][kln]ov$/,Mn]],y:[[/.[cts]hy$/,xn],[/.[st]ty$/,xn],[/.[gk]y$/,xn],[/.[tnl]ary$/,xn],[/.[oe]ry$/,Bn],[/[rdntkbhs]ly$/,Gn],[/...lly$/,Gn],[/[bszmp]{2}y$/,xn],[/.(gg|bb|zz)ly$/,xn],[/.[ai]my$/,xn],[/[ea]{2}zy$/,xn],[/.[^aeiou]ity$/,Bn]]},Sn="Adjective",_n="Infinitive",Kn="PresentTense",qn="Singular",Rn="PastTense",Wn="Adverb",Un="Plural",Qn="Actor",Zn="Verb",Xn="Noun",Yn="LastName",ea="Modal",ta=[null,null,{ea:qn,ia:Xn,ic:Sn,ly:Wn,"'n":Zn,"'t":Zn},{oed:Rn,ued:Rn,xed:Rn," so":Wn,"'ll":ea,"'re":"Copula",azy:Sn,eer:Xn,end:Zn,ped:Rn,ffy:Sn,ify:_n,ing:"Gerund",ize:_n,lar:Sn,mum:Sn,nes:Kn,nny:Sn,oid:Sn,ous:Sn,que:Sn,rol:qn,sis:qn,zes:Kn},{amed:Rn,aped:Rn,ched:Rn,lked:Rn,nded:Rn,cted:Rn,dged:Rn,akis:Yn,cede:_n,chuk:Yn,czyk:Yn,ects:Kn,ends:Zn,enko:Yn,ette:qn,fies:Kn,fore:Wn,gate:_n,gone:Sn,ices:Un,ints:Un,ines:Un,ions:Un,less:Wn,llen:Sn,made:Sn,nsen:Yn,oses:Kn,ould:ea,some:Sn,sson:Yn,tage:_n,teen:"Value",tion:qn,tive:Sn,tors:Xn,vice:qn},{tized:Rn,urned:Rn,eased:Rn,ances:Un,bound:Sn,ettes:Un,fully:Wn,ishes:Kn,ities:Un,marek:Yn,nssen:Yn,ology:Xn,ports:Un,rough:Sn,tches:Kn,tieth:"Ordinal",tures:Un,wards:Wn,where:Wn},{auskas:Yn,keeper:Qn,logist:Qn,teenth:"Value"},{opoulos:Yn,borough:"Place",sdottir:Yn}],ra={":(":!0,":)":!0,":P":!0,":p":!0,":O":!0,":3":!0,":|":!0,":/":!0,":\\":!0,":$":!0,":*":!0,":@":!0,":-(":!0,":-)":!0,":-P":!0,":-p":!0,":-O":!0,":-3":!0,":-|":!0,":-/":!0,":-\\":!0,":-$":!0,":-*":!0,":-@":!0,":^(":!0,":^)":!0,":^P":!0,":^p":!0,":^O":!0,":^3":!0,":^|":!0,":^/":!0,":^\\":!0,":^$":!0,":^*":!0,":^@":!0,"):":!0,"(:":!0,"$:":!0,"*:":!0,")-:":!0,"(-:":!0,"$-:":!0,"*-:":!0,")^:":!0,"(^:":!0,"$^:":!0,"*^:":!0,"<3":!0,"2){var a=n.clean[n.clean.length-2];if("s"===a)return void n.tag(["Possessive","Noun"],"end-tick",r);"n"===a&&n.tag(["Gerund"],"chillin",r)}jn.test(n.text)&&n.tag("Unit","per-sec",r)},regex:function(e,t){for(var r=e.text,n=0;n=2&&Nn.test(r)&&In.test(r)&&e.tag("RomanNumeral","xvii",t)},suffix:function(e,t){!function(e,t){var r=e.clean.length,n=7;r<=n&&(n=r-1);for(var a=n;a>1;a-=1){var i=e.clean.substr(r-a,r);if(!0===ta[i.length].hasOwnProperty(i)){var o=ta[i.length][i];e.tagSafe(o,"suffix -"+i,t);break}}}(e,t),function(e,t){var r=e.clean,n=r[r.length-1];if(!0===Ln.hasOwnProperty(n))for(var a=Ln[n],i=0;i35)}(n=(n=n.trim()).replace(/[.!?,]$/,""))&&(e.tag("Emoji","comma-emoji",t),e.text=n,e.pre=e.pre.replace(":",""),e.post=e.post.replace(":","")),e.text.match(na)&&(e.tag("Emoji","unicode-emoji",t),e.text=n),!0===(r=(r=n).replace(/^[:;]/,":"),ra.hasOwnProperty(r))&&(e.tag("Emoticon","emoticon-emoji",t),e.text=n)}},ia=function(e,t){var r=e.world;aa.lexicon(t,r);for(var n=0;n3&&void 0!==r[n]&&!0===r.hasOwnProperty(n)&&e.tag(r[n],"stem-"+n,t)}}))},fa={isSingular:[/(ax|test)is$/i,/(octop|vir|radi|nucle|fung|cact|stimul)us$/i,/(octop|vir)i$/i,/(rl)f$/i,/(alias|status)$/i,/(bu)s$/i,/(al|ad|at|er|et|ed|ad)o$/i,/(ti)um$/i,/(ti)a$/i,/sis$/i,/(?:(^f)fe|(lr)f)$/i,/hive$/i,/s[aeiou]+ns$/i,/(^aeiouy|qu)y$/i,/(x|ch|ss|sh|z)$/i,/(matr|vert|ind|cort)(ix|ex)$/i,/(m|l)ouse$/i,/(m|l)ice$/i,/(antenn|formul|nebul|vertebr|vit)a$/i,/.sis$/i,/^(?!talis|.*hu)(.*)man$/i],isPlural:[/(^v)ies$/i,/ises$/i,/ives$/i,/(antenn|formul|nebul|vertebr|vit)ae$/i,/(octop|vir|radi|nucle|fung|cact|stimul)i$/i,/(buffal|tomat|tornad)oes$/i,/(analy|ba|diagno|parenthe|progno|synop|the)ses$/i,/(vert|ind|cort)ices$/i,/(matr|append)ices$/i,/(x|ch|ss|sh|s|z|o)es$/i,/is$/i,/men$/i,/news$/i,/.tia$/i,/(^f)ves$/i,/(lr)ves$/i,/(^aeiouy|qu)ies$/i,/(m|l)ice$/i,/(cris|ax|test)es$/i,/(alias|status)es$/i,/ics$/i]},va=["Uncountable","Pronoun","Place","Value","Person","Month","WeekDay","Holiday"],ba=[/ss$/,/sis$/,/[^aeiou][uo]s$/,/'s$/],ya=[/i$/,/ae$/],wa=function(e,t){if(e.tags.Noun&&!e.tags.Acronym){var r=e.clean;if(e.tags.Singular||e.tags.Plural)return;if(r.length<=3)return void e.tag("Singular","short-singular",t);if(va.find((function(t){return e.tags[t]})))return;if(fa.isPlural.find((function(e){return e.test(r)})))return void e.tag("Plural","plural-rules",t);if(fa.isSingular.find((function(e){return e.test(r)})))return void e.tag("Singular","singular-rules",t);if(!0===/s$/.test(r)){if(ba.find((function(e){return e.test(r)})))return;return void e.tag("Plural","plural-fallback",t)}if(ya.find((function(e){return e.test(r)})))return;e.tag("Singular","singular-fallback",t)}},ka=["academy","administration","agence","agences","agencies","agency","airlines","airways","army","assoc","associates","association","assurance","authority","autorite","aviation","bank","banque","board","boys","brands","brewery","brotherhood","brothers","building society","bureau","cafe","caisse","capital","care","cathedral","center","central bank","centre","chemicals","choir","chronicle","church","circus","clinic","clinique","club","co","coalition","coffee","collective","college","commission","committee","communications","community","company","comprehensive","computers","confederation","conference","conseil","consulting","containers","corporation","corps","corp","council","crew","daily news","data","departement","department","department store","departments","design","development","directorate","division","drilling","education","eglise","electric","electricity","energy","ensemble","enterprise","enterprises","entertainment","estate","etat","evening news","faculty","federation","financial","fm","foundation","fund","gas","gazette","girls","government","group","guild","health authority","herald","holdings","hospital","hotel","hotels","inc","industries","institut","institute","institute of technology","institutes","insurance","international","interstate","investment","investments","investors","journal","laboratory","labs","liberation army","limited","local authority","local health authority","machines","magazine","management","marine","marketing","markets","media","memorial","mercantile exchange","ministere","ministry","military","mobile","motor","motors","musee","museum","news","news service","observatory","office","oil","optical","orchestra","organization","partners","partnership","people's party","petrol","petroleum","pharmacare","pharmaceutical","pharmaceuticals","pizza","plc","police","polytechnic","post","power","press","productions","quartet","radio","regional authority","regional health authority","reserve","resources","restaurant","restaurants","savings","school","securities","service","services","social club","societe","society","sons","standard","state police","state university","stock exchange","subcommittee","syndicat","systems","telecommunications","telegraph","television","times","tribunal","tv","union","university","utilities","workers"].reduce((function(e,t){return e[t]="Noun",e}),{}),Aa=function(e){return!!e.tags.Noun&&(!(e.tags.Pronoun||e.tags.Comma||e.tags.Possessive)&&!!(e.tags.Organization||e.tags.Acronym||e.tags.Place||e.titleCase()))},Da=/^[A-Z]('s|,)?$/,$a=/([A-Z]\.){2}[A-Z]?/i,Pa={I:!0,A:!0},Ha={neighbours:la,case:da,stem:ma,plural:wa,organizations:function(e,t){for(var r=0;r5)&&e.isAcronym()}(e,t)?(e.tag("Acronym","acronym-step",t),e.tag("Noun","acronym-infer",t)):!Pa.hasOwnProperty(e.text)&&Da.test(e.text)&&(e.tag("Acronym","one-letter-acronym",t),e.tag("Noun","one-letter-infer",t)),e.tags.Organization&&e.text.length<=3&&e.tag("Acronym","acronym-org",t),e.tags.Organization&&e.isUpperCase()&&e.text.length<=6&&e.tag("Acronym","acronym-org-case",t))}))}},ja=function(e,t){var r=e.world;return Ha.neighbours(t,r),Ha.case(e),Ha.stem(t,r),t.forEach((function(t){!1===t.isKnown()&&t.tag("Noun","noun-fallback",e.world)})),Ha.organizations(t,r),Ha.acronyms(t,r),t.forEach((function(t){Ha.plural(t,e.world)})),e},Ea=/n't$/,Na={"won't":["will","not"],wont:["will","not"],"can't":["can","not"],cant:["can","not"],cannot:["can","not"],"shan't":["should","not"],dont:["do","not"],dun:["do","not"]},Ia=function(e,t){return!0===Na.hasOwnProperty(e.clean)?Na[e.clean]:"ain't"===e.clean||"aint"===e.clean?function(e,t){var r=t.terms(),n=r.indexOf(e),a=r.slice(0,n).find((function(e){return e.tags.Noun}));return a&&a.tags.Plural?["are","not"]:["is","not"]}(e,t):!0===Ea.test(e.clean)?[e.clean.replace(Ea,""),"not"]:null},xa=/([a-z\u00C0-\u00FF]+)[\u0027\u0060\u00B4\u2018\u2019\u201A\u201B\u2032\u2035\u2039\u203A]([a-z]{1,2})$/i,Ca={ll:"will",ve:"have",re:"are",m:"am","n't":"not"},Fa=function(e){var t=e.text.match(xa);return null===t?null:Ca.hasOwnProperty(t[2])?[t[1],Ca[t[2]]]:null},Ba={wanna:["want","to"],gonna:["going","to"],im:["i","am"],alot:["a","lot"],ive:["i","have"],imma:["I","will"],"where'd":["where","did"],whered:["where","did"],"when'd":["when","did"],whend:["when","did"],howd:["how","did"],whatd:["what","did"],dunno:["do","not","know"],brb:["be","right","back"],gtg:["got","to","go"],irl:["in","real","life"],tbh:["to","be","honest"],imo:["in","my","opinion"],til:["today","i","learned"],rn:["right","now"],twas:["it","was"],"@":["at"]},Oa=function(e){return Ba.hasOwnProperty(e.clean)?Ba[e.clean]:null},Ga=/([a-z\u00C0-\u00FF]+)[\u0027\u0060\u00B4\u2018\u2019\u201A\u201B\u2032\u2035\u2039\u203A]s$/i,za={that:!0,there:!0},Ta={here:!0,there:!0,everywhere:!0},Va=function(e,t,r){var n=e.text.match(Ga);if(null!==n){if(!0===function(e,t){if(e.tags.Possessive)return!0;if(e.tags.Pronoun||e.tags.QuestionWord)return!1;if(za.hasOwnProperty(e.reduced))return!1;var r=t.get(e.next);if(!r)return!0;if(r.tags.Verb)return!!r.tags.Infinitive||!!r.tags.PresentTense;if(r.tags.Noun)return!0!==Ta.hasOwnProperty(r.reduced);var n=t.get(r.next);return!(!n||!n.tags.Noun||n.tags.Pronoun)||(r.tags.Adjective||r.tags.Adverb||r.tags.Verb,!1)}(e,t.pool))return e.tag("#Possessive","isPossessive",r),null;if(null!==n)return function(e,t){var r=t.terms(),n=r.indexOf(e);return r.slice(n+1,n+3).find((function(e){return e.tags.PastTense}))}(e,t)?[n[1],"has"]:[n[1],"is"]}return null},Ja=/[a-z\u00C0-\u00FF]'d$/,Ma={how:!0,what:!0},La=function(e,t){if(Ja.test(e.clean)){for(var r=e.clean.replace(/'d$/,""),n=t.terms(),a=n.indexOf(e),i=n.slice(a+1,a+4),o=0;o0?vi=vi.concat(t):vi.push(e)})),vi.forEach((function(e){var t,r,n;return e.required=(t=e.reg,r=[],n=[],t.forEach((function(e){!0!==e.optional&&!0!==e.negative&&(void 0!==e.tag&&r.push(e.tag),void 0!==e.word&&n.push(e.word))})),{tags:ei(r),words:ei(n)}),e}));var bi=vi,yi=function(e){bi.forEach((function(t){var r=[];t.required.words.forEach((function(t){r.push(e._cache.words[t]||[])})),t.required.tags.forEach((function(t){r.push(e._cache.tags[t]||[])}));var n=function(e){if(0===e.length)return[];var t={};e.forEach((function(e){e=ei(e);for(var r=0;r5&&e.match("#Verb+").length>=2}));if(u.found){var l=u.splitAfter("#Noun .* #Verb .* #Noun+");n=n.splitOn(l.eq(0))}return"number"==typeof t&&(n=n.get(t)),new e(n.list,this,this.world)},e},Hi=function(e){var r=function(e){a(i,e);var r=u(i);function i(e,n,a){var o;return t(this,i),(o=r.call(this,e,n,a)).contracted=null,o}return n(i,[{key:"expand",value:function(){return this.list.forEach((function(e){var t=e.terms(),r=t[0].isTitleCase();t.forEach((function(e,r){e.set(e.implicit||e.text),e.implicit=void 0,r1&&void 0!==arguments[1]?arguments[1]:{},n=this.match("(#City && @hasComma) (#Region|#Country)"),a=this.not(n).splitAfter("@hasComma"),i=(a=a.concat(n)).quotations();return i.found&&(a=a.splitOn(i.eq(0))),a=a.match("#Noun+ (of|by)? the? #Noun+?"),!0!==t.keep_anaphora&&(a=(a=(a=(a=a.not("#Pronoun")).not("(there|these)")).not("(#Month|#WeekDay)")).not("(my|our|your|their|her|his)")),a=a.not("(of|for|by|the)$"),"number"==typeof e&&(a=a.get(e)),new r(a.list,this,this.world)},e},Mi=/\(/,Li=/\)/,Si=function(e){var r=function(e){a(i,e);var r=u(i);function i(){return t(this,i),r.apply(this,arguments)}return n(i,[{key:"unwrap",value:function(){return this.list.forEach((function(e){var t=e.terms(0);t.pre=t.pre.replace(Mi,"");var r=e.lastTerm();r.post=r.post.replace(Li,"")})),this}}]),i}(e);return e.prototype.parentheses=function(e){var t=[];return this.list.forEach((function(e){for(var r=e.terms(),n=0;n0}}),Object.defineProperty(this,"length",{get:function(){return i.list.length}}),Object.defineProperty(this,"isA",{get:function(){return"Doc"}})}return n(e,[{key:"tagger",value:function(){return ki(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),e}();uo.prototype.buildFrom=function(e){return e=e.map((function(e){return e.clone(!0)})),new uo(e,this,this.world)},uo.prototype.fromText=function(e){var t=At(e,this.world,this.pool());return this.buildFrom(t)},Object.assign(uo.prototype,so.misc),Object.assign(uo.prototype,so.selections),oo(uo);var lo={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(lo).forEach((function(e){return uo.prototype[e]=uo.prototype[lo[e]]}));var co=uo,ho=function(e){var t=e.termList();return Pn(t,e.world),e.world.taggers.forEach((function(t){t(e)})),e};return function e(t){var r=t,n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0;t&&r.addWords(t);var n=At(e,r),a=new co(n,null,r);return a.tagger(),a};return n.tokenize=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,n=r;t&&((n=n.clone()).words={},n.addWords(t));var a=At(e,n),i=new co(a,null,n);return(t||i.world.taggers.length>0)&&ho(i),i},n.extend=function(e){return e(co,r,this,et,se,rt),this},n.fromJSON=function(e){var t=Dt(e,r);return new co(t,null,r)},n.clone=function(){return e(r.clone())},n.verbose=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return r.verbose(e),this},n.world=function(){return r},n.parseMatch=function(e,t){return Re(e,t)},n.version="13.10.3",n.import=n.load,n.plugin=n.extend,n}(new Br)})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).nlp=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;rr?n:r)+1;if(Math.abs(r-n)>(a||100))return a||100;for(var i,o,s,u,l,c,h=[],d=0;d4)return r;u=o===(s=t[i-1])?0:1,l=h[p-1][i]+1,(c=h[p][i-1]+1)1&&i>1&&o===t[i-2]&&e[p-2]===s&&(c=h[p-2][i-2]+u)2&&void 0!==arguments[2]?arguments[2]:3;if(e===t)return 1;if(e.lengtht.fuzzy)return!0;if(!0===t.soft&&(a=B(t.word,e.root))>t.fuzzy)return!0}return t.word===e.clean||t.word===e.text||t.word===e.reduced}return void 0!==t.tag?!0===e.tags[t.tag]:void 0!==t.method?"function"==typeof e[t.method]&&!0===e[t.method]():void 0!==t.regex?t.regex.test(e.clean):void 0!==t.fastOr?!(!e.implicit||!0!==t.fastOr.hasOwnProperty(e.implicit))||(t.fastOr.hasOwnProperty(e.reduced)||t.fastOr.hasOwnProperty(e.text)):void 0!==t.choices&&("and"===t.operator?t.choices.every((function(t){return O(e,t,r,n)})):t.choices.some((function(t){return O(e,t,r,n)})))},z=O=function(e,t,r,n){var a=G(e,t,r,n);return!0===t.negative?!a:a},T={},V={doesMatch:function(e,t,r){return z(this,e,t,r)},isAcronym:function(){return b(this.text)},isImplicit:function(){return""===this.text&&Boolean(this.implicit)},isKnown:function(){return Object.keys(this.tags).some((function(e){return!0!==T[e]}))},setRoot:function(e){var t=e.transforms,r=this.implicit||this.clean;if(this.tags.Plural&&(r=t.toSingular(r,e)),this.tags.Verb&&!this.tags.Negative&&!this.tags.Infinitive){var n=null;this.tags.PastTense?n="PastTense":this.tags.Gerund?n="Gerund":this.tags.PresentTense?n="PresentTense":this.tags.Participle?n="Participle":this.tags.Actor&&(n="Actor"),r=t.toInfinitive(r,e,n)}this.root=r}},J=/[\s-]/,M=/^[A-Z-]+$/,L={textOut:function(e,t,r){e=e||{};var n=this.text,a=this.pre,i=this.post;return!0===e.reduced&&(n=this.reduced||""),!0===e.root&&(n=this.root||""),!0===e.implicit&&this.implicit&&(n=this.implicit||""),!0===e.normal&&(n=this.clean||this.text||""),!0===e.root&&(n=this.root||this.reduced||""),!0===e.unicode&&(n=g(n)),!0===e.titlecase&&(this.tags.ProperNoun&&!this.titleCase()||(this.tags.Acronym?n=n.toUpperCase():M.test(n)&&!this.tags.Acronym&&(n=n.toLowerCase()))),!0===e.lowercase&&(n=n.toLowerCase()),!0===e.acronyms&&this.tags.Acronym&&(n=n.replace(/\./g,"")),!0!==e.whitespace&&!0!==e.root||(a="",i=" ",!1!==J.test(this.post)&&!e.last||this.implicit||(i="")),!0!==e.punctuation||e.root||(!0===this.hasPost(".")?i="."+i:!0===this.hasPost("?")?i="?"+i:!0===this.hasPost("!")?i="!"+i:!0===this.hasPost(",")?i=","+i:!0===this.hasEllipses()&&(i="..."+i)),!0!==t&&(a=""),!0!==r&&(i=""),!0===e.abbreviations&&this.tags.Abbreviation&&(i=i.replace(/^\./,"")),a+n+i}},S={Auxiliary:1,Possessive:1},_=function(e,t){var r=Object.keys(e.tags),n=t.tags;return r=r.sort((function(e,t){return S[t]||!n[t]?-1:n[t]?n[e]?n[e].lineage.length>n[t].lineage.length?1:n[e].isA.length>n[t].isA.length?-1:0:0:1}))},K={text:!0,tags:!0,implicit:!0,whitespace:!0,clean:!1,id:!1,index:!1,offset:!1,bestTag:!1},q={json:function(e,t){e=e||{};var r={};return(e=Object.assign({},K,e)).text&&(r.text=this.text),e.normal&&(r.normal=this.clean),e.tags&&(r.tags=Object.keys(this.tags)),e.clean&&(r.clean=this.clean),(e.id||e.offset)&&(r.id=this.id),e.implicit&&null!==this.implicit&&(r.implicit=this.implicit),e.whitespace&&(r.pre=this.pre,r.post=this.post),e.bestTag&&(r.bestTag=_(this,t)[0]),r}},R=Object.assign({},x,C,V,L,q);function W(){return"undefined"!=typeof window&&window.document}var U=function(e,t){for(e=e.toString();e.length0&&void 0!==arguments[0]?arguments[0]:"";t(this,e),r=String(r);var n=N(r);this.text=n.text||"",this.clean=n.clean,this.reduced=n.reduced,this.root=null,this.implicit=null,this.pre=n.pre||"",this.post=n.post||"",this.tags={},this.prev=null,this.next=null,this.id=c(n.clean),this.isA="Term",n.alias&&(this.alias=n.alias)}return n(e,[{key:"set",value:function(e){var t=N(e);return this.text=t.text,this.clean=t.clean,this}}]),e}();oe.prototype.clone=function(){var e=new oe(this.text);return e.pre=this.pre,e.post=this.post,e.clean=this.clean,e.reduced=this.reduced,e.root=this.root,e.implicit=this.implicit,e.tags=Object.assign({},this.tags),e},Object.assign(oe.prototype,R),Object.assign(oe.prototype,ie);var se=oe,ue={terms:function(e){if(0===this.length)return[];if(this.cache.terms)return void 0!==e?this.cache.terms[e]:this.cache.terms;for(var t=[this.pool.get(this.start)],r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0;"string"==typeof e&&(e="normal"===e?{whitespace:!0,unicode:!0,lowercase:!0,punctuation:!0,acronyms:!0,abbreviations:!0,implicit:!0,normal:!0}:"clean"===e?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,normal:!0}:"reduced"===e?{punctuation:!1,titlecase:!1,lowercase:!0,whitespace:!0,unicode:!0,implicit:!0,reduced:!0}:"implicit"===e?{punctuation:!0,implicit:!0,whitespace:!0,trim:!0}:"root"===e?{titlecase:!1,lowercase:!0,punctuation:!0,whitespace:!0,unicode:!0,implicit:!0,root:!0}:{});var n=this.terms(),a=!1;n[0]&&null===n[0].prev&&null===n[n.length-1].next&&(a=!0);var i=n.reduce((function(i,o,s){if(0===s&&""===o.text&&null!==o.implicit&&!e.implicit)return i;e.last=r&&s===n.length-1;var u=!0,l=!0;return!1===a&&(0===s&&t&&(u=!1),s===n.length-1&&r&&(l=!1)),i+o.textOut(e,u,l)}),"");return!0===a&&r&&(i=le(i)),!0===e.trim&&(i=i.trim()),i}},he={trim:function(){var e=this.terms();if(e.length>0){e[0].pre=e[0].pre.replace(/^\s+/,"");var t=e[e.length-1];t.post=t.post.replace(/\s+$/,"")}return this}},de=/[.?!]\s*$/,ge=function(e,t){t[0].pre=e[0].pre;var r,n,a=e[e.length-1],i=t[t.length-1];i.post=(r=a.post,n=i.post,de.test(n)?n+r.match(/\s*$/):r),a.post="",""===a.post&&(a.post+=" ")},pe=function(e,t,r){var n=e.terms(),a=t.terms();ge(n,a),function(e,t,r){var n=e[e.length-1],a=t[t.length-1],i=n.next;n.next=t[0].id,a.next=i,i&&(r.get(i).prev=a.id);var o=e[0].id;o&&(t[0].prev=o)}(n,a,e.pool);var i=[e],o=e.start,s=[r];return(s=s.concat(r.parents())).forEach((function(e){var t=e.list.filter((function(e){return e.hasId(o)}));i=i.concat(t)})),(i=function(e){return e.filter((function(t,r){return e.indexOf(t)===r}))}(i)).forEach((function(e){e.length+=t.length})),e.cache={},e},me=/ /,fe=function(e,t,r){var n=e.start,a=t.terms();!function(e){var t=e[e.length-1];!1===me.test(t.post)&&(t.post+=" ")}(a),function(e,t,r){var n=r[r.length-1];n.next=e.start;var a=e.pool,i=a.get(e.start);i.prev&&(a.get(i.prev).next=t.start),r[0].prev=e.terms(0).prev,e.terms(0).prev=n.id}(e,t,a);var i=[e],o=[r];return(o=o.concat(r.parents())).forEach((function(e){var r=e.list.filter((function(e){return e.hasId(n)||e.hasId(t.start)}));i=i.concat(r)})),(i=function(e){return e.filter((function(t,r){return e.indexOf(t)===r}))}(i)).forEach((function(e){e.length+=t.length,e.start===n&&(e.start=t.start),e.cache={}})),e},ve=function(e,t){var r=t.pool(),n=e.terms(),a=r.get(n[0].prev)||{},i=r.get(n[n.length-1].next)||{};n[0].implicit&&a.implicit&&(a.set(a.implicit),a.post+=" "),function(e,t,r,n){var a=e.parents();a.push(e),a.forEach((function(e){var a=e.list.find((function(e){return e.hasId(t)}));a&&(a.length-=r,a.start===t&&(a.start=n.id),a.cache={})})),e.list=e.list.filter((function(e){return!(!e.start||!e.length)}))}(t,e.start,e.length,i),a&&(a.next=i.id),i&&(i.prev=a.id)},be={append:function(e,t){return pe(this,e,t),this},prepend:function(e,t){return fe(this,e,t),this},delete:function(e){return ve(this,e),this},replace:function(e,t){var r=this.length;pe(this,e,t);var n=this.buildFrom(this.start,this.length);n.length=r,ve(n,t)},splitOn:function(e){var t=this.terms(),r={before:null,match:null,after:null},n=t.findIndex((function(t){return t.id===e.start}));if(-1===n)return r;var a=t.slice(0,n);a.length>0&&(r.before=this.buildFrom(a[0].id,a.length));var i=t.slice(n,n+e.length);i.length>0&&(r.match=this.buildFrom(i[0].id,i.length));var o=t.slice(n+e.length,t.length);return o.length>0&&(r.after=this.buildFrom(o[0].id,o.length,this.pool)),r}},ye={json:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r={};return e.text&&(r.text=this.text()),e.normal&&(r.normal=this.text("normal")),e.clean&&(r.clean=this.text("clean")),e.reduced&&(r.reduced=this.text("reduced")),e.implicit&&(r.implicit=this.text("implicit")),e.root&&(r.root=this.text("root")),e.trim&&(r.text&&(r.text=r.text.trim()),r.normal&&(r.normal=r.normal.trim()),r.reduced&&(r.reduced=r.reduced.trim())),e.terms&&(!0===e.terms&&(e.terms={}),r.terms=this.terms().map((function(r){return r.json(e.terms,t)}))),r}},we={lookAhead:function(e){e||(e=".*");var t=this.pool,r=[],n=this.terms();return function e(n){var a=t.get(n);a&&(r.push(a),a.prev&&e(a.next))}(n[n.length-1].next),0===r.length?[]:this.buildFrom(r[0].id,r.length).match(e)},lookBehind:function(e){e||(e=".*");var t=this.pool,r=[];return function e(n){var a=t.get(n);a&&(r.push(a),a.prev&&e(a.prev))}(t.get(this.start).prev),0===r.length?[]:this.buildFrom(r[r.length-1].id,r.length).match(e)}},ke=Object.assign({},ue,ce,he,be,ye,we),Ae=function(e,t){if(0===t.length)return!0;for(var r=0;r0)return!0;if(!0===n.anything&&!0===n.negative)return!0}return!1},De=I((function(e,t){t.getGreedy=function(e,t){for(var r=Object.assign({},e.regs[e.r],{start:!1,end:!1}),n=e.t;e.t1&&void 0!==arguments[1]?arguments[1]:0,n=e.regs[e.r],a=!1,i=0;it&&(t=r.length),n}))&&t},t.getGroup=function(e,t,r){if(e.groups[e.groupId])return e.groups[e.groupId];var n=e.terms[t].id;return e.groups[e.groupId]={group:String(r),start:n,length:0},e.groups[e.groupId]}})),$e=function(e,t,r,n){for(var a={t:0,terms:e,r:0,regs:t,groups:{},start_i:r,phrase_length:n,hasGroup:!1,groupId:null,previousGroup:null};a.ra.t)return null;if(!0===i.end&&a.start_i+a.t!==n)return null}if(!0===a.hasGroup){var m=De.getGroup(a,d,i.named);a.t>1&&i.greedy?m.length+=a.t-d:m.length++}}else{if(i.negative){var f=Object.assign({},i);if(f.negative=!1,!0===a.terms[a.t].doesMatch(f,a.start_i+a.t,a.phrase_length))return null}if(!0!==i.optional){if(a.terms[a.t].isImplicit()&&t[a.r-1]&&a.terms[a.t+1]){if(a.terms[a.t-1]&&a.terms[a.t-1].implicit===t[a.r-1].word)return null;if(a.terms[a.t+1].doesMatch(i,a.start_i+a.t,a.phrase_length)){a.t+=2;continue}}return null}}}else{var v=De.greedyTo(a,t[a.r+1]);if(void 0!==i.min&&v-a.ti.max){a.t=a.t+i.max;continue}if(null===v)return null;!0===a.hasGroup&&(De.getGroup(a,a.t,i.named).length=v-a.t),a.t=v}}return{match:a.terms.slice(0,a.t),groups:a.groups}},Pe=function(e,t,r){if(!r||0===r.length)return r;if(t.some((function(e){return e.end}))){var n=e[e.length-1];r=r.filter((function(e){return-1!==e.match.indexOf(n)}))}return r},He=/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/,je=/([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/,Ee=/ /g,Ne=function(e){return/^[\!\[\^]*(<[^<]*>)?\//.test(e)&&/\/[\?\]\+\*\$~]*$/.test(e)},Ie=function(e){return e=(e=e.map((function(e){return e.trim()}))).filter((function(e){return e}))},xe=function(e){var t=e.split(He),r=[];t.forEach((function(e){Ne(e)?r.push(e):r=r.concat(e.split(je))})),r=Ie(r);var n=[];return r.forEach((function(e){!function(e){return/^[\!\[\^]*(<[^<]*>)?\(/.test(e)&&/\)[\?\]\+\*\$~]*$/.test(e)}(e)?Ne(e)?n.push(e):n=n.concat(e.split(Ee)):n.push(e)})),n=Ie(n)},Ce=/\{([0-9]+,?[0-9]*)\}/,Fe=/&&/,Be=new RegExp(/^< *?(\S+) *?>/),Oe=function(e){return e[e.length-1]},Ge=function(e){return e[0]},ze=function(e){return e.substr(1)},Te=function(e){return e.substr(0,e.length-1)},Ve=function(e){return e=ze(e),e=Te(e)},Je=function e(t){for(var r,n={},a=0;a<2;a+=1){if("$"===Oe(t)&&(n.end=!0,t=Te(t)),"^"===Ge(t)&&(n.start=!0,t=ze(t)),("["===Ge(t)||"]"===Oe(t))&&(n.named=!0,"["===Ge(t)?n.groupType="]"===Oe(t)?"single":"start":n.groupType="end",t=(t=t.replace(/^\[/,"")).replace(/\]$/,""),"<"===Ge(t))){var i=Be.exec(t);i.length>=2&&(n.named=i[1],t=t.replace(i[0],""))}if("+"===Oe(t)&&(n.greedy=!0,t=Te(t)),"*"!==t&&"*"===Oe(t)&&"\\*"!==t&&(n.greedy=!0,t=Te(t)),"?"===Oe(t)&&(n.optional=!0,t=Te(t)),"!"===Ge(t)&&(n.negative=!0,t=ze(t)),"("===Ge(t)&&")"===Oe(t)){Fe.test(t)?(n.choices=t.split(Fe),n.operator="and"):(n.choices=t.split("|"),n.operator="or"),n.choices[0]=ze(n.choices[0]);var o=n.choices.length-1;n.choices[o]=Te(n.choices[o]),n.choices=n.choices.map((function(e){return e.trim()})),n.choices=n.choices.filter((function(e){return e})),n.choices=n.choices.map((function(t){return t.split(/ /g).map(e)})),t=""}if("/"===Ge(t)&&"/"===Oe(t))return t=Ve(t),n.regex=new RegExp(t),n;if("~"===Ge(t)&&"~"===Oe(t))return t=Ve(t),n.soft=!0,n.word=t,n}return!0===Ce.test(t)&&(t=t.replace(Ce,(function(e,t){var r=t.split(/,/g);return 1===r.length?(n.min=Number(r[0]),n.max=Number(r[0])):(n.min=Number(r[0]),n.max=Number(r[1]||999)),n.greedy=!0,n.optional=!0,""}))),"#"===Ge(t)?(n.tag=ze(t),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===Ge(t)?(n.method=ze(t),n):"."===t?(n.anything=!0,n):"*"===t?(n.anything=!0,n.greedy=!0,n.optional=!0,n):(t&&(t=(t=t.replace("\\*","*")).replace("\\.","."),n.word=t.toLowerCase()),n)},Me=function(e){for(var t,r=!1,n=-1,a=0;a1&&void 0!==arguments[1]?arguments[1]:{},r=e.filter((function(e){return e.groupType})).length;return r>0&&(e=Me(e)),t.fuzzy||(e=Le(e)),e},_e=function(e){return"[object Array]"===Object.prototype.toString.call(e)},Ke=function(e){return[{choices:e.map((function(e){return[{word:e}]})),operator:"or"}]},qe=function(e){if(!e||!e.list||!e.list[0])return[];var t=[];return e.list.forEach((function(e){var r=[];e.terms().forEach((function(e){r.push(e.id)})),t.push(r)})),[{idBlocks:t}]},Re=function(e,t){return!0===t.fuzzy&&(t.fuzzy=.85),"number"==typeof t.fuzzy&&(e=e.map((function(e){return t.fuzzy>0&&e.word&&(e.fuzzy=t.fuzzy),e.choices&&e.choices.forEach((function(e){e.forEach((function(e){e.fuzzy=t.fuzzy}))})),e}))),e},We=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(null==t||""===t)return[];if("object"===e(t)){if(_e(t)){if(0===t.length||!t[0])return[];if("object"===e(t[0]))return t;if("string"==typeof t[0])return Ke(t)}return t&&"Doc"===t.isA?qe(t):[]}"number"==typeof t&&(t=String(t));var n=xe(t);return n=n.map((function(e){return Je(e)})),n=Se(n,r),n=Re(n,r)},Ue=function(e,t){for(var r=[],n=t[0].idBlocks,a=function(t){n.forEach((function(n){0!==n.length?n.every((function(r,n){return i=t,e[t+n].id===r}))&&(r.push({match:e.slice(t,t+n.length)}),t+=n.length-1):i=t})),i=t},i=0;i2&&void 0!==arguments[2]&&arguments[2];if("string"==typeof t&&(t=We(t)),!0===Ae(e,t))return[];var n=t.filter((function(e){return!0!==e.optional&&!0!==e.negative})).length,a=e.terms(),i=[];if(t[0].idBlocks){var o=Ue(a,t);if(o&&o.length>0)return Pe(a,t,o)}if(!0===t[0].start){var s=$e(a,t,0,a.length);return s&&s.match&&s.match.length>0&&(s.match=s.match.filter((function(e){return e})),i.push(s)),Pe(a,t,i)}for(var u=0;ua.length);u+=1){var l=$e(a.slice(u),t,u,a.length);if(l&&l.match&&l.match.length>0&&(u+=l.match.length-1,l.match=l.match.filter((function(e){return e})),i.push(l),!0===r))return Pe(a,t,i)}return Pe(a,t,i)},Ze=function(e,t){var r={};Qe(e,t).forEach((function(e){e.match.forEach((function(e){r[e.id]=!0}))}));var n=e.terms(),a=[],i=[];return n.forEach((function(e){!0!==r[e.id]?i.push(e):i.length>0&&(a.push(i),i=[])})),i.length>0&&a.push(i),a},Xe={match:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=Qe(this,e,r);return n=n.map((function(e){var r=e.match,n=e.groups,a=t.buildFrom(r[0].id,r.length,n);return a.cache.terms=r,a}))},has:function(e){return Qe(this,e,!0).length>0},not:function(e){var t=this,r=Ze(this,e);return r=r.map((function(e){return t.buildFrom(e[0].id,e.length)}))},canBe:function(e,t){for(var r=this,n=[],a=this.terms(),i=!1,o=0;o0})).map((function(e){return r.buildFrom(e[0].id,e.length)}))}},Ye=function e(r,n,a){t(this,e),this.start=r,this.length=n,this.isA="Phrase",Object.defineProperty(this,"pool",{enumerable:!1,writable:!0,value:a}),Object.defineProperty(this,"cache",{enumerable:!1,writable:!0,value:{}}),Object.defineProperty(this,"groups",{enumerable:!1,writable:!0,value:{}})};Ye.prototype.buildFrom=function(e,t,r){var n=new Ye(e,t,this.pool);return r&&Object.keys(r).length>0?n.groups=r:n.groups=this.groups,n},Object.assign(Ye.prototype,Xe),Object.assign(Ye.prototype,ke);var et={term:"terms"};Object.keys(et).forEach((function(e){return Ye.prototype[e]=Ye.prototype[et[e]]}));var tt=Ye,rt=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t(this,e),Object.defineProperty(this,"words",{enumerable:!1,value:r})}return n(e,[{key:"add",value:function(e){return this.words[e.id]=e,this}},{key:"get",value:function(e){return this.words[e]}},{key:"remove",value:function(e){delete this.words[e]}},{key:"merge",value:function(e){return Object.assign(this.words,e.words),this}},{key:"stats",value:function(){return{words:Object.keys(this.words).length}}}]),e}();rt.prototype.clone=function(){var e=this,t=Object.keys(this.words).reduce((function(t,r){var n=e.words[r].clone();return t[n.id]=n,t}),{});return new rt(t)};var nt=rt,at=function(e){e.forEach((function(t,r){r>0&&(t.prev=e[r-1].id),e[r+1]&&(t.next=e[r+1].id)}))},it=/(\S.+?[.!?\u203D\u2E18\u203C\u2047-\u2049])(?=\s+|$)/g,ot=/\S/,st=/[ .][A-Z]\.? *$/i,ut=/(?:\u2026|\.{2,}) *$/,lt=/((?:\r?\n|\r)+)/,ct=/[a-z0-9\u00C0-\u00FF\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]/i,ht=/^\s+/,dt=function(e,t){if(!0===st.test(e))return!1;if(!0===ut.test(e))return!1;if(!1===ct.test(e))return!1;var r=e.replace(/[.!?\u203D\u2E18\u203C\u2047-\u2049] *$/,"").split(" "),n=r[r.length-1].toLowerCase();return!t.hasOwnProperty(n)},gt=function(e,t){var r=t.cache.abbreviations;e=e||"";var n=[],a=[];if(!(e=String(e))||"string"!=typeof e||!1===ot.test(e))return n;for(var i=function(e){for(var t=[],r=e.split(lt),n=0;n0&&(n.push(l),a[u]="")}if(0===n.length)return[e];for(var c=1;c0?(t[t.length-1]+=i,t.push(s)):t.push(i+s),i=""):i+=s}return i&&(0===t.length&&(t[0]=""),t[t.length-1]+=i),t=(t=function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,n=null;"string"!=typeof e&&("number"==typeof e?e=String(e):At(e)&&(n=e)),n=(n=n||gt(e,t)).map((function(e){return kt(e)})),r=r||new nt;var a=n.map((function(e){e=e.map((function(e){var t=new se(e);return r.add(t),t})),at(e);var t=new tt(e[0].id,e.length,r);return t.cache.terms=e,t}));return a},$t=function(e,t){var r=new nt;return e.map((function(e,n){var a=e.terms.map((function(a,i){var o=new se(a.text);return o.pre=void 0!==a.pre?a.pre:"",void 0===a.post&&(a.post=" ",i>=e.terms.length-1&&(a.post=". ",n>=e.terms.length-1&&(a.post="."))),o.post=void 0!==a.post?a.post:" ",a.tags&&a.tags.forEach((function(e){return o.tag(e,"",t)})),r.add(o),o}));return at(a),new tt(a[0].id,a.length,r)}))},Pt=["Person","Place","Organization"],Ht={Noun:{notA:["Verb","Adjective","Adverb"]},Singular:{isA:"Noun",notA:"Plural"},ProperNoun:{isA:"Noun"},Person:{isA:["ProperNoun","Singular"],notA:["Place","Organization","Date"]},FirstName:{isA:"Person"},MaleName:{isA:"FirstName",notA:["FemaleName","LastName"]},FemaleName:{isA:"FirstName",notA:["MaleName","LastName"]},LastName:{isA:"Person",notA:["FirstName"]},NickName:{isA:"Person",notA:["FirstName","LastName"]},Honorific:{isA:"Noun",notA:["FirstName","LastName","Value"]},Place:{isA:"Singular",notA:["Person","Organization"]},Country:{isA:["Place","ProperNoun"],notA:["City"]},City:{isA:["Place","ProperNoun"],notA:["Country"]},Region:{isA:["Place","ProperNoun"]},Address:{isA:"Place"},Organization:{isA:["Singular","ProperNoun"],notA:["Person","Place"]},SportsTeam:{isA:"Organization"},School:{isA:"Organization"},Company:{isA:"Organization"},Plural:{isA:"Noun",notA:["Singular"]},Uncountable:{isA:"Noun"},Pronoun:{isA:"Noun",notA:Pt},Actor:{isA:"Noun",notA:Pt},Activity:{isA:"Noun",notA:["Person","Place"]},Unit:{isA:"Noun",notA:Pt},Demonym:{isA:["Noun","ProperNoun"],notA:Pt},Possessive:{isA:"Noun"}},jt={Verb:{notA:["Noun","Adjective","Adverb","Value"]},PresentTense:{isA:"Verb",notA:["PastTense","FutureTense"]},Infinitive:{isA:"PresentTense",notA:["PastTense","Gerund"]},Imperative:{isA:"Infinitive"},Gerund:{isA:"PresentTense",notA:["PastTense","Copula","FutureTense"]},PastTense:{isA:"Verb",notA:["FutureTense"]},FutureTense:{isA:"Verb"},Copula:{isA:"Verb"},Modal:{isA:"Verb",notA:["Infinitive"]},PerfectTense:{isA:"Verb",notA:"Gerund"},Pluperfect:{isA:"Verb"},Participle:{isA:"PastTense"},PhrasalVerb:{isA:"Verb"},Particle:{isA:"PhrasalVerb"},Auxiliary:{notA:["Noun","Adjective","Value"]}},Et={Value:{notA:["Verb","Adjective","Adverb"]},Ordinal:{isA:"Value",notA:["Cardinal"]},Cardinal:{isA:"Value",notA:["Ordinal"]},Fraction:{isA:"Value",notA:["Noun"]},RomanNumeral:{isA:"Cardinal",notA:["Ordinal","TextValue"]},TextValue:{isA:"Value",notA:["NumericValue"]},NumericValue:{isA:"Value",notA:["TextValue"]},Money:{isA:"Cardinal"},Percent:{isA:"Value"}},Nt=["Noun","Verb","Adjective","Adverb","Value","QuestionWord"],It={Adjective:{notA:["Noun","Verb","Adverb","Value"]},Comparable:{isA:["Adjective"]},Comparative:{isA:["Adjective"]},Superlative:{isA:["Adjective"],notA:["Comparative"]},NumberRange:{isA:["Contraction"]},Adverb:{notA:["Noun","Verb","Adjective","Value"]},Date:{notA:["Verb","Adverb","Preposition","Adjective"]},Month:{isA:["Date","Singular"],notA:["Year","WeekDay","Time"]},WeekDay:{isA:["Date","Noun"]},Timezone:{isA:["Date","Noun"],notA:["Adjective","ProperNoun"]},Time:{isA:["Date"],notA:["AtMention"]},Determiner:{notA:Nt},Conjunction:{notA:Nt},Preposition:{notA:Nt},QuestionWord:{notA:["Determiner"]},Currency:{isA:["Noun"]},Expression:{notA:["Noun","Adjective","Verb","Adverb"]},Abbreviation:{},Url:{notA:["HashTag","PhoneNumber","Verb","Adjective","Value","AtMention","Email"]},PhoneNumber:{notA:["HashTag","Verb","Adjective","Value","AtMention","Email"]},HashTag:{},AtMention:{isA:["Noun"],notA:["HashTag","Verb","Adjective","Value","Email"]},Emoji:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Emoticon:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Email:{notA:["HashTag","Verb","Adjective","Value","AtMention"]},Acronym:{notA:["Plural","RomanNumeral"]},Negative:{notA:["Noun","Adjective","Value"]},Condition:{notA:["Verb","Adjective","Noun","Value"]}},xt={Noun:"blue",Verb:"green",Negative:"green",Date:"red",Value:"red",Adjective:"magenta",Preposition:"cyan",Conjunction:"cyan",Determiner:"cyan",Adverb:"cyan"},Ct=function(e){return Object.keys(e).forEach((function(t){e[t].color?e[t].color=e[t].color:xt[t]?e[t].color=xt[t]:e[t].isA.some((function(r){return!!xt[r]&&(e[t].color=xt[r],!0)}))})),e},Ft=function(e){return Object.keys(e).forEach((function(t){for(var r=e[t],n=r.isA.length,a=0;a=0;i--,a*=36){var o=e.charCodeAt(i)-48;o>10&&(o-=7),t+=o*a}return t},St=function(e,t,r){var n=Lt(t);return n1&&(r.hasCompound[i[0]]=!0),void 0===Rt[a]?void 0!==t[n]?("string"==typeof t[n]&&(t[n]=[t[n]]),"string"==typeof a?t[n].push(a):t[n]=t[n].concat(a)):t[n]=a:Rt[a](t,n,r)}))},Ut=function(e){var t=Object.assign({},qt);return Object.keys(Vt).forEach((function(r){var n=Kt(Vt[r]);Object.keys(n).forEach((function(e){n[e]=r})),Wt(n,t,e)})),t},Qt=Wt,Zt=function(e){for(var t=e.irregulars.nouns,r=Object.keys(t),n=0;n0&&void 0!==arguments[0]?arguments[0]:"",t=e[e.length-1];if(!0===ar.hasOwnProperty(t))for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r={};return t&&t.irregulars&&!0===t.irregulars.verbs.hasOwnProperty(e)&&(r=Object.assign({},t.irregulars.verbs[e])),void 0===(r=Object.assign({},sr(e),r)).Gerund&&(r.Gerund=lr.Gerund(e)),void 0===r.PastTense&&(r.PastTense=lr.PastTense(e)),void 0===r.PresentTense&&(r.PresentTense=lr.PresentTense(e)),r},hr=[/ght$/,/nge$/,/ough$/,/ain$/,/uel$/,/[au]ll$/,/ow$/,/oud$/,/...p$/],dr=[/ary$/],gr={nice:"nicest",late:"latest",hard:"hardest",inner:"innermost",outer:"outermost",far:"furthest",worse:"worst",bad:"worst",good:"best",big:"biggest",large:"largest"},pr=[{reg:/y$/i,repl:"iest"},{reg:/([aeiou])t$/i,repl:"$1ttest"},{reg:/([aeou])de$/i,repl:"$1dest"},{reg:/nge$/i,repl:"ngest"},{reg:/([aeiou])te$/i,repl:"$1test"}],mr=[/ght$/,/nge$/,/ough$/,/ain$/,/uel$/,/[au]ll$/,/ow$/,/old$/,/oud$/,/e[ae]p$/],fr=[/ary$/,/ous$/],vr={grey:"greyer",gray:"grayer",green:"greener",yellow:"yellower",red:"redder",good:"better",well:"better",bad:"worse",sad:"sadder",big:"bigger"},br=[{reg:/y$/i,repl:"ier"},{reg:/([aeiou])t$/i,repl:"$1tter"},{reg:/([aeou])de$/i,repl:"$1der"},{reg:/nge$/i,repl:"nger"}],yr={toSuperlative:function(e){if(gr.hasOwnProperty(e))return gr[e];for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,r=t.irregulars.nouns;if(r.hasOwnProperty(e))return r[e];var n=Dr(e);return null!==n?n:Ar.test(e)?e+"es":e+"s"},Pr=[[/([^v])ies$/i,"$1y"],[/ises$/i,"isis"],[/(kn|[^o]l|w)ives$/i,"$1ife"],[/^((?:ca|e|ha|(?:our|them|your)?se|she|wo)l|lea|loa|shea|thie)ves$/i,"$1f"],[/^(dwar|handkerchie|hoo|scar|whar)ves$/i,"$1f"],[/(antenn|formul|nebul|vertebr|vit)ae$/i,"$1a"],[/(octop|vir|radi|nucle|fung|cact|stimul)(i)$/i,"$1us"],[/(buffal|tomat|tornad)(oes)$/i,"$1o"],[/(eas)es$/i,"$1e"],[/(..[aeiou]s)es$/i,"$1"],[/(vert|ind|cort)(ices)$/i,"$1ex"],[/(matr|append)(ices)$/i,"$1ix"],[/(x|ch|ss|sh|z|o)es$/i,"$1"],[/men$/i,"man"],[/(n)ews$/i,"$1ews"],[/([ti])a$/i,"$1um"],[/([^aeiouy]|qu)ies$/i,"$1y"],[/(s)eries$/i,"$1eries"],[/(m)ovies$/i,"$1ovie"],[/([m|l])ice$/i,"$1ouse"],[/(cris|ax|test)es$/i,"$1is"],[/(alias|status)es$/i,"$1"],[/(ss)$/i,"$1"],[/(ics)$/i,"$1"],[/s$/i,""]],Hr=function(e,t){var r,n=t.irregulars.nouns,a=(r=n,Object.keys(r).reduce((function(e,t){return e[r[t]]=t,e}),{}));if(a.hasOwnProperty(e))return a[e];for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{};"string"!=typeof t&&"number"!=typeof t&&null!==t||(t={group:t});var r=We(e,t);if(0===r.length)return this.buildFrom([]);if(!1===Tr(this,r))return this.buildFrom([]);var n=this.list.reduce((function(e,t){return e.concat(t.match(r))}),[]);return void 0!==t.group&&null!==t.group&&""!==t.group?this.buildFrom(n).groups(t.group):this.buildFrom(n)},t.not=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t);if(0===r.length||!1===Tr(this,r))return this;var n=this.list.reduce((function(e,t){return e.concat(t.not(r))}),[]);return this.buildFrom(n)},t.matchOne=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t);if(!1===Tr(this,r))return this.buildFrom([]);for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t);if(!1===Tr(this,r))return this.buildFrom([]);var n=this.list.filter((function(e){return!0===e.has(r)}));return this.buildFrom(n)},t.ifNo=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t),n=this.list.filter((function(e){return!1===e.has(r)}));return this.buildFrom(n)},t.has=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t);return!1!==Tr(this,r)&&this.list.some((function(e){return!0===e.has(r)}))},t.lookAhead=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e||(e=".*");var r=We(e,t),n=[];return this.list.forEach((function(e){n=n.concat(e.lookAhead(r))})),n=n.filter((function(e){return e})),this.buildFrom(n)},t.lookAfter=t.lookAhead,t.lookBehind=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e||(e=".*");var r=We(e,t),n=[];return this.list.forEach((function(e){n=n.concat(e.lookBehind(r))})),n=n.filter((function(e){return e})),this.buildFrom(n)},t.lookBefore=t.lookBehind,t.before=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t),n=this.if(r).list,a=n.map((function(e){var t=e.terms().map((function(e){return e.id})),n=e.match(r)[0],a=t.indexOf(n.start);return 0===a||-1===a?null:e.buildFrom(e.start,a)}));return a=a.filter((function(e){return null!==e})),this.buildFrom(a)},t.after=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=We(e,t),n=this.if(r).list,a=n.map((function(e){var t=e.terms(),n=t.map((function(e){return e.id})),a=e.match(r)[0],i=n.indexOf(a.start);if(-1===i||!t[i+a.length])return null;var o=t[i+a.length].id,s=e.length-i-a.length;return e.buildFrom(o,s)}));return a=a.filter((function(e){return null!==e})),this.buildFrom(a)},t.hasAfter=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookAfter(e,t).found}))},t.hasBefore=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.filter((function(r){return r.lookBefore(e,t).found}))}})),Jr=function(e,t,r,n){var a=[];"string"==typeof e&&(a=e.split(" ")),t.list.forEach((function(i){var o=i.terms();!0===r&&(o=o.filter((function(r){return r.canBe(e,t.world)}))),o.forEach((function(r,i){a.length>1?a[i]&&"."!==a[i]&&r.tag(a[i],n,t.world):r.tag(e,n,t.world)}))}))},Mr={tag:function(e,t){return e?(Jr(e,this,!1,t),this):this},tagSafe:function(e,t){return e?(Jr(e,this,!0,t),this):this},unTag:function(e,t){var r=this;return this.list.forEach((function(n){n.terms().forEach((function(n){return n.unTag(e,t,r.world)}))})),this},canBe:function(e){if(!e)return this;var t=this.world,r=this.list.reduce((function(r,n){return r.concat(n.canBe(e,t))}),[]);return this.buildFrom(r)}},Lr={map:function(t){var r=this;if(!t)return this;var n=this.list.map((function(e,n){var a=r.buildFrom([e]);a.from=null;var i=t(a,n);return i&&i.list&&i.list[0]?i.list[0]:i}));return 0===(n=n.filter((function(e){return e}))).length?this.buildFrom(n):"object"!==e(n[0])||"Phrase"!==n[0].isA?n:this.buildFrom(n)},forEach:function(e,t){var r=this;return e?(this.list.forEach((function(n,a){var i=r.buildFrom([n]);!0===t&&(i.from=null),e(i,a)})),this):this},filter:function(e){var t=this;if(!e)return this;var r=this.list.filter((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)}));return this.buildFrom(r)},find:function(e){var t=this;if(!e)return this;var r=this.list.find((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)}));return r?this.buildFrom([r]):void 0},some:function(e){var t=this;return e?this.list.some((function(r,n){var a=t.buildFrom([r]);return a.from=null,e(a,n)})):this},random:function(e){if(!this.found)return this;var t=Math.floor(Math.random()*this.list.length);if(void 0===e){var r=[this.list[t]];return this.buildFrom(r)}return t+e>this.length&&(t=(t=this.length-e)<0?0:t),this.slice(t,t+e)}},Sr=function(e){return e.split(/[ -]/g)},_r=function(e,t,r){for(var n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r={};return e.forEach((function(e,n){var a=!0;void 0!==t[n]&&(a=t[n]),e=(e=(e||"").toLowerCase()).replace(/[,;.!?]+$/,"");var i=Sr(e).map((function(e){return e.trim()}));r[i[0]]=r[i[0]]||{},1===i.length?r[i[0]].value=a:(r[i[0]].more=r[i[0]].more||[],r[i[0]].more.push({rest:i.slice(1),value:a}))})),r}(e,t),a=[],i=function(e){for(var t=r.list[e],i=t.terms().map((function(e){return e.reduced})),o=function(e){void 0!==n[i[e]]&&(void 0!==n[i[e]].more&&n[i[e]].more.forEach((function(r){void 0!==i[e+r.rest.length]&&(!0===r.rest.every((function(t,r){return t===i[e+r+1]}))&&a.push({id:t.terms()[e].id,value:r.value,length:r.rest.length+1}))})),void 0!==n[i[e]].value&&a.push({id:t.terms()[e].id,value:n[i[e]].value,length:1}))},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return t?(!0===n&&(n={keepTags:!0}),!1===n&&(n={keepTags:!1}),n=n||{},this.uncache(),this.list.forEach((function(a){var i,o=t;if("function"==typeof t&&(o=t(a)),o&&"object"===e(o)&&"Doc"===o.isA)i=o.list,r.pool().merge(o.pool());else{if("string"!=typeof o)return;!1!==n.keepCase&&a.terms(0).isTitleCase()&&(o=Rr(o)),i=Dt(o,r.world,r.pool());var s=r.buildFrom(i);s.tagger(),i=s.list}if(!0===n.keepTags){var u=a.json({terms:{tags:!0}}).terms;i[0].terms().forEach((function(e,t){u[t]&&e.tagSafe(u[t].tags,"keptTag",r.world)}))}a.replace(i[0],r)})),this):this.delete()},replace:function(e,t,r){return void 0===t?this.replaceWith(e,r):(this.match(e).replaceWith(t,r),this)}},Ur=I((function(e,t){var r=function(e){return e&&"[object Object]"===Object.prototype.toString.call(e)},n=function(e,t){var r=Dt(e,t.world)[0],n=t.buildFrom([r]);return n.tagger(),t.list=n.list,t};t.append=function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return t?this.found?(this.uncache(),this.list.forEach((function(n){var a;r(t)&&"Doc"===t.isA?a=t.list[0].clone():"string"==typeof t&&(a=Dt(t,e.world,e.pool())[0]),e.buildFrom([a]).tagger(),n.append(a,e)})),this):n(t,this):this},t.insertAfter=t.append,t.insertAt=t.append,t.prepend=function(e){var t=this;return e?this.found?(this.uncache(),this.list.forEach((function(n){var a;r(e)&&"Doc"===e.isA?a=e.list[0].clone():"string"==typeof e&&(a=Dt(e,t.world,t.pool())[0]),t.buildFrom([a]).tagger(),n.prepend(a,t)})),this):n(e,this):this},t.insertBefore=t.prepend,t.concat=function(){this.uncache();for(var e=this.list.slice(0),t=0;t0&&void 0!==arguments[0]?arguments[0]:{};if("number"==typeof t&&this.list[t])return this.list[t].json(r);!0===(t=n(t)).root&&this.list.forEach((function(t){t.terms().forEach((function(t){null===t.root&&t.setRoot(e.world)}))}));var a=this.list.map((function(r){return r.json(t,e.world)}));if((t.terms.offset||t.offset||t.terms.index||t.index)&&Xr(this,a,t),t.frequency||t.freq||t.count){var i={};this.list.forEach((function(e){var t=e.text("reduced");i[t]=i[t]||0,i[t]+=1})),this.list.forEach((function(e,t){a[t].count=i[e.text("reduced")]}))}if(t.unique){var o={};a=a.filter((function(e){return!0!==o[e.reduced]&&(o[e.reduced]=!0,!0)}))}return a},t.data=t.json})),en=I((function(e){var t="",r=function(e,t){for(e=e.toString();e.lengtht.count?-1:e.countn?1:0},length:function(e,t){var r=e.text().trim().length,n=t.text().trim().length;return rn?-1:0},wordCount:function(e,t){var r=e.wordCount(),n=t.wordCount();return rn?-1:0}};nn.alphabetical=nn.alpha,nn.wordcount=nn.wordCount;var an={index:!0,sequence:!0,seq:!0,sequential:!0,chron:!0,chronological:!0},on={sort:function(e){return"freq"===(e=e||"alpha")||"frequency"===e||"topk"===e?(r={},n={case:!0,punctuation:!1,whitespace:!0,unicode:!0},(t=this).list.forEach((function(e){var t=e.text(n);r[t]=r[t]||0,r[t]+=1})),t.list.sort((function(e,t){var a=r[e.text(n)],i=r[t.text(n)];return ai?-1:0})),t):an.hasOwnProperty(e)?function(e){var t={};return e.json({terms:{offset:!0}}).forEach((function(e){t[e.terms[0].id]=e.terms[0].offset.start})),e.list=e.list.sort((function(e,r){return t[e.start]>t[r.start]?1:t[e.start]0){a+=o;continue}}if(void 0===r[i]||!0!==r.hasOwnProperty(i))if(i===e[a].reduced||!0!==r.hasOwnProperty(e[a].reduced)){if(!0===$n.test(i)){var s=i.replace($n,"");!0===r.hasOwnProperty(s)&&e[a].tag(r[s],"noprefix-lexicon",t)}}else e[a].tag(r[e[a].reduced],"lexicon",t);else e[a].tag(r[i],"lexicon",t)}return e},jn=/[\'‘’‛‵′`´]$/,En=/^(m|k|cm|km|m)\/(s|h|hr)$/,Nn=[[/^[\w\.]+@[\w\.]+\.[a-z]{2,3}$/,"Email"],[/^#[a-z0-9_\u00C0-\u00FF]{2,}$/,"HashTag"],[/^@1?[0-9](am|pm)$/i,"Time"],[/^@1?[0-9]:[0-9]{2}(am|pm)?$/i,"Time"],[/^@\w{2,}$/,"AtMention"],[/^(https?:\/\/|www\.)\w+\.[a-z]{2,3}/,"Url"],[/^[\w./]+\.(com|net|gov|org|ly|edu|info|biz|ru|jp|de|in|uk|br)/,"Url"],[/^'[0-9]{2}$/,"Year"],[/^[012]?[0-9](:[0-5][0-9])(:[0-5][0-9])$/,"Time"],[/^[012]?[0-9](:[0-5][0-9])?(:[0-5][0-9])? ?(am|pm)$/i,"Time"],[/^[012]?[0-9](:[0-5][0-9])(:[0-5][0-9])? ?(am|pm)?$/i,"Time"],[/^[PMCE]ST$/,"Time"],[/^utc ?[+-]?[0-9]+?$/,"Time"],[/^[a-z0-9]*? o\'?clock$/,"Time"],[/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}/i,"Date"],[/^[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,4}$/,"Date"],[/^[0-9]{1,4}\/[0-9]{1,2}\/[0-9]{1,4}$/,"Date"],[/^[0-9]{1,4}-[a-z]{2,9}-[0-9]{1,4}$/i,"Date"],[/^gmt[+-][0-9][0-9]?$/i,"Timezone"],[/^utc[+-][0-9][0-9]?$/i,"Timezone"],[/^ma?c\'.*/,"LastName"],[/^o\'[drlkn].*/,"LastName"],[/^ma?cd[aeiou]/,"LastName"],[/^(lol)+[sz]$/,"Expression"],[/^woo+a*?h?$/,"Expression"],[/^(un|de|re)\\-[a-z\u00C0-\u00FF]{2}/,"Verb"],[/^[0-9]{1,4}\.[0-9]{1,2}\.[0-9]{1,4}$/,"Date"],[/^[0-9]{3}-[0-9]{4}$/,"PhoneNumber"],[/^(\+?[0-9][ -])?[0-9]{3}[ -]?[0-9]{3}-[0-9]{4}$/,"PhoneNumber"],[/^[-+]?[\$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6][-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?(k|m|b|bn)?\+?$/,["Money","Value"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?[\$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6]\+?$/,["Money","Value"]],[/^[-+]?[\$£]?[0-9]([0-9,.])+?(usd|eur|jpy|gbp|cad|aud|chf|cny|hkd|nzd|kr|rub)$/i,["Money","Value"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?\+?$/,["Cardinal","NumericValue"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?(st|nd|rd|r?th)$/,["Ordinal","NumericValue"]],[/^\.[0-9]+\+?$/,["Cardinal","NumericValue"]],[/^[-+]?[0-9]+(,[0-9]{3})*(\.[0-9]+)?%\+?$/,["Percent","Cardinal","NumericValue"]],[/^\.[0-9]+%$/,["Percent","Cardinal","NumericValue"]],[/^[0-9]{1,4}\/[0-9]{1,4}(st|nd|rd|th)?s?$/,["Fraction","NumericValue"]],[/^[0-9.]{1,2}[-–][0-9]{1,2}$/,["Value","NumberRange"]],[/^[0-9.]{1,3}(st|nd|rd|th)?[-–][0-9\.]{1,3}(st|nd|rd|th)?$/,"NumberRange"],[/^[0-9.]+([a-z]{1,4})$/,"Value"]],In=/^[IVXLCDM]{2,}$/,xn=/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,Cn="Adjective",Fn="Infinitive",Bn="PresentTense",On="Singular",Gn="PastTense",zn="Adverb",Tn="Expression",Vn="Actor",Jn="Verb",Mn="Noun",Ln="LastName",Sn={a:[[/.[aeiou]na$/,Mn],[/.[oau][wvl]ska$/,Ln],[/.[^aeiou]ica$/,On],[/^([hyj]a)+$/,Tn]],c:[[/.[^aeiou]ic$/,Cn]],d:[[/[aeiou](pp|ll|ss|ff|gg|tt|rr|bb|nn|mm)ed$/,Gn],[/.[aeo]{2}[bdgmnprvz]ed$/,Gn],[/.[aeiou][sg]hed$/,Gn],[/.[aeiou]red$/,Gn],[/.[aeiou]r?ried$/,Gn],[/.[bcdgtr]led$/,Gn],[/.[aoui]f?led$/,Gn],[/.[iao]sed$/,Gn],[/[aeiou]n?[cs]ed$/,Gn],[/[aeiou][rl]?[mnf]ed$/,Gn],[/[aeiou][ns]?c?ked$/,Gn],[/[aeiou][nl]?ged$/,Gn],[/.[tdbwxz]ed$/,Gn],[/[^aeiou][aeiou][tvx]ed$/,Gn],[/.[cdlmnprstv]ied$/,Gn],[/[^aeiou]ard$/,On],[/[aeiou][^aeiou]id$/,Cn],[/.[vrl]id$/,Cn]],e:[[/.[lnr]ize$/,Fn],[/.[^aeiou]ise$/,Fn],[/.[aeiou]te$/,Fn],[/.[^aeiou][ai]ble$/,Cn],[/.[^aeiou]eable$/,Cn],[/.[ts]ive$/,Cn]],h:[[/.[^aeiouf]ish$/,Cn],[/.v[iy]ch$/,Ln],[/^ug?h+$/,Tn],[/^uh[ -]?oh$/,Tn]],i:[[/.[oau][wvl]ski$/,Ln]],k:[[/^(k){2}$/,Tn]],l:[[/.[gl]ial$/,Cn],[/.[^aeiou]ful$/,Cn],[/.[nrtumcd]al$/,Cn],[/.[^aeiou][ei]al$/,Cn]],m:[[/.[^aeiou]ium$/,On],[/[^aeiou]ism$/,On],[/^h*u*m+$/,Tn],[/^\d+ ?[ap]m$/,"Date"]],n:[[/.[lsrnpb]ian$/,Cn],[/[^aeiou]ician$/,Vn],[/[aeiou][ktrp]in$/,"Gerund"]],o:[[/^no+$/,Tn],[/^(yo)+$/,Tn],[/^woo+[pt]?$/,Tn]],r:[[/.[bdfklmst]ler$/,"Noun"],[/[aeiou][pns]er$/,On],[/[^i]fer$/,Fn],[/.[^aeiou][ao]pher$/,Vn],[/.[lk]er$/,"Noun"],[/.ier$/,"Comparative"]],t:[[/.[di]est$/,"Superlative"],[/.[icldtgrv]ent$/,Cn],[/[aeiou].*ist$/,Cn],[/^[a-z]et$/,Jn]],s:[[/.[^aeiou]ises$/,Bn],[/.[rln]ates$/,Bn],[/.[^z]ens$/,Jn],[/.[lstrn]us$/,On],[/.[aeiou]sks$/,Bn],[/.[aeiou]kes$/,Bn],[/[aeiou][^aeiou]is$/,On],[/[a-z]\'s$/,Mn],[/^yes+$/,Tn]],v:[[/.[^aeiou][ai][kln]ov$/,Ln]],y:[[/.[cts]hy$/,Cn],[/.[st]ty$/,Cn],[/.[gk]y$/,Cn],[/.[tnl]ary$/,Cn],[/.[oe]ry$/,On],[/[rdntkbhs]ly$/,zn],[/...lly$/,zn],[/[bszmp]{2}y$/,Cn],[/.(gg|bb|zz)ly$/,Cn],[/.[ai]my$/,Cn],[/[ea]{2}zy$/,Cn],[/.[^aeiou]ity$/,On]]},_n="Adjective",Kn="Infinitive",qn="PresentTense",Rn="Singular",Wn="PastTense",Un="Adverb",Qn="Plural",Zn="Actor",Xn="Verb",Yn="Noun",ea="LastName",ta="Modal",ra=[null,null,{ea:Rn,ia:Yn,ic:_n,ly:Un,"'n":Xn,"'t":Xn},{oed:Wn,ued:Wn,xed:Wn," so":Un,"'ll":ta,"'re":"Copula",azy:_n,eer:Yn,end:Xn,ped:Wn,ffy:_n,ify:Kn,ing:"Gerund",ize:Kn,lar:_n,mum:_n,nes:qn,nny:_n,oid:_n,ous:_n,que:_n,rol:Rn,sis:Rn,zes:qn},{amed:Wn,aped:Wn,ched:Wn,lked:Wn,nded:Wn,cted:Wn,dged:Wn,akis:ea,cede:Kn,chuk:ea,czyk:ea,ects:qn,ends:Xn,enko:ea,ette:Rn,fies:qn,fore:Un,gate:Kn,gone:_n,ices:Qn,ints:Qn,ines:Qn,ions:Qn,less:Un,llen:_n,made:_n,nsen:ea,oses:qn,ould:ta,some:_n,sson:ea,tage:Kn,teen:"Value",tion:Rn,tive:_n,tors:Yn,vice:Rn},{tized:Wn,urned:Wn,eased:Wn,ances:Qn,bound:_n,ettes:Qn,fully:Un,ishes:qn,ities:Qn,marek:ea,nssen:ea,ology:Yn,ports:Qn,rough:_n,tches:qn,tieth:"Ordinal",tures:Qn,wards:Un,where:Un},{auskas:ea,keeper:Zn,logist:Zn,teenth:"Value"},{opoulos:ea,borough:"Place",sdottir:ea}],na={":(":!0,":)":!0,":P":!0,":p":!0,":O":!0,":3":!0,":|":!0,":/":!0,":\\":!0,":$":!0,":*":!0,":@":!0,":-(":!0,":-)":!0,":-P":!0,":-p":!0,":-O":!0,":-3":!0,":-|":!0,":-/":!0,":-\\":!0,":-$":!0,":-*":!0,":-@":!0,":^(":!0,":^)":!0,":^P":!0,":^p":!0,":^O":!0,":^3":!0,":^|":!0,":^/":!0,":^\\":!0,":^$":!0,":^*":!0,":^@":!0,"):":!0,"(:":!0,"$:":!0,"*:":!0,")-:":!0,"(-:":!0,"$-:":!0,"*-:":!0,")^:":!0,"(^:":!0,"$^:":!0,"*^:":!0,"<3":!0,"2){var a=n.clean[n.clean.length-2];if("s"===a)return void n.tag(["Possessive","Noun"],"end-tick",r);"n"===a&&n.tag(["Gerund"],"chillin",r)}En.test(n.text)&&n.tag("Unit","per-sec",r)},regex:function(e,t){for(var r=e.text,n=0;n=2&&In.test(r)&&xn.test(r)&&e.tag("RomanNumeral","xvii",t)},suffix:function(e,t){!function(e,t){var r=e.clean.length,n=7;r<=n&&(n=r-1);for(var a=n;a>1;a-=1){var i=e.clean.substr(r-a,r);if(!0===ra[i.length].hasOwnProperty(i)){var o=ra[i.length][i];e.tagSafe(o,"suffix -"+i,t);break}}}(e,t),function(e,t){var r=e.clean,n=r[r.length-1];if(!0===Sn.hasOwnProperty(n))for(var a=Sn[n],i=0;i35)}(n=(n=n.trim()).replace(/[.!?,]$/,""))&&(e.tag("Emoji","comma-emoji",t),e.text=n,e.pre=e.pre.replace(":",""),e.post=e.post.replace(":","")),e.text.match(aa)&&(e.tag("Emoji","unicode-emoji",t),e.text=n),!0===(r=(r=n).replace(/^[:;]/,":"),na.hasOwnProperty(r))&&(e.tag("Emoticon","emoticon-emoji",t),e.text=n)}},oa=function(e,t){var r=e.world;ia.lexicon(t,r);for(var n=0;n3&&void 0!==r[n]&&!0===r.hasOwnProperty(n)&&e.tag(r[n],"stem-"+n,t)}}))},va={isSingular:[/(ax|test)is$/i,/(octop|vir|radi|nucle|fung|cact|stimul)us$/i,/(octop|vir)i$/i,/(rl)f$/i,/(alias|status)$/i,/(bu)s$/i,/(al|ad|at|er|et|ed|ad)o$/i,/(ti)um$/i,/(ti)a$/i,/sis$/i,/(?:(^f)fe|(lr)f)$/i,/hive$/i,/s[aeiou]+ns$/i,/(^aeiouy|qu)y$/i,/(x|ch|ss|sh|z)$/i,/(matr|vert|ind|cort)(ix|ex)$/i,/(m|l)ouse$/i,/(m|l)ice$/i,/(antenn|formul|nebul|vertebr|vit)a$/i,/.sis$/i,/^(?!talis|.*hu)(.*)man$/i],isPlural:[/(^v)ies$/i,/ises$/i,/ives$/i,/(antenn|formul|nebul|vertebr|vit)ae$/i,/(octop|vir|radi|nucle|fung|cact|stimul)i$/i,/(buffal|tomat|tornad)oes$/i,/(analy|ba|diagno|parenthe|progno|synop|the)ses$/i,/(vert|ind|cort)ices$/i,/(matr|append)ices$/i,/(x|ch|ss|sh|s|z|o)es$/i,/is$/i,/men$/i,/news$/i,/.tia$/i,/(^f)ves$/i,/(lr)ves$/i,/(^aeiouy|qu)ies$/i,/(m|l)ice$/i,/(cris|ax|test)es$/i,/(alias|status)es$/i,/ics$/i]},ba=["Uncountable","Pronoun","Place","Value","Person","Month","WeekDay","Holiday"],ya=[/ss$/,/sis$/,/[^aeiou][uo]s$/,/'s$/],wa=[/i$/,/ae$/],ka=function(e,t){if(e.tags.Noun&&!e.tags.Acronym){var r=e.clean;if(e.tags.Singular||e.tags.Plural)return;if(r.length<=3)return void e.tag("Singular","short-singular",t);if(ba.find((function(t){return e.tags[t]})))return;if(va.isPlural.find((function(e){return e.test(r)})))return void e.tag("Plural","plural-rules",t);if(va.isSingular.find((function(e){return e.test(r)})))return void e.tag("Singular","singular-rules",t);if(!0===/s$/.test(r)){if(ya.find((function(e){return e.test(r)})))return;return void e.tag("Plural","plural-fallback",t)}if(wa.find((function(e){return e.test(r)})))return;e.tag("Singular","singular-fallback",t)}},Aa=["academy","administration","agence","agences","agencies","agency","airlines","airways","army","assoc","associates","association","assurance","authority","autorite","aviation","bank","banque","board","boys","brands","brewery","brotherhood","brothers","building society","bureau","cafe","caisse","capital","care","cathedral","center","central bank","centre","chemicals","choir","chronicle","church","circus","clinic","clinique","club","co","coalition","coffee","collective","college","commission","committee","communications","community","company","comprehensive","computers","confederation","conference","conseil","consulting","containers","corporation","corps","corp","council","crew","daily news","data","departement","department","department store","departments","design","development","directorate","division","drilling","education","eglise","electric","electricity","energy","ensemble","enterprise","enterprises","entertainment","estate","etat","evening news","faculty","federation","financial","fm","foundation","fund","gas","gazette","girls","government","group","guild","health authority","herald","holdings","hospital","hotel","hotels","inc","industries","institut","institute","institute of technology","institutes","insurance","international","interstate","investment","investments","investors","journal","laboratory","labs","liberation army","limited","local authority","local health authority","machines","magazine","management","marine","marketing","markets","media","memorial","mercantile exchange","ministere","ministry","military","mobile","motor","motors","musee","museum","news","news service","observatory","office","oil","optical","orchestra","organization","partners","partnership","people's party","petrol","petroleum","pharmacare","pharmaceutical","pharmaceuticals","pizza","plc","police","polytechnic","post","power","press","productions","quartet","radio","regional authority","regional health authority","reserve","resources","restaurant","restaurants","savings","school","securities","service","services","social club","societe","society","sons","standard","state police","state university","stock exchange","subcommittee","syndicat","systems","telecommunications","telegraph","television","times","tribunal","tv","union","university","utilities","workers"].reduce((function(e,t){return e[t]="Noun",e}),{}),Da=function(e){return!!e.tags.Noun&&(!(e.tags.Pronoun||e.tags.Comma||e.tags.Possessive)&&!!(e.tags.Organization||e.tags.Acronym||e.tags.Place||e.titleCase()))},$a=/^[A-Z]('s|,)?$/,Pa=/([A-Z]\.){2}[A-Z]?/i,Ha={I:!0,A:!0},ja={neighbours:ca,case:ga,stem:fa,plural:ka,organizations:function(e,t){for(var r=0;r5)&&e.isAcronym()}(e,t)?(e.tag("Acronym","acronym-step",t),e.tag("Noun","acronym-infer",t)):!Ha.hasOwnProperty(e.text)&&$a.test(e.text)&&(e.tag("Acronym","one-letter-acronym",t),e.tag("Noun","one-letter-infer",t)),e.tags.Organization&&e.text.length<=3&&e.tag("Acronym","acronym-org",t),e.tags.Organization&&e.isUpperCase()&&e.text.length<=6&&e.tag("Acronym","acronym-org-case",t))}))}},Ea=function(e,t){var r=e.world;return ja.neighbours(t,r),ja.case(e),ja.stem(t,r),t.forEach((function(t){!1===t.isKnown()&&t.tag("Noun","noun-fallback",e.world)})),ja.organizations(t,r),ja.acronyms(t,r),t.forEach((function(t){ja.plural(t,e.world)})),e},Na=/n't$/,Ia={"won't":["will","not"],wont:["will","not"],"can't":["can","not"],cant:["can","not"],cannot:["can","not"],"shan't":["should","not"],dont:["do","not"],dun:["do","not"]},xa=function(e,t){return!0===Ia.hasOwnProperty(e.clean)?Ia[e.clean]:"ain't"===e.clean||"aint"===e.clean?function(e,t){var r=t.terms(),n=r.indexOf(e),a=r.slice(0,n).find((function(e){return e.tags.Noun}));return a&&a.tags.Plural?["are","not"]:["is","not"]}(e,t):!0===Na.test(e.clean)?[e.clean.replace(Na,""),"not"]:null},Ca=/([a-z\u00C0-\u00FF]+)[\u0027\u0060\u00B4\u2018\u2019\u201A\u201B\u2032\u2035\u2039\u203A]([a-z]{1,2})$/i,Fa={ll:"will",ve:"have",re:"are",m:"am","n't":"not"},Ba=function(e){var t=e.text.match(Ca);return null===t?null:Fa.hasOwnProperty(t[2])?[t[1],Fa[t[2]]]:null},Oa={wanna:["want","to"],gonna:["going","to"],im:["i","am"],alot:["a","lot"],ive:["i","have"],imma:["I","will"],"where'd":["where","did"],whered:["where","did"],"when'd":["when","did"],whend:["when","did"],howd:["how","did"],whatd:["what","did"],dunno:["do","not","know"],brb:["be","right","back"],gtg:["got","to","go"],irl:["in","real","life"],tbh:["to","be","honest"],imo:["in","my","opinion"],til:["today","i","learned"],rn:["right","now"],twas:["it","was"],"@":["at"]},Ga=function(e){return Oa.hasOwnProperty(e.clean)?Oa[e.clean]:null},za=/([a-z\u00C0-\u00FF]+)[\u0027\u0060\u00B4\u2018\u2019\u201A\u201B\u2032\u2035\u2039\u203A]s$/i,Ta={that:!0,there:!0},Va={here:!0,there:!0,everywhere:!0},Ja=function(e,t,r){var n=e.text.match(za);if(null!==n){if(!0===function(e,t){if(e.tags.Possessive)return!0;if(e.tags.Pronoun||e.tags.QuestionWord)return!1;if(Ta.hasOwnProperty(e.reduced))return!1;var r=t.get(e.next);if(!r)return!0;if(r.tags.Verb)return!!r.tags.Infinitive||!!r.tags.PresentTense;if(r.tags.Noun)return!0!==Va.hasOwnProperty(r.reduced);var n=t.get(r.next);return!(!n||!n.tags.Noun||n.tags.Pronoun)||(r.tags.Adjective||r.tags.Adverb||r.tags.Verb,!1)}(e,t.pool))return e.tag("#Possessive","isPossessive",r),null;if(null!==n)return function(e,t){var r=t.terms(),n=r.indexOf(e);return r.slice(n+1,n+3).find((function(e){return e.tags.PastTense}))}(e,t)?[n[1],"has"]:[n[1],"is"]}return null},Ma=/[a-z\u00C0-\u00FF]'d$/,La={how:!0,what:!0},Sa=function(e,t){if(Ma.test(e.clean)){for(var r=e.clean.replace(/'d$/,""),n=t.terms(),a=n.indexOf(e),i=n.slice(a+1,a+4),o=0;o0?bi=bi.concat(t):bi.push(e)})),bi.forEach((function(e){var t,r,n;return e.required=(t=e.reg,r=[],n=[],t.forEach((function(e){!0!==e.optional&&!0!==e.negative&&(void 0!==e.tag&&r.push(e.tag),void 0!==e.word&&n.push(e.word))})),{tags:ti(r),words:ti(n)}),e}));var yi=bi,wi=function(e){yi.forEach((function(t){var r=[];t.required.words.forEach((function(t){r.push(e._cache.words[t]||[])})),t.required.tags.forEach((function(t){r.push(e._cache.tags[t]||[])}));var n=function(e){if(0===e.length)return[];var t={};e.forEach((function(e){e=ti(e);for(var r=0;r5&&e.match("#Verb+").length>=2}));if(u.found){var l=u.splitAfter("#Noun .* #Verb .* #Noun+");n=n.splitOn(l.eq(0))}return"number"==typeof t&&(n=n.get(t)),new e(n.list,this,this.world)},e},ji=function(e){var r=function(e){a(i,e);var r=u(i);function i(e,n,a){var o;return t(this,i),(o=r.call(this,e,n,a)).contracted=null,o}return n(i,[{key:"expand",value:function(){return this.list.forEach((function(e){var t=e.terms(),r=t[0].isTitleCase();t.forEach((function(e,r){e.set(e.implicit||e.text),e.implicit=void 0,r1&&void 0!==arguments[1]?arguments[1]:{},n=this.match("(#City && @hasComma) (#Region|#Country)"),a=this.not(n).splitAfter("@hasComma"),i=(a=a.concat(n)).quotations();return i.found&&(a=a.splitOn(i.eq(0))),a=a.match("#Noun+ (of|by)? the? #Noun+?"),!0!==t.keep_anaphora&&(a=(a=(a=(a=a.not("#Pronoun")).not("(there|these)")).not("(#Month|#WeekDay)")).not("(my|our|your|their|her|his)")),a=a.not("(of|for|by|the)$"),"number"==typeof e&&(a=a.get(e)),new r(a.list,this,this.world)},e},Li=/\(/,Si=/\)/,_i=function(e){var r=function(e){a(i,e);var r=u(i);function i(){return t(this,i),r.apply(this,arguments)}return n(i,[{key:"unwrap",value:function(){return this.list.forEach((function(e){var t=e.terms(0);t.pre=t.pre.replace(Li,"");var r=e.lastTerm();r.post=r.post.replace(Si,"")})),this}}]),i}(e);return e.prototype.parentheses=function(e){var t=[];return this.list.forEach((function(e){for(var r=e.terms(),n=0;n0}}),Object.defineProperty(this,"length",{get:function(){return i.list.length}}),Object.defineProperty(this,"isA",{get:function(){return"Doc"}})}return n(e,[{key:"tagger",value:function(){return Ai(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),e}();lo.prototype.buildFrom=function(e){return e=e.map((function(e){return e.clone(!0)})),new lo(e,this,this.world)},lo.prototype.fromText=function(e){var t=Dt(e,this.world,this.pool());return this.buildFrom(t)},Object.assign(lo.prototype,uo.misc),Object.assign(lo.prototype,uo.selections),so(lo);var co={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(co).forEach((function(e){return lo.prototype[e]=lo.prototype[co[e]]}));var ho=lo,go=function(e){var t=e.termList();return Hn(t,e.world),e.world.taggers.forEach((function(t){t(e)})),e};return function e(t){var r=t,n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0;t&&r.addWords(t);var n=Dt(e,r),a=new ho(n,null,r);return a.tagger(),a};return n.tokenize=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1?arguments[1]:void 0,n=r;t&&((n=n.clone()).words={},n.addWords(t));var a=Dt(e,n),i=new ho(a,null,n);return(t||i.world.taggers.length>0)&&go(i),i},n.extend=function(e){return e(ho,r,this,tt,se,nt),this},n.fromJSON=function(e){var t=$t(e,r);return new ho(t,null,r)},n.clone=function(){return e(r.clone())},n.verbose=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return r.verbose(e),this},n.world=function(){return r},n.parseMatch=function(e,t){return We(e,t)},n.version="13.10.4",n.import=n.load,n.plugin=n.extend,n}(new Or)})); diff --git a/builds/compromise.mjs b/builds/compromise.mjs index 0672bbb33..b4da6a35c 100644 --- a/builds/compromise.mjs +++ b/builds/compromise.mjs @@ -1,4 +1,4 @@ -/* compromise 13.10.3 MIT */ +/* compromise 13.10.4 MIT */ function _typeof(obj) { "@babel/helpers - typeof"; @@ -2591,9 +2591,9 @@ var _04PostProcess = postProcess$1; // prefixes: ! [ ^ // [\!\[\^]* // match 'foo /yes/' and not 'foo/no/bar' -var bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/g; // match '(yes) but not foo(no)bar' +var bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/; // match '(yes) but not foo(no)bar' -var byParentheses = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g; // okay +var byParentheses = /([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/; // okay var byWord = / /g; @@ -2621,6 +2621,11 @@ var parseBlocks = function parseBlocks(txt) { var res = []; // parse by (blocks), next arr.forEach(function (str) { + if (isReg(str)) { + res.push(str); + return; + } + res = res.concat(str.split(byParentheses)); }); res = cleanUp(res); // split by spaces, now @@ -2639,7 +2644,7 @@ var parseBlocks = function parseBlocks(txt) { return _final; }; -var _01ParseBlocks = parseBlocks; // console.log(parseBlocks(`[#Value] [(mark|rand|won|rub|ore)] foo`)) +var _01ParseBlocks = parseBlocks; // console.log('(one two) (upto) [#Date+]'.split(byParentheses)) /* break-down a match expression into this: { @@ -3855,7 +3860,7 @@ var fromJSON = function fromJSON(json, world) { var fromJSON_1 = fromJSON; -var _version = '13.10.3'; +var _version = '13.10.4'; var entity = ['Person', 'Place', 'Organization']; var nouns$1 = { diff --git a/changelog.md b/changelog.md index 7568a5405..0789cb0d5 100644 --- a/changelog.md +++ b/changelog.md @@ -10,7 +10,10 @@ While all _Major_ releases should be reviewed, our only two _large_ releases are - +#### 13.10.4 [March 2021] +- **[fix]** - match syntax tokenization fix +- **[change]** - improved performance monitoring + #### 13.10.3 [March 2021] - **[fix]** - support complicated regular-expressions in match syntax - improved performance testing diff --git a/package.json b/package.json index 9842dd92c..c0683707e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Spencer Kelly (http://spencermounta.in)", "name": "compromise", "description": "modest natural language processing", - "version": "13.10.3", + "version": "13.10.4", "main": "./builds/compromise.js", "unpkg": "./builds/compromise.min.js", "module": "./builds/compromise.mjs", @@ -40,8 +40,10 @@ "coverage:html": "nyc --reporter=html tape \"./tests/**/*.test.js\" | tap-dancer --color always", "coverage": "nyc -r lcov -n 'src/**/*' -n 'plugins/**/*' npm run test", "codecov": "npm run coverage && codecov -t 15039ad1-b495-48cd-b4a0-bcf124c9b318", - "perf": "node ./scripts/test/perf/index.js", - "perf:build": "node ./scripts/test/perf/build-speed.js", + "perf": "node ./scripts/perf/index.js", + "perf:build": "TESTENV=prod node ./scripts/perf/index.js", + "perf:versions": "node ./scripts/perf/versions.js", + "flame": "clinic flame -- node ./scripts/perf/flame", "lint": "eslint ./src/ && eslint ./plugins/**/src/", "watch": "amble ./scratch.js", "build:all": "node ./scripts/build/build-all.js && npm run build --silent", diff --git a/scratch.js b/scratch.js index 8547cf4f3..e29afdba2 100644 --- a/scratch.js +++ b/scratch.js @@ -1,22 +1,29 @@ const nlp = require('./src/index') -nlp.extend(require('./plugins/numbers/src')) -// nlp.extend(require('./plugins/typeahead/src')) +// nlp.extend(require('./plugins/numbers/src')) // nlp.extend(require('./plugins/dates/src')) -// nlp.extend(require('./plugins/sentences/src')) -// nlp.verbose(true) -// nlp.typeahead({ march: 'Date' }, { min: 1, safe: false }) -// let str = -// '/^(?=d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]d)?dd(?:(?=\x20d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]d){0,2}(\x20[AP]M))|([01]d|2[0-3])(:[0-5]d){1,2})?$/' -// let r = new RegExp(str) -// // console.log(r) -// let res = nlp.parseMatch(`start (one|two|three four)? end`) -// console.log(res) +nlp.extend(require('./plugins/match-runner/src')) +const text = require('/Users/spencer/mountain/compromise/scripts/perf/flame/_sotu-text.js') -// let doc = nlp.tokenize('16 marc') -// doc.match() +// let list = [ +// // ==== Holiday ==== +// { match: '#Holiday (day|eve)', tag: 'Holiday', reason: 'holiday-day' }, // the captain who -// const doc = nlp('i was walking') -// const m = doc.normalize({ -// verbs: true, -// }) -// m.debug() +// // ==== WeekDay ==== +// // sun the 5th +// { match: '[sun] the #Ordinal', tag: 'WeekDay', reason: 'sun-the-5th' }, +// //sun feb 2 +// { match: '[sun] #Date', group: 0, tag: 'WeekDay', reason: 'sun-feb' }, +// ] + +// let doc = nlp('no one tunes into their 2nd favourite no-radio station. no lyin!') +// doc.matchRunner(list) +// doc.debug() +// nlp(text) + +// const reg = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g + +// let str = '(one two) (upto) snooz(et)oDate' +// console.log(str.split(/(\(.*?\))/)) +// console.log(str.split(/(?:^|\s)([\!\[\^]*\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/)) +// console.log(str.split(/(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/)) +// console.log(nlp.parseMatch('(snooze|wait|delay|punt|later|sleep) (up to) [#Date+]')) diff --git a/scripts/test/perf/_fetch.js b/scripts/perf/_fetch.js similarity index 99% rename from scripts/test/perf/_fetch.js rename to scripts/perf/_fetch.js index 814de6315..19e5bd472 100644 --- a/scripts/test/perf/_fetch.js +++ b/scripts/perf/_fetch.js @@ -18,4 +18,5 @@ const fetch = function (url) { }) }) } + module.exports = fetch diff --git a/scripts/test/perf/_sotu-text.js b/scripts/perf/flame/_sotu-text.js similarity index 100% rename from scripts/test/perf/_sotu-text.js rename to scripts/perf/flame/_sotu-text.js diff --git a/scripts/perf/flame/index.js b/scripts/perf/flame/index.js new file mode 100644 index 000000000..ef7f710bb --- /dev/null +++ b/scripts/perf/flame/index.js @@ -0,0 +1,16 @@ +const txt = require('./_sotu-text') +const path = '../../../src' + +console.log('\n-- testing: --') +console.time('load') +const nlp = require(path) +console.timeEnd('load') + +console.time('parse') +let doc = nlp(txt) +console.timeEnd('parse') + +console.time('match') +doc.match('#Noun') +console.timeEnd('match') +console.log('\n v' + nlp.version, '\n') diff --git a/scripts/perf/index.js b/scripts/perf/index.js new file mode 100644 index 000000000..79a06a5d2 --- /dev/null +++ b/scripts/perf/index.js @@ -0,0 +1,49 @@ +const Pool = require('./pool/pool') +const fetch = require('./_fetch') + +const BASELINE = 92 //node 12 + +if (!process.version.match(/^v12\./)) { + console.warn('Warn: Expecting node v12.x - got ' + process.version) +} + +let docs = [ + 'nlp-corpus-1.json', + 'nlp-corpus-2.json', + 'nlp-corpus-3.json', + 'nlp-corpus-4.json', + 'nlp-corpus-5.json', + 'nlp-corpus-6.json', + 'nlp-corpus-7.json', + 'nlp-corpus-8.json', + 'nlp-corpus-9.json', + 'nlp-corpus-10.json', +] + +const fetchAll = function (urls) { + return Promise.all(urls.map(u => fetch(u))).then(res => res.map(texts => texts.join('\n'))) +} + +const diff = function (time) { + let delta = time - BASELINE + let percent = (delta / time) * 100 + percent = Math.round(percent * 10) / 10 + return percent +} + +;(async () => { + let p = new Pool() + let texts = await fetchAll(docs.map(file => `https://unpkg.com/nlp-corpus@3.3.0/builds/${file}`)) + console.log(`\n\n running ${texts.length} texts on ${p.count()} workers`) + let nums = [] + for (let i = 0; i < texts.length; i += 1) { + console.log(` text #${i + 1} - 🕰`) + let num = await p.do(texts[i]) + nums.push(num) + } + let sum = nums.reduce((h, n) => h + n, 0) + sum = Math.round(sum * 10) / 10 + console.log('\n\n', sum, ' total') + console.log(' +/- ', diff(sum), '% ') + p.close() +})() diff --git a/scripts/test/perf/package-lock.json b/scripts/perf/package-lock.json similarity index 100% rename from scripts/test/perf/package-lock.json rename to scripts/perf/package-lock.json diff --git a/scripts/test/perf/package.json b/scripts/perf/package.json similarity index 100% rename from scripts/test/perf/package.json rename to scripts/perf/package.json diff --git a/scripts/perf/pool/_lib.js b/scripts/perf/pool/_lib.js new file mode 100644 index 000000000..96274b0cc --- /dev/null +++ b/scripts/perf/pool/_lib.js @@ -0,0 +1,12 @@ +if (typeof process !== undefined && typeof module !== undefined) { + let nlp + if (process.env.TESTENV === 'prod') { + console.warn('== production build test 🚀 ==') + nlp = require('../../../builds/compromise.min.js') + } else { + nlp = require('../../../src') + // nlp.extend(require('../plugins/numbers/src')) + } + + module.exports = nlp +} diff --git a/scripts/perf/pool/pool.js b/scripts/perf/pool/pool.js new file mode 100644 index 000000000..4fa868b61 --- /dev/null +++ b/scripts/perf/pool/pool.js @@ -0,0 +1,39 @@ +const { Worker } = require('worker_threads') +const os = require('os') +const cpus = os.cpus().length + +class Pool { + constructor() { + this.workers = [] + for (let i = 0; i < cpus; i += 1) { + this.workers.push(new Worker(__dirname + '/worker.js')) + } + } + do(msg) { + let ps = this.workers.map(w => { + return new Promise(resolve => { + w.on('message', res => { + w.removeAllListeners('message') + resolve(res) + }) + w.postMessage(msg) + }) + }) + return Promise.all(ps).then(nums => { + // console.log(nums) + let avg = nums.reduce((h, n) => h + n, 0) / nums.length + avg = Math.round(avg * 10) / 10 + return avg + }) + } + count() { + return this.workers.length + } + close() { + this.workers.forEach(w => w.terminate()) + } +} +module.exports = Pool + +// let p = new Pool() +// p.do("hey now, you're a rockstar").then(() => p.close()) diff --git a/scripts/perf/pool/worker.js b/scripts/perf/pool/worker.js new file mode 100644 index 000000000..4ca49e883 --- /dev/null +++ b/scripts/perf/pool/worker.js @@ -0,0 +1,40 @@ +const { parentPort } = require('worker_threads') +// const nlp = require('../../src') +let nlp = require('./_lib') + +let matches = [ + 'out of range', + '#Person #Person', + '. of the world', + '#Noun+ house', + 'range #Noun+', + 'doubt . of #Verb', + '(watch|house|#Verb) .', + '(watch|house|#Verb)?', + '(watch a film|eat a cake)+', + '(#Noun of #Noun)+', + '. @hasQuestionMark', + 'the .+', + 'keep a #Noun', +] + +const doit = async function (txt) { + let doc = nlp(txt) + matches.forEach(reg => { + doc.match(reg).text() + }) + doc.json() +} + +parentPort.on('message', async msg => { + let begin = new Date() + doit(msg) + let end = new Date() + let delta = (end.getTime() - begin.getTime()) / 1000 + parentPort.postMessage(delta) +}) + +// new Promise(async resolve => { +// parentPort.postMessage(r) +// resolve(r) +// }) diff --git a/scripts/test/perf/versions.js b/scripts/perf/versions.js similarity index 97% rename from scripts/test/perf/versions.js rename to scripts/perf/versions.js index fba545256..d18107231 100644 --- a/scripts/test/perf/versions.js +++ b/scripts/perf/versions.js @@ -40,7 +40,7 @@ let matches = [ let nlps = versions.map(version => { return require('compromise' + version) }) -nlps.push(require('../../..')) +nlps.push(require('../../types')) const testOne = function (nlp, texts) { let begin = new Date() diff --git a/scripts/test/perf/build-speed.js b/scripts/test/perf/build-speed.js deleted file mode 100644 index d75b58fb8..000000000 --- a/scripts/test/perf/build-speed.js +++ /dev/null @@ -1,24 +0,0 @@ -const txt = require('./_sotu-text') -const version = require('../../../package.json').version - -const paths = {} -paths[version] = '../../../src' -// v12build: '../../../builds/compromise.min.js', - -function test(build) { - console.log('\n-- testing: ' + build + ' --') - console.time('load') - const nlp = require(paths[build]) - console.timeEnd('load') - - console.time('parse') - let doc = nlp(txt) - console.timeEnd('parse') - - console.time('match') - doc.match('#Noun') - console.timeEnd('match') - console.log('\n') -} - -Object.keys(paths).forEach(test) diff --git a/scripts/test/perf/index.js b/scripts/test/perf/index.js deleted file mode 100644 index 52fa1d39d..000000000 --- a/scripts/test/perf/index.js +++ /dev/null @@ -1,115 +0,0 @@ -// https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color -const reset = '\x1b[0m' -const fetch = require('./_fetch') -let nlp = require('../../../tests/_lib') -// nlp.extend(require('../../../plugins/numbers/src')) -// nlp.extend(require('../../../plugins/dates/src')) -const highlight = 5 -const shouldFail = -10 -// const fs = require('fs') - -//cheaper than requiring chalk -const cli = { - green: function (str) { - return '\x1b[32m' + str + reset - }, - red: function (str) { - return '\x1b[31m' + str + reset - }, - grey: function (str) { - return '\x1b[90m' + str + reset - }, -} - -if (!process.version.match(/^v12\./)) { - console.warn(cli.red('Warn: Expecting node v12.x - got ' + process.version)) -} - -let matches = [ - 'out of range', - '#Person #Person', - '. of the world', - '#Noun+ house', - 'range #Noun+', - 'doubt . of #Verb', - '(watch|house|#Verb) .', - '(watch|house|#Verb)?', - '(watch a film|eat a cake)+', - '(#Noun of #Noun)+', - '. @hasQuestionMark', - 'the .+', - 'keep a #Noun', -] - -let documents = [ - ['nlp-corpus-1.json', 5.2], - ['nlp-corpus-2.json', 5.5], - ['nlp-corpus-3.json', 4.6], - ['nlp-corpus-4.json', 4.6], - ['nlp-corpus-5.json', 4.5], - ['nlp-corpus-6.json', 4.7], - ['nlp-corpus-7.json', 4.3], - ['nlp-corpus-8.json', 4.5], - ['nlp-corpus-9.json', 4.1], - ['nlp-corpus-10.json', 4.3], -] -const round = n => Math.round(n * 100) / 100 - -const nice = function (n) { - if (n > highlight) { - n = cli.red('+' + Math.abs(n) + '%') - } else if (n < -highlight) { - n = cli.green('' + n + '%') - } else { - if (n > 0) { - n = '+' + n - } - n = cli.grey(' ' + n + '%') - } - return n -} - -console.log('\n\nrunning speed-test:\n') -;(async () => { - let sum = 0 - // do each document - for (let n = 0; n < documents.length; n += 1) { - let a = documents[n] - let texts = await fetch(`https://unpkg.com/nlp-corpus@3.3.0/builds/${a[0]}`) - const _nlp = nlp.clone() - //start testing the speed - let begin = new Date() - texts.forEach(txt => { - let doc = _nlp(txt) - matches.forEach(reg => { - doc.match(reg).text() - }) - // let m = doc - // .filter(s => { - // return s.dates().found - // }) - // .json() - // let rows = m.map(obj => obj.text).join('\n') - // fs.writeFileSync('./dates.txt', rows, { flag: 'a' }) - }) - texts.forEach(txt => { - let doc = _nlp(txt) - doc.json() - }) - let end = new Date() - // calculate diff - let time = (end.getTime() - begin.getTime()) / 1000 - // console.log('\n ' + n + 'ms ' + time, a[1]) - let diff = round(time - a[1]) - let percent = round((diff / time) * 100, 10) - sum += percent - console.log(`${a[0]}: ${nice(percent)}`) - } - let avg = round(sum / documents.length) - console.log(`\n ${nice(avg)} avg difference\n`) - - // if it's a bad difference, fail - if (avg < shouldFail) { - process.exit(1) - } -})() diff --git a/src/World/match-syntax/01-parseBlocks.js b/src/World/match-syntax/01-parseBlocks.js index 06b5e7486..3e5045311 100644 --- a/src/World/match-syntax/01-parseBlocks.js +++ b/src/World/match-syntax/01-parseBlocks.js @@ -7,9 +7,9 @@ // [\!\[\^]* // match 'foo /yes/' and not 'foo/no/bar' -const bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/g +const bySlashes = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\/.*?[^\\\/]\/[\?\]\+\*\$~]*)(?:\s|$)/ // match '(yes) but not foo(no)bar' -const byParentheses = /(?:^|\s)([\!\[\^]*(?:<[^<]*>)?\(.*?[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/g +const byParentheses = /([\!\[\^]*(?:<[^<]*>)?\([^\)]+[^\\\)]\)[\?\]\+\*\$~]*)(?:\s|$)/ // okay const byWord = / /g @@ -32,6 +32,10 @@ const parseBlocks = function (txt) { let res = [] // parse by (blocks), next arr.forEach(str => { + if (isReg(str)) { + res.push(str) + return + } res = res.concat(str.split(byParentheses)) }) res = cleanUp(res) @@ -51,4 +55,6 @@ const parseBlocks = function (txt) { } module.exports = parseBlocks -// console.log(parseBlocks(`[#Value] [(mark|rand|won|rub|ore)] foo`)) +// console.log('(one two) (upto) [#Date+]'.split(byParentheses)) +// console.log(parseBlocks('(one|two) (in side) [foo]')) +// console.log(parseBlocks('(one|two) (in side) fl(atul)')) diff --git a/src/_version.js b/src/_version.js index d844f4684..49365cf09 100644 --- a/src/_version.js +++ b/src/_version.js @@ -1 +1 @@ -module.exports = '13.10.3' \ No newline at end of file +module.exports = '13.10.4' \ No newline at end of file diff --git a/tests/match/syntax.test.js b/tests/match/syntax.test.js index 8c320cd57..39b729d07 100644 --- a/tests/match/syntax.test.js +++ b/tests/match/syntax.test.js @@ -67,6 +67,10 @@ test('regex tokenization', function (t) { ['before [< word >/one two/] after', 3], ['[#Copula (#Adverb|not)+?] (#Gerund|#PastTense)', 3], ['[#Value] [(mark|rand|won|rub|ore)] foo', 3], + ['(snooze|wait|delay|punt|later|sleep) (up to) [#Date+]', 3], + ['(snooze sleep) (up to) [#Date+]?', 3], + ['(snooze sleep) (up|to) [#Date+]? (fourth)?', 4], + // ['/snooze sleep/ /up to/ [#Date+]?', 3], //known issue ] arr.forEach(a => { let regs = nlp.parseMatch(a[0])