diff --git a/builds/compromise-tokenize.js b/builds/compromise-tokenize.js index 636a51cd7..e691720d0 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!==_[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,$,D,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*?(\S+)\s*?>/),It=function(t){return t[t.length-1]},St=function(t){return t[0]},zt=function(t){return t.substr(1)},_t=function(t){return t.substr(0,t.length-1)},Dt=function(t){return t=zt(t),t=_t(t)},Mt=function t(e){for(var r,n={},i=0;i<2;i+=1){if("$"===It(e)&&(n.end=!0,e=_t(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=_t(e)),"*"!==e&&"*"===It(e)&&"\\*"!==e&&(n.greedy=!0,e=_t(e)),"?"===It(e)&&(n.optional=!0,e=_t(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]=_t(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=Dt(e),n.regex=new RegExp(e),n;if("~"===St(e)&&"~"===It(e))return e=Dt(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\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({},De);return Object.keys(De).forEach((function(r){var n=De[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===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},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.5",n.import=n.load,n.plugin=n.extend,n}(new Ye)})); +!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!==_[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,$,D,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*?(\S+)\s*?>/),It=function(t){return t[t.length-1]},St=function(t){return t[0]},zt=function(t){return t.substr(1)},_t=function(t){return t.substr(0,t.length-1)},Dt=function(t){return t=zt(t),t=_t(t)},Mt=function t(e){for(var r,n={},i=0;i<2;i+=1){if("$"===It(e)&&(n.end=!0,e=_t(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=_t(e)),"*"!==e&&"*"===It(e)&&"\\*"!==e&&(n.greedy=!0,e=_t(e)),"?"===It(e)&&(n.optional=!0,e=_t(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]=_t(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=Dt(e),n.regex=new RegExp(e),n;if("~"===St(e)&&"~"===It(e))return e=Dt(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\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({},De);return Object.keys(De).forEach((function(r){var n=De[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===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},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.6",n.import=n.load,n.plugin=n.extend,n}(new Ye)})); diff --git a/builds/compromise.js b/builds/compromise.js index 663f6b220..a2dbb4bdc 100644 --- a/builds/compromise.js +++ b/builds/compromise.js @@ -1,4 +1,4 @@ -/* compromise 13.10.5 MIT */ +/* compromise 13.10.6 MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : @@ -3866,7 +3866,7 @@ var fromJSON_1 = fromJSON; - var _version = '13.10.5'; + var _version = '13.10.6'; var entity = ['Person', 'Place', 'Organization']; var nouns$1 = { @@ -10727,14 +10727,28 @@ var isNumber = /^[0-9]+$/; var isOrdinal = /^[0-9]+(st|nd|rd|th)$/; - var isTime = /^[0-9:]+(am|pm)$/; + var isTime = /^[0-9:]+(am|pm)?$/; var createPhrase = function createPhrase(found, doc) { //create phrase from ['would', 'not'] var phrase = _01Tokenizer(found.join(' '), doc.world, doc.pool())[0]; //tag it var terms = phrase.terms(); - _01Lexicon(terms, doc.world); //make these terms implicit + _01Lexicon(terms, doc.world); + var term = terms[0]; // tag number-ranges + + if (isOrdinal.test(term.text)) { + terms[0].tag('Ordinal', 'ord-range', doc.world); + terms[2].tag('Ordinal', 'ord-range', doc.world); + } else if (isNumber.test(term.text)) { + terms[0].tag('Cardinal', 'num-range', doc.world); + terms[2].tag('Cardinal', 'num-range', doc.world); + } else if (isTime.test(term.text)) { + terms[0].tag('Time', 'time-range', doc.world); + terms[1].tag('Date', 'time-range', doc.world); + terms[2].tag('Time', 'time-range', doc.world); + } //make these terms implicit + terms.forEach(function (t) { t.implicit = t.text; @@ -10742,15 +10756,9 @@ t.clean = ''; // remove whitespace for implicit terms t.pre = ''; - t.post = ''; // tag number-ranges - - if (isNumber.test(t.implicit)) { - t.tag('Cardinal', 'num-range', doc.world); - } else if (isOrdinal.test(t.implicit)) { - t.tag('Ordinal', 'ord-range', doc.world); - } else if (isTime.test(t.implicit)) { - t.tag('Time', 'time-range', doc.world); - } else if (Object.keys(t.tags).length === 0) { + t.post = ''; + + if (Object.keys(t.tags).length === 0) { t.tags.Noun = true; // if no tag, give it a noun } }); @@ -13864,9 +13872,7 @@ // walked => walk - turn a verb into it's root form var toInfinitive = function toInfinitive(parsed, world) { - var verb = parsed.verb; // console.log(parsed) - // verb.debug() - //1. if it's already infinitive + var verb = parsed.verb; //1. if it's already infinitive var str = verb.text('reduced'); diff --git a/builds/compromise.min.js b/builds/compromise.min.js index 3f1711dec..403f5e671 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)})))},G=O=function(e,t,r,n){var a=z(e,t,r,n);return!0===t.negative?!a:a},T={},V={doesMatch:function(e,t,r){return G(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*?(\S+)\s*?>/),Oe=function(e){return e[e.length-1]},ze=function(e){return e[0]},Ge=function(e){return e.substr(1)},Te=function(e){return e.substr(0,e.length-1)},Ve=function(e){return e=Ge(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)),"^"===ze(t)&&(n.start=!0,t=Ge(t)),("["===ze(t)||"]"===Oe(t))&&(n.named=!0,"["===ze(t)?n.groupType="]"===Oe(t)?"single":"start":n.groupType="end",t=(t=t.replace(/^\[/,"")).replace(/\]$/,""),"<"===ze(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)),"!"===ze(t)&&(n.negative=!0,t=Ge(t)),"("===ze(t)&&")"===Oe(t)){Fe.test(t)?(n.choices=t.split(Fe),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]=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("/"===ze(t)&&"/"===Oe(t))return t=Ve(t),n.regex=new RegExp(t),n;if("~"===ze(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,""}))),"#"===ze(t)?(n.tag=Ge(t),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===ze(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)},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\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,3}[a-z]{0,2}[-–—][0-9]{1,3}[a-z]{0,2}$/,["Value","NumberRange"]],[/^[0-9][0-9]?(:[0-9][0-9])?(am|pm)?[-–—][0-9][0-9]?(:[0-9][0-9])?(am|pm)?$/,["Time","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",zn="PastTense",Gn="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$/,zn],[/.[aeo]{2}[bdgmnprvz]ed$/,zn],[/.[aeiou][sg]hed$/,zn],[/.[aeiou]red$/,zn],[/.[aeiou]r?ried$/,zn],[/.[bcdgtr]led$/,zn],[/.[aoui]f?led$/,zn],[/.[iao]sed$/,zn],[/[aeiou]n?[cs]ed$/,zn],[/[aeiou][rl]?[mnf]ed$/,zn],[/[aeiou][ns]?c?ked$/,zn],[/[aeiou][nl]?ged$/,zn],[/.[tdbwxz]ed$/,zn],[/[^aeiou][aeiou][tvx]ed$/,zn],[/.[cdlmnprstv]ied$/,zn],[/[^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$/,Gn],[/...lly$/,Gn],[/[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"]},za=function(e){return Oa.hasOwnProperty(e.clean)?Oa[e.clean]:null},Ga=/([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(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(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?wi=wi.concat(t):wi.push(e)})),wi.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:ni(r),words:ni(n)}),e}));var ki=wi,Ai=function(e){ki.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=ni(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},Ni=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},_i=/\(/,Ki=/\)/,qi=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(_i,"");var r=e.lastTerm();r.post=r.post.replace(Ki,"")})),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 $i(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),e}();ho.prototype.buildFrom=function(e){return e=e.map((function(e){return e.clone(!0)})),new ho(e,this,this.world)},ho.prototype.fromText=function(e){var t=Dt(e,this.world,this.pool());return this.buildFrom(t)},Object.assign(ho.prototype,co.misc),Object.assign(ho.prototype,co.selections),lo(ho);var go={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(go).forEach((function(e){return ho.prototype[e]=ho.prototype[go[e]]}));var po=ho,mo=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 po(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 po(a,null,n);return(t||i.world.taggers.length>0)&&mo(i),i},n.extend=function(e){return e(po,r,this,tt,se,nt),this},n.fromJSON=function(e){var t=$t(e,r);return new po(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.5",n.import=n.load,n.plugin=n.extend,n}(new Or)})); +!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)})))},G=O=function(e,t,r,n){var a=z(e,t,r,n);return!0===t.negative?!a:a},T={},V={doesMatch:function(e,t,r){return G(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*?(\S+)\s*?>/),Oe=function(e){return e[e.length-1]},ze=function(e){return e[0]},Ge=function(e){return e.substr(1)},Te=function(e){return e.substr(0,e.length-1)},Ve=function(e){return e=Ge(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)),"^"===ze(t)&&(n.start=!0,t=Ge(t)),("["===ze(t)||"]"===Oe(t))&&(n.named=!0,"["===ze(t)?n.groupType="]"===Oe(t)?"single":"start":n.groupType="end",t=(t=t.replace(/^\[/,"")).replace(/\]$/,""),"<"===ze(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)),"!"===ze(t)&&(n.negative=!0,t=Ge(t)),"("===ze(t)&&")"===Oe(t)){Fe.test(t)?(n.choices=t.split(Fe),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]=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("/"===ze(t)&&"/"===Oe(t))return t=Ve(t),n.regex=new RegExp(t),n;if("~"===ze(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,""}))),"#"===ze(t)?(n.tag=Ge(t),n.tag=(r=n.tag).charAt(0).toUpperCase()+r.substr(1),n):"@"===ze(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)},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\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,3}[a-z]{0,2}[-–—][0-9]{1,3}[a-z]{0,2}$/,["Value","NumberRange"]],[/^[0-9][0-9]?(:[0-9][0-9])?(am|pm)?[-–—][0-9][0-9]?(:[0-9][0-9])?(am|pm)?$/,["Time","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",zn="PastTense",Gn="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$/,zn],[/.[aeo]{2}[bdgmnprvz]ed$/,zn],[/.[aeiou][sg]hed$/,zn],[/.[aeiou]red$/,zn],[/.[aeiou]r?ried$/,zn],[/.[bcdgtr]led$/,zn],[/.[aoui]f?led$/,zn],[/.[iao]sed$/,zn],[/[aeiou]n?[cs]ed$/,zn],[/[aeiou][rl]?[mnf]ed$/,zn],[/[aeiou][ns]?c?ked$/,zn],[/[aeiou][nl]?ged$/,zn],[/.[tdbwxz]ed$/,zn],[/[^aeiou][aeiou][tvx]ed$/,zn],[/.[cdlmnprstv]ied$/,zn],[/[^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$/,Gn],[/...lly$/,Gn],[/[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"]},za=function(e){return Oa.hasOwnProperty(e.clean)?Oa[e.clean]:null},Ga=/([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(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(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?wi=wi.concat(t):wi.push(e)})),wi.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:ni(r),words:ni(n)}),e}));var ki=wi,Ai=function(e){ki.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=ni(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},Ni=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},_i=/\(/,Ki=/\)/,qi=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(_i,"");var r=e.lastTerm();r.post=r.post.replace(Ki,"")})),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 $i(this)}},{key:"pool",value:function(){return this.list.length>0?this.list[0].pool:this.all().list[0].pool}}]),e}();ho.prototype.buildFrom=function(e){return e=e.map((function(e){return e.clone(!0)})),new ho(e,this,this.world)},ho.prototype.fromText=function(e){var t=Dt(e,this.world,this.pool());return this.buildFrom(t)},Object.assign(ho.prototype,co.misc),Object.assign(ho.prototype,co.selections),lo(ho);var go={untag:"unTag",and:"match",notIf:"ifNo",only:"if",onlyIf:"if"};Object.keys(go).forEach((function(e){return ho.prototype[e]=ho.prototype[go[e]]}));var po=ho,mo=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 po(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 po(a,null,n);return(t||i.world.taggers.length>0)&&mo(i),i},n.extend=function(e){return e(po,r,this,tt,se,nt),this},n.fromJSON=function(e){var t=$t(e,r);return new po(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.6",n.import=n.load,n.plugin=n.extend,n}(new Or)})); diff --git a/builds/compromise.mjs b/builds/compromise.mjs index b7b96ccdb..8169e2fde 100644 --- a/builds/compromise.mjs +++ b/builds/compromise.mjs @@ -1,4 +1,4 @@ -/* compromise 13.10.5 MIT */ +/* compromise 13.10.6 MIT */ function _typeof(obj) { "@babel/helpers - typeof"; @@ -3860,7 +3860,7 @@ var fromJSON = function fromJSON(json, world) { var fromJSON_1 = fromJSON; -var _version = '13.10.5'; +var _version = '13.10.6'; var entity = ['Person', 'Place', 'Organization']; var nouns$1 = { @@ -10721,14 +10721,28 @@ var _07French = checkFrench; var isNumber = /^[0-9]+$/; var isOrdinal = /^[0-9]+(st|nd|rd|th)$/; -var isTime = /^[0-9:]+(am|pm)$/; +var isTime = /^[0-9:]+(am|pm)?$/; var createPhrase = function createPhrase(found, doc) { //create phrase from ['would', 'not'] var phrase = _01Tokenizer(found.join(' '), doc.world, doc.pool())[0]; //tag it var terms = phrase.terms(); - _01Lexicon(terms, doc.world); //make these terms implicit + _01Lexicon(terms, doc.world); + var term = terms[0]; // tag number-ranges + + if (isOrdinal.test(term.text)) { + terms[0].tag('Ordinal', 'ord-range', doc.world); + terms[2].tag('Ordinal', 'ord-range', doc.world); + } else if (isNumber.test(term.text)) { + terms[0].tag('Cardinal', 'num-range', doc.world); + terms[2].tag('Cardinal', 'num-range', doc.world); + } else if (isTime.test(term.text)) { + terms[0].tag('Time', 'time-range', doc.world); + terms[1].tag('Date', 'time-range', doc.world); + terms[2].tag('Time', 'time-range', doc.world); + } //make these terms implicit + terms.forEach(function (t) { t.implicit = t.text; @@ -10736,15 +10750,9 @@ var createPhrase = function createPhrase(found, doc) { t.clean = ''; // remove whitespace for implicit terms t.pre = ''; - t.post = ''; // tag number-ranges - - if (isNumber.test(t.implicit)) { - t.tag('Cardinal', 'num-range', doc.world); - } else if (isOrdinal.test(t.implicit)) { - t.tag('Ordinal', 'ord-range', doc.world); - } else if (isTime.test(t.implicit)) { - t.tag('Time', 'time-range', doc.world); - } else if (Object.keys(t.tags).length === 0) { + t.post = ''; + + if (Object.keys(t.tags).length === 0) { t.tags.Noun = true; // if no tag, give it a noun } }); @@ -13858,9 +13866,7 @@ var Quotations = addMethod$2; // walked => walk - turn a verb into it's root form var toInfinitive = function toInfinitive(parsed, world) { - var verb = parsed.verb; // console.log(parsed) - // verb.debug() - //1. if it's already infinitive + var verb = parsed.verb; //1. if it's already infinitive var str = verb.text('reduced'); diff --git a/changelog.md b/changelog.md index d17654e33..7bf92ce24 100644 --- a/changelog.md +++ b/changelog.md @@ -8,62 +8,78 @@ compromise uses semver, and pushes to npm frequently While all _Major_ releases should be reviewed, our only two _large_ releases are **v6** in 2016 and and **v12** in 2019. Others have been mostly incremental, or niche. - -#### 13.10.5 [March 2021] + +#### 13.10.6 [April 2021] + +- **[fix]** - support more time-ranges + _plugin-releases_: dates@2.0.2 + +#### 13.10.5 [March 2021] + - **[new]** - support Time-range like '3pm-4pm' - **[change]** - cleanup some unicode regexes -*plugin-releases*: dates + _plugin-releases_: dates + +#### 13.10.4 [March 2021] -#### 13.10.4 [March 2021] - **[fix]** - match syntax tokenization fix - **[change]** - improved performance monitoring - -#### 13.10.3 [March 2021] + +#### 13.10.3 [March 2021] + - **[fix]** - support complicated regular-expressions in match syntax - improved performance testing - -#### 13.10.2 [March 2021] + +#### 13.10.2 [March 2021] + - **[fix]** - support matching implicit terms in (or|blocks) - **[change]** - add #Timezone tag (from date-plugin) - **[change]** - add many more cities and regions #### 13.10.1 [March 2021] + - **[change]** - #Date terms can still be a #Conjunction - **[new]** - #Imperative tag and `.verbs().isImperative()` method - **[fix]** - some tagger issues - update deps -*plugin-releases*: dates - + _plugin-releases_: dates #### 13.10.0 [Feb 2021] + - **[new]** - #Fraction tag and improved fraction support (thanks Jakeii!) - **[fix]** - edge-case match issues with `!` syntax - **[change]** - update deps - updates for `compromise-dates@1.4.0`, `compromise-numbers@1.2.0` #### 13.9.3 [Feb 2021] + - **[fix]** - fix weird ordering issue with named exports #815 - + #### 13.9.2 [Feb 2021] + - **[fix]** - typescript issue - + #### 13.9.1 [Feb 2021] -- **[fix]** - matches over a contraction + +- **[fix]** - matches over a contraction - **[new]** - add 'implicit' text output #### 13.9.0 [Feb 2021] + - **[new]** - World.addConjugations() method - **[new]** - World.addPlurals() method - **[new]** - start compromise-penn-tags plugin - **[new]** - add fuzzy option to match commands - **[new]** - support multiple-word matches in OR matches (a|b|foo bar|c) -- **[change] (internal)** - rename 'oneOf' match syntax to 'fastOr' +- **[change] (internal)** - rename 'oneOf' match syntax to 'fastOr' - **[change]** - use new export maps format - **[fix]** - conjugations fixes #800 - **[fix]** - tokenization fixes #801 #### 13.8.0 [Dec 2020] + - **[change]** improved support for fractions in numbers-plugin #793 - **[change]** remove zero-width characters in normalized output #759 - **[change]** improved Person tagging with particles #794 @@ -86,8 +102,8 @@ While all _Major_ releases should be reviewed, our only two _large_ releases are - **[new]** - support `.apppend(doc)` and `.prepend(doc)` - **[new]** - `values.normalize()` method - #### 13.7.0 [Oct 2020] + - **[change]** many misc tagging fixes - 'if' is now a #Preposition - possessive pronouns are #Pronoun and #Possessive @@ -185,8 +201,8 @@ _major changes to `.export()` and `[capture] group` match-syntax._ modifications: -- **[fix]** - nlp.clone() - hasn't worked properly, since v12. (@Drache93) -- **[fix]** - issues with greedy capture [*] and [.+] -(@Drache93) 💛 +- **[fix]** - nlp.clone() - hasn't worked properly, since v12. (@Drache93) +- **[fix]** - issues with greedy capture [*] and [.+] -(@Drache93) 💛 - add whitespace properties (pre+post) to default json output (suppress with `.json({ whitespace: false })`) - `.lookup({ key: val })` with an object now returns an object back ({val: Doc}) - add nlp constructor as a third param to `.extend()` @@ -197,10 +213,10 @@ modifications: - allow null results in `.map()` function - better typescript support - allow longer acronyms -- **[fix]** - offset length issue -- **[new]** - add new named-match syntax, with .groups() method (@Drache93) -- **[new]** - add `nlp.fromJSON()` method -- **[new]** - add a new `compromise-tokenize.js` build, without the tagger, or data included. +- **[fix]** - offset length issue +- **[new]** - add new named-match syntax, with .groups() method (@Drache93) +- **[new]** - add `nlp.fromJSON()` method +- **[new]** - add a new `compromise-tokenize.js` build, without the tagger, or data included. #### 12.3.0 [Jan 2020] diff --git a/package-lock.json b/package-lock.json index 1cf3ec971..0bd5f9ea8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "compromise", - "version": "13.10.5", + "version": "13.10.6", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "13.10.5", + "version": "13.10.6", "license": "MIT", "dependencies": { "efrt-unpack": "2.2.0" @@ -14,7 +14,7 @@ "@babel/core": "7.13.14", "@babel/preset-env": "7.13.12", "@rollup/plugin-alias": "3.1.2", - "@rollup/plugin-commonjs": "17.1.0", + "@rollup/plugin-commonjs": "18.0.0", "@rollup/plugin-json": "4.1.0", "@rollup/plugin-node-resolve": "11.2.1", "amble": "1.3.0", @@ -1174,9 +1174,9 @@ } }, "node_modules/@rollup/plugin-commonjs": { - "version": "17.1.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-17.1.0.tgz", - "integrity": "sha512-PoMdXCw0ZyvjpCMT5aV4nkL0QywxP29sODQsSGeDpr/oI49Qq9tRtAsb/LbYbDzFlOydVEqHmmZWFtXJEAX9ew==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", + "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", "dev": true, "dependencies": { "@rollup/pluginutils": "^3.1.0", @@ -1189,6 +1189,9 @@ }, "engines": { "node": ">= 8.0.0" + }, + "peerDependencies": { + "rollup": "^2.30.0" } }, "node_modules/@rollup/plugin-commonjs/node_modules/estree-walker": { @@ -5231,9 +5234,9 @@ } }, "@rollup/plugin-commonjs": { - "version": "17.1.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-17.1.0.tgz", - "integrity": "sha512-PoMdXCw0ZyvjpCMT5aV4nkL0QywxP29sODQsSGeDpr/oI49Qq9tRtAsb/LbYbDzFlOydVEqHmmZWFtXJEAX9ew==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", + "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", "dev": true, "requires": { "@rollup/pluginutils": "^3.1.0", diff --git a/package.json b/package.json index ce905836a..e361d8fc8 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.5", + "version": "13.10.6", "main": "./builds/compromise.js", "unpkg": "./builds/compromise.min.js", "module": "./builds/compromise.mjs", @@ -75,7 +75,7 @@ "@babel/core": "7.13.14", "@babel/preset-env": "7.13.12", "@rollup/plugin-alias": "3.1.2", - "@rollup/plugin-commonjs": "17.1.0", + "@rollup/plugin-commonjs": "18.0.0", "@rollup/plugin-json": "4.1.0", "@rollup/plugin-node-resolve": "11.2.1", "amble": "1.3.0", diff --git a/plugins/dates/builds/compromise-dates.js b/plugins/dates/builds/compromise-dates.js index c57957285..9f4becfd5 100644 --- a/plugins/dates/builds/compromise-dates.js +++ b/plugins/dates/builds/compromise-dates.js @@ -1,4 +1,4 @@ -/* compromise-dates 2.0.0 MIT */ +/* compromise-dates 2.0.2 MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : @@ -326,11 +326,6 @@ var here$5 = 'date-values'; // var values = function values(doc) { - // a year ago - if (!doc.has('once [a] #Duration')) { - doc.match('[a] #Duration', 0).replaceWith('1').tag('Cardinal', here$5); - } - if (doc.has('#Value')) { //june 5 to 7th doc.match('#Month #Value to #Value of? #Year?').tag('Date', here$5); //5 to 7th june @@ -450,7 +445,9 @@ date.match('half an (hour|minute|second)').tag('Date', here$2); // in eastern time - date.match('(in|for|by|near|at) #Timezone').tag('Timezone', here$2); //--time-ranges-- + date.match('(in|for|by|near|at) #Timezone').tag('Timezone', here$2); // 3pm to 4pm + + date.match('#Time to #Time').tag('Date', here$2); //--time-ranges-- // 4pm sharp date.match('#Time [(sharp|on the dot)]', 0).tag('Time', here$2); @@ -468,9 +465,28 @@ } // from 4 to 5 tomorrow - date.match('(from|between) #NumericValue and #NumericValue (in|on)? (#WeekDay|tomorrow|yesterday)').tag('Date', '4-to-5pm').match('#NumericValue').tag('Time', here$2); // from 4 to 5pm + date.match('(from|between) #Cardinal and #Cardinal (in|on)? (#WeekDay|tomorrow|yesterday)').tag('Date', '4-to-5pm').match('#NumericValue').tag('Time', here$2); // from 4 to 5pm + + date.match('(from|between) [#NumericValue] (to|and) #Time', 0).tag('Time', '4-to-5pm'); // date.match('#Cardinal to #Time') + // wed from 3 to 4 + + date.match('(#WeekDay|tomorrow|yesterday) from? (#Cardinal|#Time) to (#Cardinal|#Time)').tag('Date', here$2).match('#Cardinal').tag('#Time', 'tues 3-5'); // june 5 from 3 to 4 - date.match('(from|between) [#NumericValue] (to|and) #Time', 0).tag('Time', '4-to-5pm'); + var m = date.match('#Month #Value+ from [