compromise
Version:
modest natural language processing
2 lines • 93.1 kB
JavaScript
((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";var t={methods:{one:{},two:{},three:{},four:{}},model:{one:{},two:{},three:{}},compute:{},hooks:[]};const e={compute:function(t,e){const{world:n}=this,o=n.compute;return"string"==typeof t&&Object.hasOwn(o,t)?o[t](this,e):Array.isArray(t)?t.forEach(r=>{Object.hasOwn(n.compute,r)?o[r](this,e):console.warn("no compute:",t)}):"function"==typeof t?t(this,e):console.warn("no compute:",t),this}},n=(t,e)=>(n,o)=>e(t.update([n]),o);var o={forEach:function(t){return this.fullPointer.forEach(n(this,t)),this},map:function(t,e){const o=n(this,t),r=this.fullPointer.map((t,e)=>{const n=o(t,e);return void 0===n?this.none():n});if(0===r.length)return e||this.update([]);if(void 0!==r[0]){if("string"==typeof r[0])return r;if("object"==typeof r[0]&&(null===r[0]||!r[0].isView))return r}let s=[];return r.forEach(t=>{s=s.concat(t.fullPointer)}),this.toView(s)},filter:function(t){return this.update(this.fullPointer.filter(n(this,t)))},find:function(t){const e=this.fullPointer.find(n(this,t));return void 0===e?this.update([]):this.update([e])},some:function(t){return this.fullPointer.some(n(this,t))},random:function(t=1){let e=this.fullPointer,n=Math.floor(Math.random()*e.length);return n+t>this.length&&(n=this.length-t,n=n<0?0:n),e=e.slice(n,n+t),this.update(e)}};const r=t=>t.pointer||t.docs.map((t,e)=>[e]),s=(t,e)=>(t.compute([...e,"freeze","lexicon"]),t.world.compute.preTagger&&t.compute("preTagger"),t.compute("unfreeze"),t),i={termList:function(){return this.methods.one.termList(this.docs)},terms:function(t){const e=this.match(".");return"number"==typeof t?e.eq(t):e},groups:function(t){if(t||0===t)return this.update(this._groups[t]||[]);const e={};return Object.keys(this._groups).forEach(t=>{e[t]=this.update(this._groups[t])}),e},eq:function(t){const e=r(this);return e[t]?this.update([e[t]]):this.none()},first:function(){return this.eq(0)},last:function(){const t=this.fullPointer.length-1;return this.eq(t)},firstTerms:function(){return this.match("^.")},lastTerms:function(){return this.match(".$")},slice:function(t,e){return this.update(r(this).slice(t,e))},all:function(){return this.update().toView()},fullSentences:function(){const t=this.fullPointer.map(t=>[t[0]]);return this.update(t).toView()},none:function(){return this.update([])},isDoc:function(t){if(!t||!t.isView)return!1;const e=this.fullPointer,n=t.fullPointer;return e.length===n.length&&e.every((t,e)=>n[e]&&t[0]===n[e][0]&&t[1]===n[e][1]&&t[2]===n[e][2])},wordCount:function(){return this.docs.reduce((t,e)=>t+e.filter(t=>""!==t.text).length,0)},isFull:function(){const t=this.pointer;if(!t)return!0;if(0===t.length||0!==t[0][0])return!1;let e=0,n=0;return this.document.forEach(t=>e+=t.length),this.docs.forEach(t=>n+=t.length),e===n},getNth:function(t){return"number"==typeof t?this.eq(t):"string"==typeof t?this.if(t):this}};i.group=i.groups,i.fullSentence=i.fullSentences,i.sentence=i.fullSentences,i.lastTerm=i.lastTerms,i.firstTerm=i.firstTerms;const a={...i,...e,...o};a.get=a.eq;class c{constructor(e,n,o={}){[["document",e],["world",t],["_groups",o],["_cache",null]].forEach(t=>{Object.defineProperty(this,t[0],{value:t[1],writable:!0})}),this.ptrs=n}get docs(){let e=this.document;return this.ptrs&&(e=t.methods.one.getDoc(this.ptrs,this.document)),e}get pointer(){return this.ptrs}get methods(){return this.world.methods}get model(){return this.world.model}get hooks(){return this.world.hooks}get isView(){return!0}get found(){return this.docs.length>0}get length(){return this.docs.length}get fullPointer(){const{docs:t,ptrs:e,document:n}=this;return(e||t.map((t,e)=>[e])).map(t=>{let[e,o,r,s,i]=t;return o||=0,r||=(n[e]||[]).length,n[e]?.[o]&&(s||=n[e][o].id,n[e][r-1]&&(i||=n[e][r-1].id)),[e,o,r,s,i]})}update(t){const e=new c(this.document,t);if(this._cache&&t?.length>0){const n=[];t.forEach((t,e)=>{const[o,r,s]=t;(1===t.length||0===r&&this.document[o].length===s)&&(n[e]=this._cache[o])}),n.length>0&&(e._cache=n)}return e.world=this.world,e}toView(t){return new c(this.document,t||this.pointer)}fromText(t){const{methods:e}=this,n=e.one.tokenize.fromString(t,this.world),o=new c(n);return o.world=this.world,s(o,["normal"])}clone(){let t=this.document.slice(0);t=t.map(t=>t.map(t=>((t={...t}).tags=new Set(t.tags),t)));const e=this.update(this.pointer);return e.document=t,e._cache=this._cache,e}}Object.assign(c.prototype,a),c.prototype.viewType="View";const l=t=>t&&"object"==typeof t&&!Array.isArray(t),u=t=>"__proto__"===t||"constructor"===t||"prototype"===t;function h(t,e){if(l(e))for(const n in e)u(n)||(l(e[n])?(t[n]||(t[n]={}),h(t[n],e[n])):Array.isArray(e[n])&&Array.isArray(t[n])?t[n]=t[n].concat(e[n]):t[n]=e[n]);return t}const p=[["pastTense","Past"],["presentTense","Present"],["gerund","Gerund"],["comparative","Comparative"],["superlative","Superlative"]],f=(t,e,n,o)=>{if(Array.isArray(t))return void t.forEach(t=>f(t,e,n,o));const{methods:r,model:s,compute:i,hooks:a}=e;t.methods&&((t,e)=>{for(const n in e)u(n)||(t[n]||={},Object.assign(t[n],e[n]))})(r,t.methods),t.model&&h(s,t.model),t.irregulars&&((t,e)=>{const n=t.two.models||{};Object.keys(e).forEach(t=>{p.forEach(([o,r])=>{const s=e[t][o];s&&(n["to"+r]&&(n["to"+r].ex[t]=s),n["from"+r]&&(n["from"+r].ex[s]=t))})})})(s,t.irregulars),t.compute&&Object.assign(i,t.compute),a&&(e.hooks=a.concat(t.hooks||[])),t.onReplace&&(r.one.onReplace=(r.one.onReplace||[]).concat(t.onReplace)),t.api&&t.api(n),t.lib&&Object.keys(t.lib).forEach(e=>o[e]=t.lib[e]),t.tags&&o.addTags(t.tags),t.words&&o.addWords(t.words),t.frozen&&o.addWords(t.frozen,!0),t.mutate&&t.mutate(e,o)},d="undefined"!=typeof process&&Object.hasOwn(process.env||{},"NO_COLOR"),m=t=>e=>d?e:"["+t+"m"+e+"[0m",g=m(32),w=m(31),b=m(34),y=m(36),v=m(33),x=m(35),j=m(2),O=m(3),k=m(1),E=m(4),$=m(90);var S=Object.freeze({__proto__:null,b:k,blue:b,cyan:y,dim:j,green:g,grey:$,i:O,magenta:x,red:w,ul:E,yellow:v});const A=globalThis.process?.env??globalThis.env??{},z={tags:Boolean(A.DEBUG_TAGS),before:t=>!z.tags||z.word&&z.word!==(t.normal||t.text||t.implicit||"").toLowerCase()?null:[...t.tags],log:(t,e,n="")=>{if(!e)return;const o=[...t.tags].filter(t=>!e.includes(t)),r=e.filter(e=>!t.tags.has(e));if(!o.length&&!r.length)return;const s=t.text||t.implicit||"",i=t.index?.join(":")||"?",a=z.prefix||" ";if(z.rule!==n){const t=z.prefix?a.replace("│ ","│ "):" ";console.log(`${t}${j((n||"tag change")+":")}`),z.rule=n}const c=(t,e,n)=>{if(!t.length)return;const o=n(`'${s}'`),r=t.map(t=>n(`#${t}`)).join(" ");console.log(`${a}${n(e)} ${o} ${j(i.padEnd(9))} ${r}`)};c(r,"−",w),c(o,"+",g)}},P=(t,e)=>{const n=t.methods.one,o=n.match,r=n.parseMatch,s=new WeakMap,i=e.word?.toLowerCase(),a=t=>!i||t.some(t=>(t.normal||t.text||t.implicit||"").toLowerCase()===i),c=function(...t){const e=r.apply(this,t);return s.set(e,String(t[0])),e},l=function(t,n,r){const c=o.call(this,t,n,r),l=n.match||s.get(n.regs)||"[parsed pattern]";if(void 0!==e.pattern&&l!==e.pattern)return c;if(i&&!t.some(a))return c;const u=c.ptrs.map(([e,n,o])=>t[e].slice(n,o)).filter(a);if(i&&c.ptrs.length&&!u.length)return c;z.rule=void 0;const h=c.ptrs.length?g("✓"):w("✗"),p=u.map(t=>{const e=t.map(t=>t.text||t.implicit).join(" ");return`${g("'"+e+"'")} ${j(t[0]?.index?.join(":")||"?")}`}).join(", "),f=l.length>80?l.slice(0,79)+"…":l,d=p?p+" ":" --- ";return console.log(`${z.prefix||" "}${h} ${d}${j(O(f))}`),c};return n.parseMatch=c,n.match=l,()=>{n.parseMatch===c&&(n.parseMatch=r),n.match===l&&(n.match=o)}};let T;const _=t=>"[object Object]"===Object.prototype.toString.call(t),C=(t,e,n)=>{const{methods:o}=n,r=new e([]);return r.world=n,"number"==typeof t&&(t=String(t)),t?"string"==typeof t?new e(o.one.tokenize.fromString(t,n)):_(t)&&t.isView?new e(t.document,t.ptrs):Array.isArray(t)?Array.isArray(t[0])?new e(t.map(t=>t.map(t=>({text:t,normal:t,pre:"",post:" ",tags:new Set})))):new e(t.map(t=>t.terms.map(t=>(Array.isArray(t.tags)&&(t.tags=new Set(t.tags)),t)))):r:r},L={...t},N=["alias","normal","machine","contractions"],M=function nlp(t,e){e&&nlp.addWords(e);const n=C(t,c,L);return t&&(z.hooks?z.hooks(n,L.hooks):n.compute(L.hooks)),n};Object.defineProperty(M,"_world",{value:L,writable:!0}),M.tokenize=function(t,e){const{compute:n}=this._world;e&&M.addWords(e);const o=C(t,c,L);return z.hooks?z.hooks(o,n.contractions?N:[]):n.contractions&&o.compute(N),o},M.plugin=function(t){return f(t,this._world,c,this),this},M.extend=M.plugin,M.world=function(){return this._world},M.model=function(){return this._world.model},M.methods=function(){return this._world.methods},M.hooks=function(){return this._world.hooks},M.verbose=function(t=!0,e={}){return T?.(),T=void 0,"match"!==t&&!0!==t||(T=P(this._world,e)),z.hooks="hooks"===t||!0===t?(n=!0===t,(t,e)=>{const o=Math.max(8,...e.map(t=>t.length)),r=(e,n=!1)=>{const r=(t=>t.docs.map((e,n)=>{const o=e.map(t=>t.pre+t.text+t.post).join("").trim(),r=j("'"+o+"'"),s=t.update([[n]]).out("spec");return r+$(O(s.slice(o.length)))}).join("\n"))(t);r.split("\n").forEach((t,r,s)=>{if(n){const e=r===s.length-1?" ╰─":"│ ";return void console.log(` ${j(e)} ${t}`)}const i=(0===r?e:"").padEnd(o);console.log(` ${j(i)} ${t}`)})};r("tokenize"),e.forEach(e=>{const o=n,s=z.prefix,i=z.rule;z.rule=void 0,o&&(console.log(` ${b(k(E(e+":")))}`),z.prefix=j(" │ "));try{t.compute(e),r(e,o)}finally{z.prefix=s,z.rule=i}})}):void 0,z.word=e.word?.toLowerCase(),z.contractions="contractions"===t||!0===t,z.rule=void 0,z.tags="tagger"===t||!0===t,z.spec="spec"===t||!0===t,this;var n},M.version="14.21.0";var q={one:{cacheDoc:t=>{const e=t.map(t=>{const e=new Set;return t.forEach(t=>{""!==t.normal&&e.add(t.normal),t.switch&&e.add(`%${t.switch}%`),t.implicit&&e.add(t.implicit),t.machine&&e.add(t.machine),t.root&&e.add(t.root),t.alias&&t.alias.forEach(t=>e.add(t)),t.tags.forEach(t=>{e.add("#"+t)})}),e});return e}}};const F={cache:function(){return this._cache=this.methods.one.cacheDoc(this.document),this},uncache:function(){return this._cache=null,this}};var W={api:t=>{Object.assign(t.prototype,F)},compute:{cache:t=>{t._cache=t.methods.one.cacheDoc(t.document)}},methods:q};const B=(t,e)=>{for(let n=0;n<t.length;n+=1){const o=t[n];for(let t=0;t<o.length;t+=1)e(o[t],o,t,n)}},V=t=>t.replace(/^ *[a-z\u00C0-\u00FF]/,t=>t.toUpperCase()),U=(t,e)=>(t.termList().forEach(t=>{t.text=e(t.text)}),t);var R={toLowerCase:function(){return U(this,t=>t.toLowerCase())},toUpperCase:function(){return U(this,t=>t.toUpperCase())},toTitleCase:function(){return U(this,V)},toCamelCase:function(){return B(this.docs,(t,e,n)=>{0!==n&&(t.text=V(t.text)),n!==e.length-1&&(t.post="")}),this}};const D=t=>/^\p{Lu}[\p{Ll}'’]/u.test(t)||/^\p{Lu}$/u.test(t),I=t=>t.replace(/^\p{Ll}/u,t=>t.toUpperCase()),G=t=>t.replace(/^\p{Lu}/u,t=>t.toLowerCase()),Q=(t,e,n)=>{var o;/^\p{Lu}/u.test(t.text)&&(e.text=I(e.text),n&&!(o=t).tags.has("ProperNoun")&&!o.tags.has("Acronym")&&1!==o.text.length&&D(o.text)&&(t.text=G(t.text)))},H=(t,e)=>{e.pre=t.pre+e.pre,t.pre=""},Z=(t,e,n)=>(n.forEach(t=>t.dirty=!0),t&&t.splice(e,0,...n),t),J=t=>{const e=t.at(-1);!e||/ $/.test(e.post)||/[-–—]/.test(e.post)||(e.post+=" ")};let K=0;const X=t=>t.padStart(3,"0"),Y=t=>{let[e,n]=t.index||[0,0];K+=1,K=K>46655?0:K,e=e>46655?0:e,n=n>1294?0:n;let o=X(K.toString(36));return o+=X(e.toString(36)),o+=n.toString(36).padStart(2,"0"),o+=parseInt(36*Math.random(),10).toString(36),t.normal+"|"+o.toUpperCase()},tt=t=>{t.has("@hasContraction")&&t.contractions&&t.grow("@hasContraction").contractions().expand()},et=(t,e,n,o={})=>{const r=!1!==o.agree,{document:i,world:a}=e;e.uncache();const c=e.fullPointer,l=e.fullPointer;e.forEach((o,s)=>{const u=o.fullPointer[0],[h]=u,p=i[h];let f=((t,e)=>{const{methods:n}=e;return"string"==typeof t?n.one.tokenize.fromString(t,e)[0]:"object"==typeof t&&t.isView?t.clone().docs[0]||[]:Array.isArray(t)?Array.isArray(t[0])?t[0]:t:[]})(t,a);0!==f.length&&(f=(t=>t.map(t=>(t.id=Y(t),t)))(f),n?(tt(e.update([u]).firstTerm()),((t,e,n,o,r)=>{const[s,i,a]=e;0===i||a===o[s].length?J(n):(J(n),J([t[e[1]]])),r&&(H(t[i],n[0]),0===i&&Q(t[i],n[0],!0)),Z(t,i,n)})(p,u,f,i,r)):(tt(e.update([u]).lastTerm()),((t,e,n,o,r)=>{const[s,,i]=e,a=(o[s]||[]).length,c=r&&t[i-1]&&((t,e,n)=>{const o=t[e];if(!o.post||(t=>/^[-–]$/.test(t))(o.post)||((t,e)=>!!/^['’]/.test(t[e].post)&&!t.slice(0,e+1).some(t=>/['‘]/.test(t.pre)))(t,e))return!1;let r=o.post;return/[.?!…]/.test(n.post)&&(r=r.replace(/^[.?!…]+/,"")),n.post=n.post.trimEnd()+r,o.post=" ",!0})(t,i-1,n.at(-1));!c&&i<a?J(n):c||(J(t),o[s+1]&&(n.at(-1).post+=" ")),Z(t,e[2],n),e[4]=n.at(-1).id})(p,u,f,i,r)),i[h]?.[u[1]]&&(u[3]=i[h][u[1]].id),l[s]=u,u[2]+=f.length,c[s]=u)});const u=e.toView(c);return e.ptrs=l,s(u,["id","index"])},nt={insertAfter:function(t,e){return et(t,this,!1,e)},insertBefore:function(t,e){return et(t,this,!0,e)}};nt.append=nt.insertAfter,nt.prepend=nt.insertBefore,nt.insert=nt.insertAfter;const ot=/\$[0-9a-z]+/g,rt={},st=(t,e,n)=>{const o=[];return t.forEach((t,r)=>{const s=t.replaceWith(e(t,r),n);o.push(...s.fullPointer)}),t.ptrs&&(t.ptrs=o),t},it=t=>{const e=t.at(-1);return{pre:t[0].pre,post:e.post,isTitleCase:D(t[0].text),text:t[0].text,isPossessive:e.tags.has("Possessive"),tags:t.map(t=>Array.from(t.tags))}};rt.replaceWith=function(t,e={}){!0===e&&(e={tags:!0,case:!0,possessives:!0});const n=this;if(this.uncache(),!n.found)return n;if("function"==typeof t)return st(n,t,e);if("string"==typeof t&&t.includes("$")&&Object.keys(n._groups).length>0){const o=n.fullPointer.map(e=>((t,e,[n,o,r])=>{const s=e._groups;return t.replace(ot,t=>{const i=t.replace(/\$/,""),a=(Object.hasOwn(s,i)?s[i]:[]).find(t=>t[0]===n&&t[1]>=o&&t[2]<=r);return a?e.update([a]).text({keepEndPunct:!1}):t})})(t,n,e));return st(n,(t,e)=>o[e],e)}const o=n.docs.map(it),r=this.world.methods.one.onReplace&&this.fullPointer.map(([t,e,n])=>({sentence:this.document[t],before:new Set(this.document[t]),oldTerms:this.document[t].slice(e,n)})),i=this.update(this.fullPointer);"string"==typeof t&&(t=this.fromText(t).compute("id"));const a=!1!==e.agree;n.insertAfter(t,{agree:a}),r&&r.forEach(t=>{const e=t.sentence.indexOf(t.oldTerms.at(-1))+1;t.newTerms=[];for(let n=e;n<t.sentence.length&&!t.before.has(t.sentence[n]);n+=1)t.newTerms.push(t.sentence[n])}),i.has("@hasContraction")&&n.contractions&&n.grow("@hasContraction+").contractions().expand(),n.delete(i,{agree:a,start:!1!==e.case,end:!1}),a&&n.docs.forEach((t,n)=>((t,e,n)=>{const o=t.at(-1);if(n.possessives&&e.isPossessive&&!o.tags.has("Possessive")&&(o.text+="'s",o.normal+="'s",o.tags.add("Possessive")),e.pre&&(t[0].pre=e.pre),e.post){const t=o.post.trim();t&&t!==e.post.trim()||(o.post=e.post)}})(t,o[n],e));const c=s(n.toView(),["index"]);return e.tags&&c.forEach((t,e)=>{t.terms().forEach((t,n)=>t.tagSafe(o[e].tags[n]))}),e.case&&c.docs.forEach((t,e)=>{const n=o[e].isTitleCase?I:G;t[0].text=((t,e)=>t.length>1&&t===t.toUpperCase()&&t!==t.toLowerCase()?e.toUpperCase():/^\p{Lu}/u.test(t)?I(e):e)(o[e].text,n(t[0].text))}),c.world.methods.one.onReplace&&r.forEach(({oldTerms:t,newTerms:e})=>{c.world.methods.one.onReplace.forEach(n=>n({oldTerms:t,newTerms:e,document:c.document}))}),c},rt.replace=function(t,e,n){if(t&&void 0===e)return this.replaceWith(t,n);const o=this.match(t);return o.found?(this.soften(),o.replaceWith(e,n)):this};const at=(t,e,n)=>{let o=0;for(;o<t.length;){if(!e.includes(t[o])){o++;continue}const r=o;for(;o<t.length&&e.includes(t[o]);)o++;if(o<t.length&&n.includes(t[o]))return t.slice(0,r)+t.slice(o)}return t},ct={"(":")","[":"]",'"':'"',"“":"”","‘":"’"},lt={remove:function(t,e){const{indexN:n}=this.methods.one.pointer;t&&Object.hasOwn(t,"agree")&&(e=t,t=void 0),this.uncache();let o=this.all(),r=this;t&&(o=this,r=this.match(t));const s=!o.ptrs;tt(r);let i=o.fullPointer;const a=r.fullPointer.reverse(),c=n(a),l=((t,e)=>Object.keys(t).map(Number).filter(n=>{const o=t[n].reduce((t,e)=>t+e[2]-e[1],0);return e[n]&&o>=e[n].length}))(c,this.document),u=((t,e,n={})=>{e.forEach(e=>{const[o,r,s]=e,i=s-r;t[o]&&(!1!==n.agree&&(((t,e,n)=>{const o=t[e],r=t[n-1];Object.keys(ct).forEach(t=>{o.pre.includes(t)&&r.post.includes(ct[t])&&(o.pre=o.pre.replace(t,""),r.post=r.post.replace(ct[t],""))})})(t[o],r,s),s===t[o].length&&s>1?((t,e)=>{const n=t.length-1,o=t[n],r=t[n-e];r&&o&&(r.post+=o.post,r.post=at(r.post," ",'.?!,;:"”)]'),r.post=at(r.post,",;:",".?!"))})(t[o],i):!1!==n.end&&((t,e,n)=>{const o=t[e-1],r=t[n-1].post;o&&/\S/.test(r)&&!/\S/.test(o.post)&&(o.post=r)})(t[o],r,s),!1!==n.start&&((t,e,n)=>{const o=t[n];o&&(H(t[e],o),0===e&&Q(t[e],o))})(t[o],r,s)),t[o].splice(r,i))});for(let e=t.length-1;e>=0;e-=1)if(0===t[e].length&&(t.splice(e,1),e===t.length&&t[e-1])){const n=t[e-1].at(-1);n&&(n.post=n.post.trimEnd())}return t})(this.document,a,e);return i=((t,e,n)=>(t=t.map(t=>{const[o]=t;return(e[o]||[]).forEach(e=>{const n=e[2]-e[1];t[1]<=e[1]&&t[2]>=e[2]?t[2]-=n:t[1]>=e[2]&&(t[1]-=n,t[2]-=n)}),t[0]-=n.filter(t=>t<o).length,t[3]=null,t[4]=null,t}),t.filter(t=>t[2]-t[1]>0)))(i,c,l),o.ptrs=i,o.document=u,o.compute("index"),s&&(o.ptrs=void 0),t?o.toView(i):(this.ptrs=[],o.none())}};lt.delete=lt.remove;const ut=(t,e,n,o)=>(t.docs.forEach(t=>{const r="pre"===e?t[0]:t.at(-1);!0===o?r[e]+=n:r[e]=n}),t),ht=(t,e,n)=>(t.docs.forEach(t=>{t[0].pre=e+t[0].pre;const o=t.at(-1);o.post=n+o.post}),t),pt={pre:function(t,e){return void 0===t&&this.found?this.docs[0][0].pre:ut(this,"pre",t,e)},post:function(t,e){return void 0===t?this.docs.at(-1).at(-1).post:ut(this,"post",t,e)},trim:function(){if(!this.found)return this;const t=this.docs,e=t[0][0];e.pre=e.pre.trimStart();const n=t.at(-1).at(-1);return n.post=n.post.trimEnd(),this},hyphenate:function(){return B(this.docs,(t,e,n)=>{0!==n&&(t.pre=""),e[n+1]&&(t.post="-")}),this},dehyphenate:function(){const t=/[-–—]/;return B(this.docs,e=>{t.test(e.post)&&(e.post=" ")}),this},toQuotations:function(t,e){return ht(this,t||'"',e||'"')},toParentheses:function(t,e){return ht(this,t||"(",e||")")}};pt.deHyphenate=pt.dehyphenate,pt.toQuotation=pt.toQuotations;var ft={alpha:(t,e)=>t.normal<e.normal?-1:t.normal>e.normal?1:0,length:(t,e)=>e.normal.trim().length-t.normal.trim().length,wordCount:(t,e)=>e.words-t.words,sequential:(t,e)=>t.pointer[0]-e.pointer[0]||t.pointer[1]-e.pointer[1]||t.pointer[2]-e.pointer[2],byFreq:t=>{const e=Object.create(null);return t.forEach(t=>{e[t.normal]??=0,e[t.normal]+=1}),t.sort((t,n)=>e[n.normal]-e[t.normal]),t}};const dt=new Set(["index","sequence","seq","sequential","chron","chronological"]),mt=new Set(["freq","frequency","topk","repeats"]),gt=new Set(["alpha","alphabetical"]);var wt={unique:function(){const t=new Set;return this.filter(e=>{const n=e.text("machine");return!t.has(n)&&(t.add(n),!0)})},reverse:function(){const t=[].concat(r(this)).reverse();return this._cache&&(this._cache=this._cache.reverse()),this.update(t)},sort:function(t){const{docs:e}=this;if(this.uncache(),"function"==typeof t)return((t,e)=>{let n=t.fullPointer;return n=n.sort((n,o)=>(n=t.update([n]),o=t.update([o]),e(n,o))),t.ptrs=n,t})(this,t);t||="alpha";const n=r(this);let o=e.map((t,e)=>({index:e,words:t.length,normal:t.map(t=>t.machine||t.normal||"").join(" "),pointer:n[e]}));return dt.has(t)&&(t="sequential"),gt.has(t)&&(t="alpha"),mt.has(t)?(o=ft.byFreq(o),this.update(o.map(t=>t.pointer))):"function"==typeof ft[t]?(o=o.sort(ft[t]),this.update(o.map(t=>t.pointer))):this}};const bt=(t,e)=>{if(t.length>0){const e=t.at(-1).at(-1);/ /.test(e.post)||(e.post+=" ")}return t.concat(e)};var yt={concat:function(t){if("string"==typeof t){const e=this.fromText(t);if(this.found&&this.ptrs){const t=this.fullPointer.at(-1)[0];this.document.splice(t,0,...e.document)}else this.document=this.document.concat(e.document);return this.all().compute("index")}if("object"==typeof t&&t.isView)return((t,e)=>{if(t.document===e.document){const n=t.fullPointer.concat(e.fullPointer);return t.toView(n).compute("index")}return e.fullPointer.forEach(e=>{e[0]+=t.document.length}),t.document=bt(t.document,e.docs),t.all()})(this,t);if(Array.isArray(t)){const e=bt(this.document,t);return this.document=e,this.all()}return this}};const vt={...R,...nt,...rt,...lt,...pt,...wt,...yt,harden:function(){return this.ptrs=this.fullPointer,this},soften:function(){let t=this.ptrs;return t&&0!==t.length?(t=t.map(t=>t.slice(0,3)),this.ptrs=t,this):this}};var xt={api:t=>{Object.assign(t.prototype,vt)},compute:{id:t=>{B(t.docs,t=>{t.id||=Y(t)})}}};const jt=(t,e)=>t.trim().split("\n").map(t=>{const[n,o]=t.trim().split(":");return{[e]:n,out:o.split(" ")}}),Ot=t=>t.trim().split("\n").map(t=>t.trim()),kt=t=>Object.fromEntries(t.map(t=>[t,!0]));var Et={one:{contractions:[...jt("\n@:at\narent:are not\nalot:a lot\nbrb:be right back\ncannot:can not\ndun:do not\ncan't:can not\nshan't:should not\nwon't:will not\nthat's:that is\nwhat's:what is\nlet's:let us\ndunno:do not know\ngonna:going to\ngotta:have got to\ngimme:give me\noutta:out of\ntryna:trying to\ngtg:got to go\nim:i am\nimma:I will\nimo:in my opinion\nirl:in real life\nive:i have\nrn:right now\ntbh:to be honest\nwanna:want to\nc'mere:come here\nc'mon:come on\nshoulda:should have\ncoulda:could have\nwoulda:would have\nmusta:must have\ntis:it is\ntwas:it was\ny'know:you know\nne'er:never\no'er:over\n ","word"),...jt("\nll:will\nve:have\nre:are\nm:am\n ","after"),...jt("\nc:ce\nm:me\nn:ne\nqu:que\ns:se\nt:tu\n ","before"),...jt("\nshouldnt:should not\ncouldnt:could not\nwouldnt:would not\nhasnt:has not\nwasnt:was not\nisnt:is not\ncant:can not\ndont:do not\nwont:will not\nhowd:how did\nwhatd:what did\nwhend:when did\nwhered:where did\n ","word")],numberSuffixes:kt(Ot("\nst\nnd\nrd\nth\nam\npm\nmax\n°\ns\ne\ner\nère\nème\n"))}};const $t=/'/,St=new Set(["what","how","when","where","why"]),At=new Set(["be","go","start","think","need"]),zt=new Set(["been","gone"]),Pt=/^(.+)'(t|d|ll)'ve$/,Tt=(t,e)=>{const n=t[e].normal.match(Pt);if(null===n)return null;const o=n[1];return"d"===n[2]?[o,"would","have"]:"ll"===n[2]?[o,"will","have"]:"can"===o?["can","not","have"]:"won"===o?["will","not","have"]:[o.replace(/n$/,""),"not","have"]},_t=/'/,Ct=/(e|é|aison|sion|tion)$/,Lt=/(age|isme|acle|ege|oire)$/,Nt=new Set(["homme","arbre","espace","exemple","ordre","ange","etre","ete","empire","oncle","angle","article","orchestre","insecte","episode"]),Mt=/(eau|tion|sion)$/,qt=(t,e)=>t[e].normal.split(_t)[1];var Ft={preJ:(t,e)=>["je",qt(t,e)],preL:(t,e)=>{const n=qt(t,e);return n&&(n.endsWith("e")&&!Nt.has(n)||Mt.test(n))?["la",n]:["le",n]},preD:(t,e)=>{const n=qt(t,e);return n&&Ct.test(n)&&!Lt.test(n)?["du",n]:n&&n.endsWith("s")?["des",n]:["de",n]}};const Wt=/^([0-9.]{1,4}[a-z]{0,2}) ?[-–—] ?([0-9]{1,4}[a-z]{0,2})$/i,Bt=/^([0-9]{1,2}(:[0-9][0-9])?(am|pm)?) ?[-–—] ?([0-9]{1,2}(:[0-9][0-9])?(am|pm)?)$/i,Vt=/^[0-9]{3}-[0-9]{4}$/,Ut=(t,e)=>{const n=t[e];let o=n.text.match(Wt);return null!==o?n.tags.has("PhoneNumber")||Vt.test(n.text)?null:[o[1],"to",o[2]]:(o=n.text.match(Bt),null!==o?[o[1],"to",o[4]]:null)},Rt=/^([+-]?[0-9][.,0-9]*)([a-z°²³µ/]+)$/,Dt=(t,e,n)=>{const o=n.model.one.numberSuffixes||{},r=t[e].text.match(Rt);if(null!==r){const t=r[2].toLowerCase().trim();return Object.hasOwn(o,t)?null:[r[1],t]}return null},It=/'/,Gt=/^[0-9][^-–—]*[-–—].*?[0-9]/,Qt={t:(t,e)=>"ain't"===t[e].normal||"aint"===t[e].normal?null:[t[e].normal.replace(/n't/,""),"not"],d:(t,e)=>{const n=t[e].normal.split($t)[0];if(St.has(n))return[n,"did"];if(t[e+1]){if(zt.has(t[e+1].normal))return[n,"had"];if(At.has(t[e+1].normal))return[n,"would"]}return null}},Ht={j:Ft.preJ,l:Ft.preL,d:Ft.preD},Zt=(t,e,n,o)=>{for(let r=0;r<t.length;r+=1){const s=t[r];if(s.word===e.normal)return s.out;if(null!==o&&o===s.after)return[n].concat(s.out);if(null!==n&&n===s.before&&o&&o.length>2)return s.out.concat(o)}return null},Jt=(t,e,n,o,r)=>{((t,e)=>{if(!z.contractions||z.word&&z.word!==(t.normal||t.text).toLowerCase())return;z.rule=void 0;const n=e?"["+e.map(t=>v(`'${t}'`)).join(", ")+"]":"possessive (kept)";console.log(`${z.prefix||" "}${v(JSON.stringify(t.text))} → ${n}`)})(n[o][r],t);const s=e.fromText(t.join(" "));return s.compute(["id","alias"]),((t,e,n)=>{const[o,r]=e;n&&0!==n.length&&(n=n.map((t,e)=>(t.implicit=t.text,t.machine=t.text,t.pre="",t.post="",t.text="",t.normal="",t.index=[o,r+e],t)),n[0]&&(n[0].pre=t[o][r].pre,n[n.length-1].post=t[o][r].post,n[0].text=t[o][r].text,n[0].normal=t[o][r].normal),t[o].splice(r,1,...n))})(n,[o,r],t=s.docs[0]),t},Kt=(t,e)=>{for(let n=e+1;n<5&&t[n];n+=1)if("been"===t[n].normal)return["there","has"];return["there","is"]};var Xt={contractions:t=>{const{world:e,document:n}=t,{model:o,methods:r}=e,s=o.one.contractions||[];n.forEach((o,i)=>{const a=o.length;for(let a=o.length-1;a>=0;a-=1){if(o[a].implicit)continue;let c=null,l=null;if(It.test(o[a].normal)){const t=o[a].normal.split(It);c=t[0],l=t[1]}let u=Tt(o,a)||Zt(s,o[a],c,l);!u&&Object.hasOwn(Qt,l)&&(u=Qt[l](o,a,e)),!u&&Object.hasOwn(Ht,c)&&(u=Ht[c](o,a)),"there"===c&&"s"===l&&(u=Kt(o,a)),u?Jt(u,t,n,i,a):Gt.test(o[a].normal)?(u=Ut(o,a),u&&(u=Jt(u,t,n,i,a),r.one.setTag(u,"NumberRange",e),u[2]&&u[2].tags.has("Time")&&r.one.setTag([u[0]],"Time",e,null,"time-range"))):(u=Dt(o,a,e),u&&(u=Jt(u,t,n,i,a),r.one.setTag([u[1]],"Unit",e,null,"contraction-unit")))}o.length!==a&&(t=>{t.forEach((t,e)=>{t.index&&(t.index[1]=e)})})(o)})}};const Yt={model:Et,compute:Xt,hooks:["contractions"]},te=t=>{const e=t.world,{model:n,methods:o}=t.world,r=o.one.setTag,{frozenLex:s}=n.one,i=n.one._multiCache||{};B(t.docs,(t,n,o)=>{const a=t.machine||t.normal;if(void 0!==i[a]&&n[o+1])for(let t=o+i[a]-1;t>o;t-=1){const i=n.slice(o,t+1),a=i.map(t=>t.machine||t.normal).join(" ");Object.hasOwn(s,a)&&(r(i,s[a],e,!1,"1-frozen-multi-lexicon"),i.forEach(t=>t.frozen=!0))}void 0!==s[a]&&Object.hasOwn(s,a)&&(r([t],s[a],e,!1,"1-freeze-lexicon"),t.frozen=!0)})};var ee={compute:{frozen:te,freeze:te,unfreeze:t=>(B(t.docs,t=>{delete t.frozen}),t)},mutate:t=>{const e=t.methods.one;e.termMethods.isFrozen=t=>!0===t.frozen,e.debug.freeze=t=>e.debug.tags(t),e.debug.frozen=e.debug.freeze},api:function(t){t.prototype.freeze=function(){return B(this.docs,t=>{t.frozen=!0}),this},t.prototype.unfreeze=function(){this.compute("unfreeze")},t.prototype.isFrozen=function(){return this.match("@isFrozen+")}},hooks:["freeze"]};const ne=/^(under|over|mis|re|un|dis|semi|pre|post)-?/,oe=new Set(["Verb","Infinitive","PastTense","Gerund","PresentTense","Adjective","Participle"]);var re={lexicon:t=>{const e=t.world;B(t.docs,(t,n,o)=>{if(0===t.tags.size){let t=null;t||=((t,e,n)=>{const{model:o,methods:r}=n,s=r.one.setTag,i=o.one._multiCache||{},{lexicon:a}=o.one||{},c=t[e],l=c.machine||c.normal;if(void 0!==i[l]&&t[e+1]){for(let o=e+i[l]-1;o>e;o-=1){const r=t.slice(e,o+1);if(r.length<=1)return!1;const i=r.map(t=>t.machine||t.normal).join(" ");if(Object.hasOwn(a,i)){const t=a[i];if(t&&t.includes("PhrasalVerb")&&"-"===r[r.length-1].post)continue;return s(r,t,n,!1,"1-multi-lexicon"),!t||2!==t.length||"PhrasalVerb"!==t[0]&&"PhrasalVerb"!==t[1]||s([r[1]],"Particle",n,!1,"1-phrasal-particle"),!0}}return!1}return null})(n,o,e),t||=((t,e,n)=>{const{model:o,methods:r}=n,s=r.one.setTag,{lexicon:i}=o.one,a=t[e],c=a.machine||a.normal;if(void 0!==i[c]&&Object.hasOwn(i,c))return s([a],i[c],n,!1,"1-lexicon"),!0;if(a.machine&&Object.hasOwn(i,a.normal))return s([a],i[a.normal],n,!1,"1-lexicon-normal"),!0;if(a.alias){const t=a.alias.find(t=>Object.hasOwn(i,t));if(t)return s([a],i[t],n,!1,"1-lexicon-alias"),!0}if(ne.test(c)){const t=c.replace(ne,"");if(Object.hasOwn(i,t)&&t.length>3&&oe.has(i[t]))return s([a],i[t],n,!1,"1-lexicon-prefix"),!0}return null})(n,o,e)}})}},se={one:{expandLexicon:t=>{const e={},n={};return Object.keys(t).forEach(o=>{const r=t[o],s=(o=(o=o.toLowerCase().trim()).replace(/'s\b/,"")).split(/ /);s.length>1&&(void 0===n[s[0]]||s.length>n[s[0]])&&(n[s[0]]=s.length),e[o]||=r}),delete e[""],delete e.null,delete e[" "],{lex:e,_multi:n}}}},ie={addWords:function(t,e=!1){const n=this.world(),{methods:o,model:r}=n;if(!t)return;if(Object.entries(t).forEach(([e,n])=>{"string"==typeof n&&n.startsWith("#")&&(t[e]=n.replace(/^#/,""))}),!0===e){const{lex:e,_multi:s}=o.one.expandLexicon(t,n);return Object.assign(r.one._multiCache,s),void Object.assign(r.one.frozenLex,e)}if(o.two.expandLexicon){const{lex:e,_multi:s}=o.two.expandLexicon(t,n);Object.assign(r.one.lexicon,e),Object.assign(r.one._multiCache,s)}const{lex:s,_multi:i}=o.one.expandLexicon(t,n);Object.assign(r.one.lexicon,s),Object.assign(r.one._multiCache,i)}},ae={model:{one:{lexicon:{},_multiCache:{},frozenLex:{}}},methods:se,compute:re,lib:ie,hooks:["lexicon"]};const ce=(t,e)=>{const n=[{}],o=[null],r=[0],s=[];let i=0;t.forEach(t=>{let r=0;const s=((t,e)=>{const{methods:n,model:o}=e;return n.one.tokenize.splitTerms(t,o).map(t=>n.one.tokenize.splitWhitespace(t,o)).map(t=>t.text.toLowerCase())})(t,e);for(let t=0;t<s.length;t++){const e=s[t];n[r]&&Object.hasOwn(n[r],e)?r=n[r][e]:(i++,n[r][e]=i,n[i]={},r=i,o[i]=null)}o[r]=[s.length]});for(const t in n[0])i=n[0][t],r[i]=0,s.push(i);for(;s.length>0;){const t=s.shift(),e=Object.keys(n[t]);for(let a=0;a<e.length;a+=1){const c=e[a],l=n[t][c];for(s.push(l),i=r[t];i>0&&!Object.hasOwn(n[i],c);)i=r[i];if(Object.hasOwn(n,i)){const t=n[i][c];r[l]=t,o[t]&&(o[l]||=[],o[l]=o[l].concat(o[t]))}else r[l]=0}}return{goNext:n,endAs:o,failTo:r}},le=(t,e,n)=>{let o=0;const r=[];for(let s=0;s<t.length;s++){const i=t[s][n.form]||t[s].normal;for(;o>0&&(void 0===e.goNext[o]||!Object.hasOwn(e.goNext[o],i));)o=e.failTo[o]||0;if(Object.hasOwn(e.goNext[o],i)&&(o=e.goNext[o][i],e.endAs[o])){const n=e.endAs[o];for(let e=0;e<n.length;e++){const o=n[e],i=t[s-o+1],[a,c]=i.index;r.push([a,c,c+o,i.id])}}}return r},ue=(t,e)=>{for(let n=0;n<t.length;n+=1)if(e.has(t[n]))return!1;return!0},he=(t,e)=>{for(let n=t.length-1;n>=0;n-=1)if(t[n]!==e)return t.slice(0,n+1);return t},pe={buildTrie:function(t){return(e=ce(t,this.world())).goNext=e.goNext.map(t=>{if(0!==Object.keys(t).length)return t}),e.goNext=he(e.goNext,void 0),e.failTo=he(e.failTo,0),e.endAs=he(e.endAs,null),e;var e}};pe.compile=pe.buildTrie;var fe={api:function(t){t.prototype.lookup=function(t,e={}){if(!t)return this.none();"string"==typeof t&&(t=[t]);let n=((t,e,n)=>{let o=[];n.form||="normal";const r=t.docs;if(!e.goNext||!e.goNext[0])return console.error("Compromise invalid lookup trie"),t.none();const s=Object.keys(e.goNext[0]);for(let i=0;i<r.length;i++){if(t._cache&&t._cache[i]&&!0===ue(s,t._cache[i]))continue;const a=r[i],c=le(a,e,n);c.length>0&&(o=o.concat(c))}return t.update(o)})(this,_(t)?t:ce(t,this.world),e);return n=n.settle(),n}},lib:pe};const de=(t,e)=>e?(t.forEach(t=>{const n=t[0];e[n]&&(t[0]=e[n][0],t[1]+=e[n][1],t[2]+=e[n][1])}),t):t,me=(t,e,n)=>{const o=n.methods.one;return"number"==typeof t&&(t=String(t)),"string"==typeof t&&(t=o.killUnicode(t,n),t=o.parseMatch(t,e,n)),t},ge=t=>t&&_(t)&&!0===t.isView,we=t=>t&&_(t)&&!0===t.isNet,be={tagger:!1},ye=(t,e,n,o,r)=>(e=me(e,o,t.world),t.methods.one.match(t.docs,{regs:e,group:n,justOne:r},t._cache)),ve=(t,e)=>{const{ptrs:n,byGroup:o}=((t,e)=>{let{ptrs:n}=t;const{byGroup:o}=t;return n=de(n,e),Object.keys(o).forEach(t=>{o[t]=de(o[t],e)}),{ptrs:n,byGroup:o}})(e,t.fullPointer),r=t.toView(n);return r._groups=o,r},xe=t=>function(e,n,o){if(ge(e))return this.filter(n=>n.intersection(e).found===t);if(we(e)){const n=this.sweep(e,be).view.settle();return this.filter(e=>e.intersection(n).found===t)}const r={regs:e=me(e,o,this.world),group:n,justOne:!0},s=this._cache||[],i=this.filter((e,n)=>this.methods.one.match(e.docs,r,s[n]).ptrs.length>0===t);return this._cache&&(i._cache=i.ptrs.map(t=>s[t[0]])),i};var je={matchOne:function(t,e,n){return ge(t)?this.intersection(t).eq(0):we(t)?this.sweep(t,{tagger:!1,matchOne:!0}).view:ve(this,ye(this,t,e,n,!0))},match:function(t,e,n){return ge(t)?this.intersection(t):we(t)?this.sweep(t,be).view.settle():ve(this,ye(this,t,e,n))},has:function(t,e,n){return ge(t)?this.intersection(t).fullPointer.length>0:we(t)?this.sweep(t,be).view.found:ye(this,t,e,n,!0).ptrs.length>0},if:xe(!0),ifNo:xe(!1)};const Oe=(t,e,n,o,r)=>{const{indexN:s}=t.methods.one.pointer,{document:i}=t,a=e?-1:1,c=[],l=s(t.fullPointer);Object.keys(l).forEach(t=>{const[n,o,r]=l[t].sort((t,e)=>t[1]>e[1]?a:-a)[0];e?r<i[n].length&&c.push([n,r,i[n].length]):o>0&&c.push([n,0,o])});const u=t.toView(c);return n?u.match(n,o,r):u},ke=(t,e,n,o,r)=>{"string"==typeof n&&(n=t.world.methods.one.parseMatch(n,r,t.world)),e?n[0].start=!0:n[n.length-1].end=!0;const s=t.fullPointer;return t.forEach((t,r)=>{const i=e?t.after(n,o):t.before(n,o);if(i.found){const t=i.terms();e?(s[r][2]+=t.length,s[r][4]=null):(s[r][1]-=t.length,s[r][3]=t.docs[0][0].id)}}),t.update(s)},Ee=(t,e)=>function(n,o,r){return t(this,e,n,o,r)};var $e={before:Ee(Oe,!1),after:Ee(Oe,!0),growLeft:Ee(ke,!1),growRight:Ee(ke,!0),grow:function(t,e,n){return this.growRight(t,e,n).growLeft(t,e,n)}};const Se=(t,e)=>{if(t[0]!==e[0])return!1;const[,n,o]=t,[,r,s]=e;return n<=r&&o>r||r<=n&&s>n},Ae=t=>{const e={};return t.forEach(t=>{e[t[0]]||=[],e[t[0]].push(t)}),e},ze=(t,e,n)=>"string"==typeof t||Array.isArray(t)?e.match(t,n):t||e.none(),Pe=(t,e)=>[t[0],t[1],e[2]],Te=(t,e,n,o)=>{const{splitAll:r}=t.methods.one.pointer,s=ze(e,t,n).fullPointer,i=o(r(t.fullPointer,s)).filter(t=>t).map(e=>((t,e)=>{const[n,o,r]=t;return e.document[n]?.[o]&&(t[3]||=e.document[n][o].id,e.document[n][r-1]&&(t[4]||=e.document[n][r-1].id)),t})(e,t));return t.update(i)},_e={splitOn:function(t,e){return Te(this,t,e,t=>t.flatMap(t=>[t.passthrough,t.before,t.match,t.after]))},splitBefore:function(t,e){return Te(this,t,e,t=>{for(let e=0;e<t.length;e+=1)!t[e].after&&t[e+1]?.before&&t[e].match&&t[e].match[0]===t[e+1].before[0]&&(t[e].after=t[e+1].before,delete t[e+1].before);return t.flatMap(t=>t.match&&t.after?[t.passthrough,t.before,Pe(t.match,t.after)]:[t.passthrough,t.before,t.match])})},splitAfter:function(t,e){return Te(this,t,e,t=>t.flatMap(t=>t.before&&t.match?[t.passthrough,Pe(t.before,t.match),t.after]:[t.passthrough,t.before,t.match,t.after]))}};_e.split=_e.splitAfter;const Ce=(t,e)=>!(!t||!e)&&t[0]===e[0]&&t[2]===e[1],Le=(t,e,n)=>{const o=t.world,r=o.methods.one.parseMatch;e||=".$",n||="^.";const s=r(e,{},o),i=r(n,{},o);s[s.length-1].end=!0,i[0].start=!0;const a=t.fullPointer,c=[a[0]];for(let e=1;e<a.length;e+=1){const n=c[c.length-1],o=a[e],r=t.update([n]),l=t.update([o]);Ce(n,o)&&r.has(s)&&l.has(i)?c[c.length-1]=[n[0],n[1],o[2],n[3],o[4]]:c.push(o)}return t.update(c)},Ne={joinIf:function(t,e){return Le(this,t,e)},join:function(){return Le(this)}},Me={...je,...$e,..._e,...Ne};Me.lookBehind=Me.before,Me.lookBefore=Me.before,Me.lookAhead=Me.after,Me.lookAfter=Me.after,Me.notIf=Me.ifNo;const qe=new Set("!~[^"),Fe=new Set("?]+*$~{},0123456789"),We=/\s/,Be=new Set("![^"),Ve=new Set("?]+*$~"),Ue=new Set("\n\r\u2028\u2029"),Re=/\s/,De=/\s+/,Ie=t=>/^[![^]*(<[^<]*>)?\//.test(t)&&/\/[?\]+*$~]*$/.test(t),Ge=()=>!1,Qe=t=>(t=t.map(t=>t.trim())).filter(t=>t),He=/\{([0-9]+)?(, *[0-9]*)?\}/,Ze=/&&/,Je=/^<\s*([^\s>]+)\s*>/,Ke=t=>t.charAt(0).toUpperCase()+t.substring(1),Xe=t=>t.charAt(t.length-1),Ye=t=>t.charAt(0),tn=t=>t.substring(1),en=t=>t.substring(0,t.length-1),nn=t=>(t=tn(t),en(t)),on=(t,e,n=e)=>Ye(t)===e&&Xe(t)===n,rn=(t,e,n)=>{const o={};for(let r=0;r<2;r+=1){if("$"===Xe(t)&&(o.end=!0,t=en(t)),"^"===Ye(t)&&(o.start=!0,t=tn(t)),"?"===Xe(t)&&(o.optional=!0,t=en(t)),("["===Ye(t)||"]"===Xe(t))&&(o.group=null,"["===Ye(t)&&(o.groupStart=!0),"]"===Xe(t)&&(o.groupEnd=!0),t=(t=t.replace(/^\[/,"")).replace(/\]$/,""),"<"===Ye(t))){const e=Je.exec(t);if(!e)throw new SyntaxError("Invalid named capture: expected [<name> ...]");e.length>=2&&(o.group=e[1],t=t.replace(e[0],""))}if("+"!==Xe(t)||t.endsWith("\\+")||(o.greedy=!0,t=en(t)),"*"===t||"*"!==Xe(t)||t.endsWith("\\*")||(o.greedy=!0,o.optional=!0,t=en(t)),"!"===Ye(t)&&(o.negative=!0,t=tn(t)),on(t,"~")&&t.length>2&&(t=nn(t),o.fuzzy=!0,o.min=e.fuzzy??.85,!/\(/.test(t)))return o.word=t,o;if(on(t,"/")&&t.length>2&&!e.noRegex)return t=nn(t),e.caseSensitive&&(o.use="text"),o.regex=new RegExp(t),o;if(He.test(t)&&(t=t.replace(He,(t,e,n)=>(void 0===n?(o.min=Number(e),o.max=Number(e)):(n=n.replace(/, */,""),void 0===e?(o.min=0,o.max=Number(n)):(o.min=Number(e),o.max=Number(n||999))),o.greedy=!0,o.min||(o.optional=!0),""))),on(t,"(",")")){Ze.test(t)?(o.choices=t.split(Ze),o.operator="and"):(o.choices=t.split("|"),o.operator="or"),o.choices[0]=tn(o.choices[0]);const r=o.choices.length-1;o.choices[r]=en(o.choices[r]),o.choices=o.choices.map(t=>t.trim()),o.choices=o.choices.filter(t=>t),o.choices=o.choices.map(t=>t.split(/\s+/).map(t=>rn(t,e,n))),t=""}if(on(t,"{","}")){if(t=nn(t),o.root=t,/\//.test(t)){const t=o.root.split(/\//);o.root=t[0],o.pos=t[1],"adj"===o.pos&&(o.pos="Adjective"),o.pos=o.pos.charAt(0).toUpperCase()+o.pos.substr(1).toLowerCase(),void 0!==t[2]&&(o.sense=t[2])}return o}if(on(t,"<",">"))return t=nn(t),o.chunk=Ke(t),o.greedy=!0,o;if(on(t,"%"))return t=nn(t),o.switch=t,o}if("#"===Ye(t)){const e=tn(t);return o.tag=n?.[e],o.tag||(o.tag=Ke(e),o.tag=n?.[o.tag]||o.tag),o}return"@"===Ye(t)?(o.method=tn(t),o):"."===t?(o.anything=!0,o):"*"===t?(o.anything=!0,o.greedy=!0,o.optional=!0,o):(t&&(t=(t=(t=(t=t.replace("\\*","*")).replace("\\.",".")).replace("\\+","+")).replace("\\/","/"),e.caseSensitive?o.use="text":t=t.toLowerCase(),o.word=t),o)},sn=/^[\w.!#$%&'*+/=?^`{|}~-]+@(?:[\w-]+\.)+[a-z]{2,}$/i,an=/^(?:https?:(?:\/\/)?|www\.)(?:[a-z0-9-]+\.)+[a-z]{2,}(?::[0-9]+)?(?:[/?#]\S*)?$/i,cn=/^(?:[a-z0-9-]+\.)+(?:com|net|gov|org|ly|edu|info|biz|dev|ru|jp|de|in|uk|br|io|ai)(?::[0-9]+)?(?:[/?#]\S*)?$/i,ln=(t,e)=>{const n=t.split(/[-–—]/);if(n.length<=1)return!1;if((t=>{if(!t.includes("."))return!1;let e=0,n=t.length;for(;e<n&&/[\s("'“‘<]/.test(t[e]);)e++;for(;n>e&&/[\s).,!?:;"'”’>]/.test(t[n-1]);)n--;const o=t.slice(e,n);return sn.test(o)||an.test(o)||cn.test(o)})(t))return!1;const{prefixes:o,suffixes:r}=e.one;return(1!==n[0].length||!/[a-z]/i.test(n[0]))&&(!Object.hasOwn(o,n[0])&&(n[1]=n[1].trim().replace(/[.?!]$/,""),!Object.hasOwn(r,n[1])&&(!!/^([a-z\u00C0-\u00FF`"'/]+)[-–—]([a-z0-9\u00C0-\u00FF].*)/i.test(t)||!!/^[('"]?([0-9]{1,4})[-–—]([a-z\u00C0-\u00FF`"'/-]+[)'"]?$)/i.test(t))))},un=t=>{const e=[],n=t.split(/[-–—]/);let o="-";const r=t.match(/[-–—]/);r&&r[0]&&(o=r);for(let t=0;t<n.length;t++)t===n.length-1?e.push(n[t]):e.push(n[t]+o);return e},hn=(t,e,n,o)=>{const{all:r}=e.methods.two.transform[n]||{};return r?r(t.root,e.model):o},pn={Verb:"verb",Noun:"noun",Adjective:"adjective"},fn=(t,e)=>{for(const n of e)if(t.has(n))return!0;return!1},dn=(t,e)=>{for(let n=0;n<t.length;n+=1){const o=t[n];if(!0!==o.optional&&!0!==o.negative&&!0!==o.fuzzy){if(void 0!==o.word&&!e.has(o.word))return!0;if(void 0!==o.tag&&!e.has("#"+o.tag))return!0;if(void 0!==o.fastOr&&!fn(o.fastOr,e))return!0}}return!1},mn=/([\u0022\uFF02\u0027\u201C\u2018\u201F\u201B\u201E\u2E42\u201A\u00AB\u2039\u2035\u2036\u2037\u301D\u0060\u301F])/,gn=/([\u0022\uFF02\u0027\u201D\u2019\u00BB\u203A\u2032\u2033\u2034\u301E\u00B4])/,wn=/^[-–—]$/,bn=/ [-–—]{1,3} /,yn=(t,e)=>-1!==t.post.indexOf(e),vn={hasQuote:t=>mn.test(t.pre)||gn.test(t.post),hasComma:t=>yn(t,","),hasPeriod:t=>!0===yn(t,".")&&!1===yn(t,"..."),hasExclamation:t=>yn(t,"!"),hasQuestionMark:t=>yn(t,"?")||yn(t,"¿"),hasEllipses:t=>yn(t,"..")||yn(t,"…"),hasSemicolon:t=>yn(t,";"),hasColon:t=>yn(t,":"),hasSlash:t=>/\//.test(t.text),hasHyphen:t=>wn.test(t.post)||wn.test(t.pre),hasDash:t=>bn.test(t.post)||bn.test(t.pre),hasContraction:t=>Boolean(t.implicit),isAcronym:t=>t.tags.has("Acronym"),isKnown:t=>t.tags.size>0,isTitleCase:t=>/^['\u2019]?\p{Lu}[a-z'\u00C0-\u00FF]/u.test(t.text),isUpperCase:t=>/^\p{Lu}+$/u.test(t.text)};vn.hasQuotation=vn.hasQuote;let xn=()=>{};xn=(t,e,n,o)=>{const r=((t,e,n,o)=>{if(!0===e.anything)return!0;if(!0===e.start&&0!==n)return!1;if(!0===e.end&&n!==o-1)return!1;if(void 0!==e.id&&e.id===t.id)return!0;if(void 0!==e.word){if(e.use)return e.word===t[e.use];if(null!==t.machine&&t.machine===e.word)return!0;if(!0===e.fuzzy){if(e.word===t.root)return!0;const n=((t,e,n=3)=>{if(t===e)return 1;if(t.length<n||e.length<n)return 0;const o=((t,e)=>{const n=t.length,o=e.length;if(0===n)return o;if(0===o)return n;const r=(o>n?o:n)+1;if(Math.abs(n-o)>(r||100))return r||100;const s=[];for(let t=0;t<r;t++)s[t]=[t],s[t].length=r;for(let t=0;t<r;t++)s[0][t]=t;let i,a,c,l,u,h;for(let r=1;r<=n;++r)for(a=t[r-1],i=1;i<=o;++i){if(r===i&&s[r][i]>4)return n;c=e[i-1],l=a===c?0:1,u=s[r-1][i]+1,(h=s[r][i-1]+1)<u&&(u=h),(h=s[r-1][i-1]+l)<u&&(u=h);const o=r>1&&i>1&&a===e[i-2]&&t[r-2]===c&&(h=s[r-2][i-2]+l)<u;s[r][i]=o?h:u}return s[n][o]})(t,e),r=Math.max(t.length,e.length);return 1-(0===r?0:o/r)})(e.word,t.normal);if(n>=e.min)return!0}return!(!t.alias||!t.alias.some(t=>t===e.word))||e.word===t.text||e.word===t.normal}if(void 0!==e.tag)return t.tags.has(e.tag);if(void 0!==e.method)return"function"==typeof vn[e.method]&&!0===vn[e.method](t);if(void 0!==e.pre)return t.pre&&t.pre.includes(e.pre);if(void 0!==e.post)return t.post&&t.post.includes(e.post);if(void 0!==e.regex){let n=t.normal;if(e.use&&(n=t[e.use]),e.regex.global||e.regex.sticky){const t=e.regex.lastIndex;try{return e.regex.lastIndex=0,e.regex.test(n)}finally{e.regex.lastIndex=t}}return e.regex.test(n)}if(void 0!==e.chunk)return t.chunk===e.chunk;if(void 0!==e.switch)return t.switch===e.switch;if(void 0!==e.machine)return t.normal===e.machine||t.machine===e.machine||t.root===e.machine;if(void 0!==e.sense)return t.sense===e.sense;if(void 0!==e.fastOr){if(e.pos&&!t.tags.has(e.pos))return null;const n=t.root||t.implicit||t.machine||t.normal;return e.fastOr.has(n)||e.fastOr.has(t.text)}return void 0!==e.choices&&("and"===e.operator?e.choices.every(e=>xn(t,e[0],n,o)):e.choices.some(e=>xn(t,e[0],n,o)))})(t,e,n,o);return!0===e.negative?!r:r};const jn=(t,e)=>(t.groups||(t.groups={}),t.groups[t.inGroup]||(t.groups[t.inGroup]={start:e,length:0}),t.groups[t.inGroup]),On=(t,e)=>{!0===t.hasGroup&&t.t>e&&(jn(t,e).length+=t.t-e)},kn=(t,e,n)=>xn(t.terms[n],e,t.start_i+n,t.phrase_length),En=t=>({...t,start:!1,end:!1}),$n=t=>t.filter(t=>!0!==t.optional&&!0!==t.negative).length,Sn=t=>{const{regs:e}=t,n=e[t.r],o=((t,e)=>{let n=t.t;if(!e)return t.terms.length;for(;n<t.terms.length;n+=1)if(!0===kn(t,e,n))return n;return null})(t,e[t.r+1]);return null===o||o===t.offset||void 0!==n.min&&o-t.t<n.min?null:void 0!==n.max&&o-t.t>n.max?(t.t=t.t+n.max,!0):(!0===t.hasGroup&&(jn(t,t.t).length+=o-t.t),t.t=o,!0)},An=(t,e,n)=>{let o=0;for(let r=0;r<e.length;r+=1){const s=e[r],i=t.t+n+o;if(void 0===t.terms[i])return 0;if(!0!==kn(t,s,i))return 0;if(o+=1,!0===s.greedy){const e=En(s);for(let n=i+1;n<t.terms.length&&!0===kn(t,e,n);n+=1)o+=1}}return o},zn=(t,e)=>{const n=t.regs[t.r];for(let o=0;o<n.choices.length;o+=1){const r=n.choices[o];if(!Array.isArray(r))return 0;const s=An(t,r,e);if(s>0)return s}return 0},Pn=(t,e)=>{let n=0;return!0===t.regs[t.r].choices.every(o=>{const r=o.every((n,o)=>{const r=t.t+e+o;return void 0!==t.terms[r]&&kn(t,n,r)});return!0===r&&o.length>n&&(n=o.length),r})?n:0},Tn=(t,e)=>{const n=t.regs[t.r];let o=e(t,0);if(0===o||!0!==n.greedy)return o;const r=t.regs[t.r+1];let s=1;for(;s!==n.max;){const i=t.t+o,a=t.terms[i],c=void 0===n.min||s>=n.min;if(!a||r&&c&&kn(t,r,i))break;const l=e(t,o);if(0===l)break;o+=l,s+=1}return void 0!==n.min&&s<n.min?0:o},_n=t=>{const e=t.regs[t.r+1];return!(!e||!kn(t,e,t.t))&&(!t.terms[t.t+1]||!kn(t,e,t.t+1))},Cn=(t,e,n)=>{let o=0;for(let r=t.t;r<t.terms.length;r+=1){let s=kn(t,e,r);if(s)break;if(n&&(s=kn(t,n,r),s))break;if(o+=1,void 0!==e.max&&o===e.max)break}return 0===o?!0===e.optional:!(e.min&&e.min>o||(t.t+=o,0))},Ln=t=>e=>{const{regs:n}=e,o=n[e.r],r=t(e);if(r){if(!0===o.negative)return!0===o.optional&&!0===o.greedy;if(!0===o.optional&&_n(e))return!0;if(!0===e.hasGroup&&(jn(e,e.t).length+=r),!0===o.end){const t=e.phrase_length;if(e.t+e.start_i+r!==t)return null}return e.t+=r,!0}return!0===o.negative?(t=>{const e=t.regs[t.r],n=t.t;let o=!0;return!0===e.greedy?o=Cn(t,En({...e,negative:!1}),t.regs[t.r+1]):e.optional||(t.t+=1),On(t,n),o})(e):!!o.optional||null};var Nn=Ln(t=>Tn(t,zn)),Mn=Ln(t=>Tn(t,Pn));const qn=t=>{const{regs:e}=t,n=e[t.r],o=t.t,r={...n};if(r.negative=!1,kn(t,r,t.t))return!0===n.optional&&!0===n.greedy;if(n.greedy){const n=Cn(t,En(r),e[t.r+1]);return On(t,o),n}if(n.optional){const n=e[t.r+1];if(n){if(kn(t,n,t.t))return!0;if(n.optional&&e[t.r+2]&&kn(t,e[t.r+2],t.t))return!0}}return t.t+=1,On(t,o),!0},Fn=t=>{const{regs:e}=t,n=e[t.r],o=t.terms[t.t],r=t.t;if(n.optional&&e[t.r+1]&&n.negative)return!0;if(n.optional&&_n(t))return!0;if(o.implicit&&t.terms[t.t+1]&&(t=>{const e=t.terms[t.t],n=t.regs[t.r];if(e.implicit&&t.terms[t.t+1]?.implicit&&(n.word===e.normal||"hasContraction"===n.method)){let e=t.terms[t.t+1];for(;e&&e.implicit&&""===e.text;)t.t+=1,e=t.terms[t.t+1]}})(t),t.t+=1,!0===n.end&&t.t!==t.terms.length&&!0!==n.greedy)return null;if(!0===n.greedy){const e=(t=>{const{regs:e,phrase_length:n}=t,o=e[t.r];return t.t=((t,e)=>{const n=En(t.regs[t.r]),o=t.t;for(;t.t<t.terms.length;t.t+=1){const r=t.t-o+1;if(e&&kn(t,e,t.t)&&(void 0===n.min||r>=n.min))return t.t;if(void 0!==n.max&&r===n.max)return t.t;if(!1===kn(t,n,t.t))return void 0!==n.min&&r<n.min?null:t.t}return void 0!==n.min&&t.t-o+1<n.min?null:t.t})(t,e[t.r+1]),null===t.t?null:!0!==o.end||t.start_i+t.t===n||null})(t);if(!e)return null}return!0===t.hasGroup&&((t,e)=>{const n=t.regs[t.r],o=jn(t,e);t.t-t.offset>1&&n.greedy?o.length+=t.t-e:o.length++})(t,r),!0},Wn=(t,e)=>!0===t.anything&&!0===t.greedy?Sn:void 0!==t.choices&&"or"===t.operator?Nn:void 0!==t.choices&&"and"===t.operator?Mn:!0===t.anything?t.negative?null:Fn:!0===((t,e)=>{if(!0===t.end&&!0===t.greedy&&e.start_i+e.t<e.phrase_length-1){const n={...t,end:!1};if(!0===kn(e,n,e.t))return!0}return!1})(t,e)?Fn:t.negative?qn:!0===kn(e,t,e.t)?Fn:!0!==t.optional?null:void 0,Bn=(t,e,n,o,r=0)=>{if(r>=t.length||0===e.length)return null;const s=n-r,i={t:r,offset:r,terms:t,r:0,regs:e,groups:null,start_i:s,phrase_length:o,inGroup:null};for(;i.r<e.length;i.r+=1){const t=e[i.r];if(i.hasGroup=Boolean(t.group),i.inGroup=i.hasGroup?t.group:null,!i.terms[i.t]){if(!1===e.slice(i.r).some(t=>!t.optional))break;return null}const n=Wn(t,i);if(null===n)return null;if(n&&!n(i))return null}const a=[null,n,i.t+s];if(a[1]===a[2])return null;const c={};return i.groups&&Object.keys(i.groups).forEach(t=>{const e=i.groups[t],n=s+e.start;c[t]=[null,n,n+e.length]}),{pointer:a,groups:c}},Vn=t=>t.every(t=>!(t.optional||t.greedy||t.negative||t.choices||t.anything||void 0===t.word&&void 0===t.tag&&void 0===t.switch&&void 0===t.fastOr)),Un=(t,e,n,o,r=0)=>{if(r+e.length>t.length)return null;for(let s=0;s<e.length;s+=1){const i=t[r+s];if(i.implicit)return Bn(t,e,n,o,r);if(!0!==xn(i,e[s],n+s,o))return null}const s={};for(let t=0;t<e.length;t+=1){const o=e[t].group;o&&(s[o]||(s[o]=[null,n+t,n+t]),s[o][2]+=1)}return{pointer:[null,n,n+e.length],groups:s}},Rn=(t,e)=>(t.pointer[0]=e,Object.keys(t.groups).forEach(n=>{t.groups[n][0]=e}),t),Dn=(t,e,n,o)=>{let r=o(t,e,0,t.length);return r?(r=Rn(r,n),r):null},In={one:{termMethods:vn,parseMatch:(t,e,n)=>{if(null==t||""===t)return[];e||={},"number"==typeof t&&(t=String(t));let o=((t,e={})=>{const n=e.noRegex?Ge:Ie,o=e.noRegex?[t]:(t=>{if(!t.includes("/"))return[t];const e=t.length,n=new Uint32Array(e+1),o=new Uint32Array(e);n[e]=e;let r=0,s=0;for(let i=e-1;i>=0;i--){if("/"===t[i]&&(o[i]=r),n[i]=Ve.has(t[i])?n[i+1]:i,Ue.has(t[i])&&(r=0),"/"===t[i+1]&&"/"!==t[i]&&"\\"!==t[i]){const o=n[i+2];(o===e||Re.test(t[o]))&&(r=o)}"<"===t[i]?(o[i]=s,s=0):">"!==t[i]||s||"/"!==t[i+1]||(s=o[i+1])}const i=[];let a=0;for(let n=-1;n<e;n++)if(-1===n||Re.test(t[n])){let e=n+1;for(;Be.has(t[e]);)e++;const r=o[e];r&&(i.push(t.slice(a,Math.max(n,0)),t.slice(n+1,r)),a=r+1,n=r-1)}return i.push(t.slice(a)),i})(t);let r=[];o.forEach(t=>{n(t)?r.push(t):r=r.concat((t=>{if(!t.includes("(")||!t.includes(")"))return[t];const e=t.length,n=new Uint32Array(e+1),o=new Uint32Array(e),r=new Uint32Array(e);n[e]=e;let s=-1,i=0;for(let a=e-1;a>=0;a--){if(n[a]=Fe.has(t[a])?n[a+1]:a,")"===t[a]&&(s=a),"("===t[a]&&s>=a+3&&"\\"!==t[s-1]){const r=n[s+1];(r===e||We.test(t[r]))&&(o[a]=r)}"<"===t[a]?(r[a]=i,i=0):">"!==t[a]||i||(i=o["!"===t[a+1]?a+2:a+1]||0)}const a=[];let c=0,l=0;for(;l<e;){const n=l;for(;l<e&&qe.has(t[l]);)l++;const s="<"===t[l]?r[l]:o[l];s?(a.push(t.slice(c,n),t.slice(n,s)),l=s<e?s+1:s,c=l):l===n&&l++}return a.push(t.slice(c)),a})(t))}),r=Qe(r);const s=r.flatMap(t=>(t=>/^[![^]*(<[^<]*>)?!?\(/.test(t)&&/\)[?\]+*$~{},0-9]*$/.test(t))(t)||n(t)?t:t.split(De));return Qe(s)})(t,e);var r;return o=o.map(t=>rn(t,e,n.model.one.tagAliases)),o=((t,e)=>{for(let n=t.length-1;n>=0;n-=1){const o=t[n];if(o.word&&ln(o.word,e.model)){let e=o.word.split(/[-–—]/g);e=e.filter(t=>t).reverse(),t.splice(n,1),e.forEach(e=>{const r={...o};r.word=e,t.splice(n,0,r)})}}return t})(o,n),o=((t,e)=>t.map(t=>{if(t.root)if(e.methods.two&&e.methods.two.transform){let n=[];if(t.pos){if(Object.hasOwn(pn,t.pos)){const o=pn[t.pos];n=hn(t,e,o,"verb"===o?[]:[t.root])}}else n=[...hn(t,e,"verb",[]),...hn(t,e,"noun",[t.root]),...hn(t,e,"adjective",[t.root])];n=n.filter(t=>t),n.length>0&&(t.operator="or",t.fastOr=new Set(n))}else t.machine=t.root,delete t.id,delete t.root;return t}))(o,n),r=(t=>{let e=0,n=null;for(let o=0;o<t.length;o++){const r=t[o];!0===r.groupStart&&(n=r.group,null===n&&(n=String(e),e+=1)),null!==n&&(r.group=n),!0===r.groupEnd&&(n=null)}return t})(r=o),o=(t=>t.map(t=>(t.fuzzy&&t.choices&&t.choices.forEach(e=>{1===e.length&&e[0].word&&(e[0].fuzzy=!0,e[0].min=t.min)}),t)))(r=r.map(t=>{if(void 0!==t.choices){if("or"!==t.operator)return t;if(!0===t.fuzzy)return t;!0===t.choices.every(t=>{if(1!==t.length)return!1;const e=t[0];return!0!==e.fuzzy&&!e.start&&!e.end&&void 0!==e.word&&!0!==e.negative&&!0!==e.optional&&!0!==e.method})&&(t.fastOr=new Set,t.choices.forEach(e=>{t.fastOr.add(e[0].word)}),delete t.choices)}return t})),o},match:(t,e,n)=>{n||=[];const{regs:o,group:r,justOne:s,checkFirst:i}=e;let a=[];if(!o||0===o.length)return{ptrs:[],byGroup:{}};const c=e.fixed??Vn(o)?Un:Bn;let l=e.minLength;void 0===l&&(l=$n(o));t:for(let e=0;e<t.length;e+=1){const r=t[e];if(!n[e]||!dn(o,n[e])){if(!0===o[0].start){const t=Dn(r,o,e,c);t&&a.push(t);continue}for(let t=0;t<r.length&&!(r.length-t<l);t+=1){if(i&&!xn(r[t],o[0],t,r.length))continue;let n=c(r,o,t,r.length,t);if(n){if(n=Rn(n,e),a.push(n),!0===s)break t;const o=n.pointer[2];Math.abs(o-1)>t&&(t=Math.abs(o-1))}}}}return!0===o[o.length-1].end&&(a=a.filter(e=>{const n=e.pointer[0];return t[n].length===e.pointer[2]})),e.notIf&&(a=((t,e,n)=>t.filter(t=>{const[o,r,s]=t.pointer,i=n[o].slice(r,s);return!i.some((t,n)=>null!==Bn(i,e,n,i.length,n))}))(a,e.notIf,t)),a=((t,e)=>{const n=[],o={};return"number"==typeof e&&(e=String(e)),e?t.forEach(t=>{t.groups[e]&&n.push(t.groups[e])}):t.forEach(t=>{n.push(t.pointer),Object.entries(t.groups).forEach(([t,e])=>{o[t]||=[],o[t].push(e)})}),{ptrs:n,byGroup:o}})(a,r),a.ptrs.forEach(e=>{const[n,o,r]=e;e[3]=t[n][o].id,e[4]=t[n][r-1].id}),a}}};var Gn={api:t=>{Object.assign(t.prototype,Me)},methods:In,lib:{parseMatch:function(t,e){const n=this.world(),o=n.methods.one.killUnicode;return o&&(t=o(t,n)),n.methods.one.parseMatch(t,e,n)}}};const Qn=/^\../,Hn=/^#./,Zn={"&":"&","<":"<",">":">",'"':""","'":"'"};var Jn={html:function(t){const{starts:e,ends:n}=((t,e)=>{const n={},o={};return Object.keys(e).forEach(r=>{let s=e[r];const i=(t=>{let e="",n="</span>";return t=t.replace(/[&<>"']/g,t=>Zn[t]),Qn.test(t)?e=`<span class="${t.replace(/^\./,"")}"`:Hn.test(t)?e=`<span id="${t.replace(/^#/,"")}"`:(e=`<${t}`,n=`</${t}>`),e+=">",{start:e,end:n}})(r);"string"==typeof s&&(s=t.match(s)),s.docs.forEach(t=>{if(t.every(t=>t.implicit))return;const e=t[0].id;n[e]||=[],n[e].push(i.start);const r=t.at(-1).id;o[r]||=[],o[r].push(i.end)})}),{starts:n,ends:o}})(this,t);let o="";return B(this.docs,t=>{Object.hasOwn(e,t.id)&&(o+=e[t.id].join("")),o+=t.pre||"",o+=t.text||"",Object.hasOwn(n,t.id)&&(o+=n[t.id].join("")),o+=t.post||""}),o}};const Kn=/[,:;)\]*.?~!\u0022\uFF02\u201D\u2019\u00BB\u203A\u2032\u2033\u2034\u301E\u00B4—-]/,Xn=t=>{let e=t.length;for(;e>0&&Kn.test(t[e-1]);)e--;return t.slice(0,e)},Yn=/^[(['"*~\uFF02\u201C\u2018\u201F\u201B\u201E\u2E42\u201A\u00AB\u2039\u2035\u2036\u2037\u301D\u0060\u301F]+/,to=/[,:;)('"\uFF02\u201D\u2019\u00BB\u203A\u2032\u2033\u2034\u301E\u00B4\]]/,eo=/^[-–—]$/,no=/ /,oo=t=>t.reduce((t,e)=>t+e.pre+e.text+e.post,"").trim(),ro=(t,e,n=!0)=>{let o="";return t.forEach((n,r)=>{let s=n.pre||"",i=n.post||"";"some"===e.punctuation&&(s=s.replace(/[,،]/g,""),s=s.replace(Yn,""),eo.test(i)&&(i=" "),i=i.replace(to,""),i=i.replace(/\?!+/,"?"),i=i.replace(/!+/,"!"),i=i.replace(/\?+/,"?"),i=i.replace(/[,،…]|\.{2,}/g,""),n.tags.has("Abbreviation")&&(i=i.replace(/\./,""))),"some"===e.whitespace&&(s=s.replace(/\s/,""),i=i.replace(/\s+/," ")),e.keepPunct||(s=s.replace(Yn,""),i="-"===i?" ":Xn(i));let a=n[e.form||"text"]||n.normal||"";"implicit"===e.form&&(a=n.implicit||n.text),"root"===e.form&&n.implicit&&(a=n.root||n.implicit||n.normal),("machine"===e.form||"implicit"===e.form||"root"===e.form)&&n.implicit&&r<t.length-1&&(i&&no.test(i)||(i+=" ")),o+=s+a+i}),!1===n&&(o=o.trim()),!0===e.lowerCase&&(o=o.toLowerCase()),o},so={whitespace:"some",punctuation:"some",unicode:"some"},io={text:{form:"text"},normal:{...so,case:"some",form:"normal"},machine:{...so,keepSpace:!1,case:"none",form:"machine"},root:{...so,keepSpace:!1,case:"some",form:"root"},implicit:{form:"implicit"}};io.clean=io.normal,io.reduced=io.root;const ao=[];let co=0;for(;co<64;co++)ao[co]=0|4294967296*Math.sin((co+1)%Math.PI);const lo=t=>{let e,n,o,r=decodeURI(encodeURI(t))+"",s=r.length;const i=[e=1732584193,n=4023233417,~e,~n],a=[];for(t=--s/4+2|15,a[--t]=8*s;~s;)a[s>>2]|=r.charCodeAt(s)<<8*s--;for(co=r=0;co<t;co+=16){for(s=i;r<64;s=[o=s[3],e+((o=s[0]+[e&n|~e&o,o&e|~o&n,e^n^o,n^(e|~o)][s=r>>4]+ao[r]+~~a[co|15&[r,5*r+1,3*r+5,7*r][s]])<<(s=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*s+r++%4])|o>>>-s),e,n])e=0|s[1],n=s[2];for(r=4;r;)i[--r]+=s[r]}for(t="";r<32;)t+=(i[r>>3]>>4*(1^r++)&15).toString(16);return t},uo={text:!0,terms:!0},ho={case:"none",unicode:"some",form:"machine",punctuation:"some"},po=(t,e)=>ro(t,{...e,keepPunct:!0},!1),fo={text:t=>po(t),normal:t=>po(t,io.normal),implicit:t=>po(t,io.implicit),machine:t=>ro(t,ho,!1),root:t=>ro(t,{...ho,form:"root"},!1),hash:t=>lo(po(t)),offset:t=>{const e=fo.text(t).length,n=t[0].pre+t[0].text,o=t[0].pre.length-(n.length-n.trimStart().length);return{index:t[0].offset.index,start:t[0].offset.start-o,length:e}},terms:t=>t.map(t=>({...t,tags:[...t.tags]})),confidence:(t,e,n)=>e.eq(n).confidence(),syllables:(t,e,n)=>e.eq(n).syllables(),sentence:(t,e,n)=>e.eq(n).fullSentence().text(),dirty:t=>t.some(t=>!0===t.dirty)};fo.sentences=fo.sentence,fo.clean=fo.normal,fo.reduced=fo.root;const mo={json:function(t){const e=(n=this,o=t,o||={},"string"==typeof o&&(o={}),(o={...uo,...o}).offset&&n.compute("offset"),n.docs.map((t,e)=>{const r={};return Object.keys(o).forEach(s=>{o[s]&&fo[s]&&(r[s]=fo[s](t,n,e))}),r}));var n,o;return"number"==typeof t?e[t]:e}};mo.data=mo.json;const go=t=>{const e=t.pre||"",n=t.post||"";return e+t.text+n},wo=(t,e)=>{const n=((t,e)=>{const n={};return Object.keys(e).forEach(o=>{t.match(o).fullPointer.forEach(t=>{n[t[3]]={fn:e[o],end:t[2]}})}),n})(t,e);let o="";return t.docs.forEach((e,r)=>{for(let s=0;s<e.length;s+=1){const i=e[s];if(Object.hasOwn(n,i.id)){const{fn:a,end:c}=n[i.id],l=t.update([[r,s,c]]);o+=e[s].pre||"",o+=a(l),s=c-1,o+=e[s].post||""}else o+=go(i)}}),o},bo=new Set(["Hyphenated","Prefix","SlashedTerm"]),yo=(t,e)=>{const n=e[t];if(!n||!n.parents||0===n.parents.length)return t;for(let t=0;t<n.parents.length;t+=1){const o=n.parents[t];if(e[o]&&(!e[o].parents||0===e[o].parents.length))return o}return n.parents.at(-1)},vo={text:t=>t.text(),normal:t=>t.text("normal"),root:t=>t.text("root"),machine:t=>t.text("machine"),hash:t=>lo(t.text()),spec:t=>((t,e)=>{const n=e.model.one.tagSet,o=((t,e)=>{const n=Object.create(null);for(const o in t){const r=t[o],s=void 0===r.aliases?r.alias:r.aliases[0];s&&e[s]===o&&(n[o]=s)}return n})(n,e.model.one.tagAliases);return t.docs.map(t=>{const e=oo(t),r=t.map(t=>{const e=((t,e)=>{const n=Array.from(t.tags||[]);if(0===n.length)return"-";const o=n.find(t=>!bo.has(yo(t,e)))||n[0];return yo(o,e)})(t,n);return o[e]||e}).join(",");return`${e} {${r}}`}).join("\n")})(t,t.world),json:t=>t.json(),offset:t=>(t.compute("offset"),t.json({offset:!0})),array:t=>t.docs.map(oo).filter(t=>t),freq:t=>(t=>{const e=new Map;t.forEach(t=>{e.set(t,(e.get(t)??0)+1)});const n=Array.from(e,([t,e])=>({normal:t,count:e}));return n.sort((t,e)=>e.count-t.count)})(t.json({normal:!0}).map(t=>t.normal)),terms:t=>t.docs.flatMap(t=>t.map(t=>t.text).filter(Boolean)),tags:t=>t.docs.map(t=>t.reduce((t,e)=>(t[e.implicit||e.normal]=Array.from(e.tags),t),{})),"best-tag":t=>(t.compute("tagRank"),t.docs.map(t=>t.map(t=>t.tagRank?.[0]?`#${t.tagRank[0]}`:"").join(" ")).join("\n")),debug:t=>t.debug()};vo.reduced=vo.machine,vo.md5=vo.hash,vo.offsets=vo.offset,vo.frequency=vo.freq,vo.topk=vo.freq;const xo=/^\s+[-—]\s+$/;var jo={text:function(t){let e={};if(t&&"string"==typeof t&&Object.hasOwn(io,t)?e={...io[t]}:t&&_(t)&&(e={...t}),void 0!==e.keepSpace||this.isFull()||(e.keepSpace=!1),void 0===e.keepEndPunct&&this.pointer){const t=this.pointer[0],n=this.docs.at(-1)?.at(-1);t?.[1]||xo.test(n?.post)?e.keepEndPunct=!1:e.keepEndPunct=!0}return void 0===e.keepPunct&&(e.keepPunct=!0),void 0===e.keepSpace&&(e.keepSpace=!0),((t,e)=>{let n="";if(!t||!t[0]||!t[0][0])return n;for(let o=0;o<t.length;o+=1)n+=ro(t[o],e,!0);return e.keepSpace||(n=n.trim()),!1===e.keepEndPunct&&(t[0][0].tags.has("Emoticon")||(n=n.replace(Yn,"")),t.at(-1).at(-1).tags.has("Emoticon")||(n=Xn(n),e.keepSpace||(n=n.trimEnd())),n.endsWith("'")&&!n.endsWith("s'")&&(n=n.replace(/'/,""))),!0===e.cleanWhitespace&&(n=n.trim()),n})(this.docs,e)}};const Oo={...{debug:function(t){const e=this.methods.one.debug||{};return t&&Object.hasOwn(e,t)||(t="tags"),e[t](this),this},out:function(t){return _(t)?wo(this,t):Object.hasOwn(vo,t)?vo[t](this):this.text()},wrap:function(t){return wo(this,t)}},...jo,...mo,...Jn},ko={Noun:b,Verb:g,Adjective:v,Pivot:w},Eo=(t,e,n)=>{let o=!1;const r=()=>(n?t.join("").trimStart():t.join("").trimEnd()).length+(o?2:0);for(;t.length>0&&r()>e;)n?t.shift():t.pop(),o=!0;return o},$o={tags:t=>{if("undefined"!=typeof window&&window.document)return void(t=>{console.log("%c -=-=- ","background-color:#6699cc;"),t.forEach(t=>{console.groupCollapsed(t.text());const e=t.docs[0].map(t=>({text:t.implicit?"["+t.implicit+"]":t.text||"-",tags:"["+Array.from(t.tags).join(", ")+"]"}));console.table(e,["text","tags"]),console.groupEnd()})})(t);const{docs:e,model:n}=t;0===e.length&&console.log(b("\n ──────")),e.forEach(e=>{console.log(b("\n ╭─────────")),e.forEach(e=>{const o=[...e.tags||[]];let r=e.text||"-";e.sense&&(r=`{${e.normal}/${e.sense}}`),e.implicit&&(r="["+e.implicit+"]"),r=v(r);let s="'"+r+"'";if(!0===e.frozen&&(s+=" ❄️"),e.reference){const n=t.update([e.reference]).text("normal");s+=` - ${j(O("["+n+"]"))}`}s=s.padEnd(18);const i=b(" │ ")+O(s)+" - "+((t,e)=>(e.one.tagSet&&(t=t.map(t=>Object.hasOwn(e.one.tagSet,t)?(S[e.one.tagSet[t].color]||b)(t):t)),t.join(", ")))(o,n);console.log(i)})}),console.log("\n")},chunks:t=>{console.log(""),t.docs.forEach(t=>{const e=t.map(t=>{const e=t.implicit||t.normal;return Object.hasOwn(ko,t.chunk)?ko[t.chunk](e):e});console.log(e.join(" "),"\n")}),console.log("\n")},highlight:t=>{const e="undefined"!=typeof window&&window.document;t.fullPointer.forEach(([n,o,r])=>{const[s,i,a]=((t,e,n)=>{const o=[[],[],[]];t.forEach((t,r)=>{const s=(t.pre+t.text+t.post).replace(/\s+/g," "),i=o[(r>=e?1:0)+(r>=n?1:0)];""===s.trim()&&i.length>0?i[i.length-1]=(i.at(-1)+s).replace(/\s+/g," "):i.push(s)});const[r,s,i]=o,a=(Eo(r,27,!0)?"… ":"")+r.join("").trimStart();let c=s.join("");const l=Eo(i,28-c.length,!1),u=i.join("").trimEnd()+(l?" …":"");return""===u&&(c=c.trimEnd()),[" ".repeat(Math.max(0,27-a.length))+a,c,u]})(t.document[n],o,r);e?console.log("%c"+s+"%c"+i+"%c"+a,"color:grey","color:green","color:grey"):console.log($(s)+g(i)+(a?$(a):""))})}},So=/\{(?=[^{]*$)/,Ao=/\}[ \t]*#(.*)$/s,zo=(t="")=>{let[e,n]=t.split(So);if(void 0===n){const t=e.match(/\s#(.*)$/s)?.[1]||"";return{text:e.replace(/\s#.*$/s,"").trim(),tags:null,comment:t.trim()}}const o=(n.match(Ao)?.[1]||"").trim();n=n.replace(Ao,"}"),n=n.split(",").map(t=>t.trim());const r=n[n.length-1];return n[n.length-1]=r.replace(/\}$/,""),n=n.map(t=>t.split("|").map(t=>t.trim())),1===n.length&&1===n[0].length&&""===n[0][0]&&(n=[]),{text:e.trim(),tags:n,comment:o}},Po=(t="")=>{const e=[];return t.split("\n").forEach((t,n)=>{t.trim()&&!/^\s*#/.test(t)&&e.push({line:n+1,...zo(t)})}),e},To=(t,e)=>t.some(t=>t.some(t=>"."!==t&&!/^!?#?[a-z][a-z0-9]*$/i.test(t)))?null:t.map(t=>(t=t.map(t=>{if("."===t)return".";const n=t.startsWith("!"),o=t.replace(/^!?#?/,"");return(n?"!#":"#")+(e[o]||o)}),t.length>1?`(${t.join(" && ")})`:t[0])).join(" "),_o=(t,e,n)=>{const o=t.terms();t.docs.flat().forEach(t=>t.tags.clear()),e?.forEach((t,e)=>{const r=t.filter(t=>"."!==t&&!t.startsWith("!")).map(t=>(t=t.replace(/^#/,""),n[t]||t));o.eq(e).tag(r,"fromSpec")})},Co=(t,e,n)=>{const o=t.docs.flat(),r=e.map(t=>To([t],n)),s=To(e,n);if(o.length===e.length&&null!==s&&t.has(s))return[];const i=[];return o.length!==e.length&&i.push({code:"length",expected:e.length,actual:o.length,message:`expected ${e.length} terms, got ${o.length}`}),t.compute("tagRank"),e.forEach((t,e)=>{const s=o[e],a=s?Array.from(s.tags):[],c={term:e+1,word:s?.implicit||s?.text||"",expected:t,actual:a};if(null===r[e])return void i.push({...c,code:"syntax",message:`term ${e+1}: invalid slot ${t.join("|")}`});if(!s)return;const l=[];if(t.forEach(t=>{if("."===t)return;const e=t.startsWith("!"),o=t.replace(/^!?#?/,""),r=s.tags.has(n[o]||o);e&&r?l.push(`unexpected #${o}`):e||r||l.push(`missing #${o}`)}),l.length>0){const t=s.tagRank?.[0]||a.at(-1)||"Untagged";i.push({...c,code:"tags",message:`term ${e+1} '${c.word}': #${t}, ${l.join(", ")}`})}}),0===i.length&&i.push({code:"match",message:"tags align, but the sentence pattern did not match"}),i};var Lo={lib:{fromSpec:function(t,{tags:e="ignore",failures:n="ignore",verbose:o=!1}={}){if(!["ignore","use"].includes(e)||!["ignore","throw","retain","log"].includes(n))throw new Error("Invalid fromSpec options");const r=this.world().model.one.tagAliases,s=this("");return s.failures=[],Po(t).forEach(({line:t,text:i,tags:a})=>{const c="use"===e?this.tokenize(i):this(i);let l=[];if(null===a||"use"!==e&&"ignore"===n)"use"===e&&_o(c,null,r);else{const o=c.docs.reduce((t,e)=>t+e.length,0),u=To(a,r),h=o===a.length&&null!==u;if("use"===e&&!h&&"log"!==n){const t=Co(c,a,r);throw new Error(`${i} - ${t.map(t=>t.message).join("; ")}`)}"use"===e&&_o(c,h?a:null,r),"ignore"!==n&&(l=Co(c,a,r).map(e=>({line:t,text:i,...e})),s.failures.push(...l))}const u=l.map(t=>t.message).join("; ");if("log"===n&&l.length>0?console.error(((t,e,n,o)=>{const r=t.docs.flat(),s=new Set(n.filter(t=>t.term).map(t=>t.term-1)),i=new Set(n.filter(t=>"syntax"===t.code).map(t=>t.term-1)),a=n.some(t=>"match"===t.code);let c=0;r.forEach((t,n)=>{t.text&&(c=n),(s.has(n)||n>=e.length||a)&&s.add(c)});const l=r.map((t,e)=>{const n=s.has(e)&&t.text?w(t.text):t.text;return t.pre+n+t.post}).join("").trim(),u=e.map((t,e)=>{const n=r[e];return!n||i.has(e)||a?w(t.join("|")):t.map(t=>{if("."===t)return t;const e=t.startsWith("!"),r=t.replace(/^!?#?/,"");return n.tags.has(o[r]||r)===e?w(t):t}).join("|")}).join(",");return`${l} ${0===e.length?w("{}"):`{${u}}`}`})(c,a,l,r)):(o||z.spec)&&console.log(((t,e,n)=>{const o=null===e?"":` {${e.map(t=>t.join("|")).join(",")}}`;return n?`${w("✗")} ${t}${j(o)} - ${w(n)}`:`${g("✓")} ${g(j(t))}${j(o)}`})(i,a,u)),l.length>0&&"throw"===n)throw new Error(`${i} - ${u}`);if(("retain"!==n||null===a||0!==l.length)&&c.found){const t=s.document.at(-1)?.at(-1);t&&(t.post+="\n"),s.document.push(...c.docs)}}),s},testSpec:function(t,e=!0,n=!1){const o=this.fromSpec(t,{tags:"ignore",failures:"retain",verbose:e});if(n&&o.failures.length>0){const t=o.failures[0];throw new Error(`${t.text} - ${t.message}`)}return o}},api:t=>{Object.assign(t.prototype,Oo)},methods:{one:{hash:lo,debug:$o,parseSpec:Po}}};const No=(t,e)=>{const n=Ae(e),o=[];return t.forEach(t=>{const[e]=t;let r=n[e]||[];if(r=r.filter(e=>((t,e)=>t[1]<=e[1]&&e[2]<=t[2])(t,e)),0===r.length)return void o.push({passthrough:t});r=r.sort((t,e)=>t[1]-e[1]);let s=t;r.forEach((t,e)=>{const n=((t,e)=>{const[n,o]=t,r=e[1],s=e[2],i={};if(o<r){const e=r<t[2]?r:t[2];i.before=[n,o,e]}return i.match=e,t[2]>s&&(i.after=[n,s,t[2]]),i})(s,t);r[e+1]?(o.push({before:n.before,match:n.match}),n.after&&(s=n.after)):o.push(n)})}),o};var Mo={one:{termList:t=>t.flat(),getDoc:(t,e)=>{let n=[];return t.forEach((o,r)=>{if(!o)return;let[s,i,a,c,l]=o,u=e[s]||[];if(void 0===i&&(i=0),void 0===a&&(a=u.length),!c||u[i]&&u[i].id===c)u=u.slice(i,a);else{const n=((t,e,n)=>{for(let o=0;o<20;o+=1)for(const r of[n-o,n+o])if(e[r]){const n=e[r].findIndex(e=>e.id===t);if(-1!==n)return[r,n]}return null})(c,e,s);if(null!==n){const s=a-i;u=e[n[0]].slice(n[1],n[1]+s);const c=u[0]?u[0].id:null;l=e[n[0]].some(t=>t.id===l)?l:void 0,o=[n[0],n[1],n[1]+s,c,l],t[r]=o}else u=u.slice(i,a),o[3]=u[0]?u[0].id:null}0!==u.length&&i!==a&&(l&&u[u.length-1].id!==l&&(u=((t,e)=>{const[n,o,,,r]=t,s=e[n],i=s.findIndex(t=>t.id===r);return-1===i?(t[2]=e[n].length,t[4]=s.length>0?s[s.length-1].id:null):t[2]=i+1,e[n].slice(o,t[2])})(o,e)),n.push(u))}),n=n.filter(t=>t.length>0),n},pointer:{indexN:Ae,splitAll:No}}};const qo=(t,e)=>{const n=t.concat(e),o=Ae(n);let r=[];return n.forEach(t=>{const[e]=t;if(1===o[e].length)return void r.push(t);const n=o[e].filter(e=>Se(t,e));n.push(t);const s=(t=>{let e=t[0][1],n=t[0][2];return t.forEach(t=>{t[1]<e&&(e=t[1]),t[2]>n&&(n=t[2])}),[t[0][0],e,n]})(n);r.push(s)}),r=(t=>{const e={};for(let n=0;n<t.length;n+=1)e[t[n].join(",")]=t[n];return Object.values(e)})(r),r},Fo=(t,e)=>{const n=[];return No(t,e).forEach(t=>{t.passthrough&&n.push(t.passthrough),t.before&&n.push(t.before),t.after&&n.push(t.after)}),n},Wo=(t,e)=>t.map(t=>{const[n,o]=t;return e[n]&&e[n][o]&&(t[3]=e[n][o].id),t}),Bo=(t,e)=>t.toView(Wo(e,t.document)),Vo=t=>function(e){return e=ze(e,this),Bo(this,t(this.fullPointer,e.fullPointer))},Uo={};Uo.union=Vo(qo),Uo.and=Uo.union,Uo.intersection=Vo((t,e)=>{const n=Ae(e),o=[];return t.forEach(t=>{let e=n[t[0]]||[];e=e.filter(e=>Se(t,e)),0!==e.length&&e.forEach(e=>{const n=((t,e)=>{const n=t[1]<e[1]?e[1]:t[1],o=t[2]>e[2]?e[2]:t[2];return n<o?[t[0],n,o]:null})(t,e);n&&o.push(n)})}),o}),Uo.not=Vo(Fo),Uo.difference=Uo.not,Uo.complement=function(){return Bo(this,Fo(this.all().fullPointer,this.fullPointer))},Uo.settle=function(){let t=this.fullPointer;return t.forEach(e=>{t=qo(t,[e])}),t=Wo(t,this.document),this.update(t)};var Ro={methods:Mo,api:t=>{Object.assign(t.prototype,Uo)}};const Do=new WeakMap,Io=new Set,Go=t=>{if(!t||0===t.length)return Io;let e=Do.get(t);return e||(e=new Set(t),Do.set(t,e)),e},Qo=(t,e)=>(t=t.replace(/^#/,""),e?.[t]||t),Ho=t=>Boolean(t&&!t.optional&&!t.negative&&!t.greedy&&!t.choices&&!t.anything&&!t.regex&&!t.method),Zo=(t,e)=>Ho(t)&&t[e]?t:null,Jo=t=>!0===t.optional||!0===t.negative?null:t.tag?"#"+t.tag:t.word?t.word:t.switch?`%${t.switch}%`:null,Ko=(t,e)=>t.some(t=>!t.optional&&!t.negative&&(Jo(t)===e||"and"===t.operator&&t.choices&&t.choices.some(t=>Ko(t,e)))),Xo=(t,e,n)=>{const o=Object.create(null),r=new Set,s=Object.keys(e).length;return t.forEach((t,i)=>{if(r.has(t))return;r.add(t);let a=null,c=s;for(let o=0;o<t.needs.length;o+=1){const r=t.needs[o];(null===a||e[r].length<e[a].length)&&(a=r),c=Math.min(c,n[r])}void 0!==t.hook&&(a=t.hook);const l=[...new Set(t.wants)].filter(t=>n[t]<c).sort((t,e)=>n[t]-n[e]),u=null===a?[...new Set(t.wants)]:[a],h=[...new Set(t.needs)].filter(t=>t!==a),p={rule:t,order:i,rank:c,earlier:l,needs:h,single:1===u.length};for(let t=0;t<u.length;t+=1){const e=u[t];o[e]||=[],o[e].push(p)}}),o},Yo=(t,e,n,o=t.needs)=>{const r=n.length;if(!(r>=t.minWords))return!1;for(let t=0;t<o.length;t+=1)if(!e.has(o[t]))return!1;if(void 0!==t.ifNo)for(let n=0;n<t.ifNo.length;n+=1)if(e.has(t.ifNo[n]))return!1;if(t.wants.length>0){let n=0;for(let o=0;o<t.wants.length&&!(e.has(t.wants[o])&&(n+=1,n>=t.minWant));o+=1);if(!(n>=t.minWant))return!1}return!(r&&t.startTerm&&!xn(n[0],t.startTerm,0,r)||r&&t.endTerm&&!xn(n[r-1],t.endTerm,r-1,r))},tr=(t,e,n)=>{if(!Object.hasOwn(n,e))return!0;const o=Go(n[e].not);if(0===o.size)return!0;for(const e of t.tags)if(o.has(e))return!1;return!0};var er={buildNet:(t,e)=>{t=((t,e)=>{const n=e.methods.one.parseMatch;return t.forEach(t=>{if(((t,e)=>{const n=t=>Array.isArray(t)?t.map(n):"string"!=typeof t?t:t.trim().split(/ +/).map(t=>Qo(t,e)).join(" "),o=t=>"string"==typeof t&&t.startsWith("#")?"#"+n(t):t;void 0!==t.tag&&(t.tag=n(t.tag)),void 0!==t.unTag&&(t.unTag=n(t.unTag)),void 0!==t.hook&&(t.hook=o(t.hook)),void 0!==t.ifNo&&(t.ifNo=[t.ifNo].flat().map(o))})(t,e.model.one.tagAliases),t.regs=n(t.match,{},e),t.fixed=Vn(t.regs),t.checkFirst=Ho(t.regs[0]),t.startTerm=Zo(t.regs[0],"start"),t.endTerm=Zo(t.regs[t.regs.length-1],"end"),t.notIf&&(t.notIf=n(t.notIf,{},e)),t.needs=(t=>{const e=[];return t.forEach(t=>{e.push(Jo(t)),"and"!==t.operator||!t.choices||t.optional||t.negative||t.choices.forEach(t=>{t.forEach(t=>{e.push(Jo(t))})})}),e.filter(t=>t)})(t.regs),!(void 0===t.hook||"string"==typeof t.hook&&t.needs.includes(t.hook)&&Ko(t.regs,t.hook)))throw new Error(`Invalid hook "${t.hook}" for match "${t.match}": use a required word, #Tag, or %Switch%.`);const{wants:o,count:r}=(t=>{const e=[];let n=0;return t.forEach(t=>{"or"!==t.operator||t.optional||t.negative||(t.fastOr&&Array.from(t.fastOr).forEach(t=>{e.push(t)}),t.choices&&t.choices.forEach(t=>{t.forEach(t=>{const n=Jo(t);n&&e.push(n)})}),n+=1)}),{wants:e,count:n}})(t.regs);t.wants=o,t.minWant=r,t.minWords=t.regs.filter(t=>!t.optional).length,t.minLength=$n(t.regs)}),t})(t,e);const n={};t.forEach(t=>{t.needs.concat(t.wants).forEach(e=>{n[e]=Array.isArray(n[e])?n[e]:[],n[e].push(t)})});const o=Object.create(null);Object.keys(n).forEach((t,e)=>{o[t]=e;const r=new Set;n[t]=n[t].filter(t=>!r.has(t)&&(r.add(t),!0))});const r=t.filter(t=>0===t.needs.length&&0===t.wants.length);return{hooks:n,hookOrder:o,index:Xo(t,n,o),always:r}},bulkMatch:(t,e,n,o={})=>{const r=((t,e,n)=>{const{hooks:o,index:r,always:s}=e;let{hookOrder:i}=e;i||(i=Object.create(null),Object.keys(o).forEach((t,e)=>{i[t]=e}));const a=t.map((t,e)=>{if(r)return((t,e,n,o)=>{const r=[],s=new Set;return t.forEach(i=>{const a=e[i];if(Array.isArray(a))for(let e=0;e<a.length;e+=1){const i=a[e];if(!0!==i.single){if(s.has(i))continue;s.add(i)}if(!Yo(i.rule,t,o,i.needs))continue;let c=i.rank;for(let e=0;e<i.earlier.length;e+=1){const o=i.earlier[e];if(t.has(o)){c=n[o];break}}c===i.rank?r.push(i):r.push({rule:i.rule,rank:c,order:i.order})}}),r.sort((t,e)=>t.rank-e.rank||t.order-e.order),r.map(t=>t.rule)})(t,r,i,n[e]);const s=[];t.forEach(t=>{"number"==typeof i[t]&&s.push(t)}),s.sort((t,e)=>i[t]-i[e]);const a=[],c=new Set;for(let r=0;r<s.length;r+=1){const i=o[s[r]];for(let o=0;o<i.length;o+=1){const r=i[o];c.has(r)||(c.add(r),Yo(r,t,n[e])&&a.push(r))}}return a});return a.forEach((e,o)=>{for(let r=0;r<s.length;r+=1)Yo(s[r],t[o],n[o])&&e.push(s[r])}),a})(n.one.cacheDoc(t),e,t),s=((t,e,n,o)=>{const r=[];for(let s=0;s<t.length;s+=1){const i=[e[s]];for(let e=0;e<t[s].length;e+=1){const a=t[s][e],c=n.one.match(i,a);if(c.ptrs.length>0&&(c.ptrs.forEach(t=>{t[0]=s,r.push({...a,pointer:t})}),!0===o.matchOne))return[r[0]]}}return r})(r,t,n,o);return s},bulkTagger:(t,e,n)=>{const{model:o,methods:r}=n,{getDoc:s,setTag:i,unTag:a}=r.one,c=r.two.looksPlural;return 0===t.length?t:t.map(t=>{if(!t.tag&&!t.chunk&&!t.unTag)return;const r=t.reason||t.match,l=s([t.pointer],e)[0];let u;if(!0===t.safe){if(!1===((t,e,n)=>t.every(t=>tr(t,e,n.one.tagSet)))(l,t.tag,o))return;if("-"===l[l.length-1].post)return;"string"==typeof t.tag&&Object.hasOwn(o.one.tagSet,t.tag)&&(u=o.one.tagSet[t.tag])}if(void 0!==t.tag){if(i(l,t.tag,n,t.safe,`[post] '${r}'`,u),"Noun"===t.tag&&c){const e=l[l.length-1];c(e.text)?i([e],"Plural",n,t.safe,"quick-plural"):i([e],"Singular",n,t.safe,"quick-singular")}!0===t.freeze&&l.forEach(t=>t.frozen=!0)}void 0!==t.unTag&&a(l,t.unTag,o.one.tagSet,r),t.chunk&&l.forEach(e=>e.chunk=t.chunk)})}},nr={lib:{buildNet:function(t){const e=this.methods().one.buildNet(t,this.world());return e.isNet=!0,e}},api:function(t){t.prototype.sweep=function(t,e={}){const{world:n,docs:o}=this,{methods:r}=n;let s=r.one.bulkMatch(o,t,this.methods,e);!1!==e.tagger&&r.one.bulkTagger(s,o,this.world),s=s.map(t=>{const e=t.pointer,n=o[e[0]][e[1]],r=e[2]-e[1];return n.index&&(t.pointer=[n.index[0],n.index[1],n.index[1]+r]),t});const i=s.map(t=>t.pointer);return s=s.map(t=>(t.view=this.update([t.pointer]),delete t.regs,delete t.needs,delete t.pointer,delete t._expanded,t)),{view:this.update(i),found:s}}},methods:{one:er}};const or=/ /,rr=(t,e)=>{"Noun"!==e&&"Verb"!==e||(t.chunk=e)},sr=(t,e,n,o,r,s)=>{if(t.tags.has(e))return null;if("."===e)return null;!0===t.frozen&&(o=!0);const i=z.tags?z.before(t):null,a=n[e];if(a){if(a!==r&&a.not&&a.not.length>0){const e=Go(a.not);for(const n of t.tags)if(e.has(n)){if(!0===o)return null;t.tags.delete(n)}}if(a.parents&&a.parents.length>0)for(let e=0;e<a.parents.length;e+=1)t.tags.add(a.parents[e]),rr(t,a.parents[e])}return t.tags.add(e),t.dirty=!0,rr(t,e),i&&z.log(t,i,s),!0},ir=(t,e,n={},o,r,s)=>{const i=n.model.one.tagSet||{};if(e)if(Array.isArray(e))e.forEach(e=>ir(t,e,n,o,r));else if("string"==typeof e)if(e=e.trim(),or.test(e))((t,e,n,o,r,s)=>{const i=e.split(or);t.forEach((t,e)=>{const a=i[e];a&&sr(t,Qo(a,o),n,r,void 0,s)})})(t,e,i,n.model.one.tagAliases,o,r);else{e=Qo(e,n.model.one.tagAliases);for(let n=0;n<t.length;n+=1)sr(t[n],e,i,o,s,r)}else console.warn(`compromise: Invalid tag '${e}'`)},ar=t=>(t.children=t.children||[],t._cache=t._cache||{},t.props=t.props||{},t._cache.parents=t._cache.parents||[],t),cr=(t,e,n=!0)=>{const o=n?[]:null,r=[t];for(;r.length>0;){const t=r.pop();if(n&&o.push(t),t.children)for(let n=t.children.length-1;n>=0;n-=1){const o=t.children[n];e&&e(t,o),r.push(o)}}return o};class lr{constructor(t){Object.defineProperty(this,"json",{enumerable:!1,value:t,writable:!0})}cache(){var t;return t=this.json,cr(t,(t,e)=>{t.id&&(e._cache.parents=t._cache.parents.concat([t.id]))},!1),this}fillDown(){return t=this.json,cr(t,(t,e)=>{e.props=((t,e)=>(e.not&&(t.not=new Set([...t.not,...e.not])),Array.isArray(e.also)&&(void 0===t.also||Array.isArray(t.also))?t.also=e.also.concat(t.also||[]):void 0===t.also&&(t.also=e.also),void 0===t.is&&(t.is=e.is),void 0===t.novel&&(t.novel=e.novel),t))(e.props,t.props)},!1),this;var t}toArray(){return(t=>{const e=cr(t),n=e[0];return n&&!n.id&&0===Object.keys(n.props).length&&e.shift(),e})(this.json)}}const ur={Noun:"blue",Verb:"green",Negative:"green",Date:"red",Value:"red",Adjective:"magenta",Connector:"cyan",Determiner:"cyan",Hyphenated:"cyan",Adverb:"cyan"},hr=t=>{if(Object.hasOwn(ur,t.id))return ur[t.id];if(Object.hasOwn(ur,t.is))return ur[t.is];const e=t._cache.parents.find(t=>ur[t]);return ur[e]},pr=(t,e)=>{const n=Object.create(null);return Object.keys(t).forEach(t=>{n[t]=t}),Object.keys(t).forEach(o=>{const r=t[o];(void 0===r.aliases?[r.alias]:[r.aliases].flat()).forEach(r=>{if(null!=r){if("string"!=typeof r||!/^[\p{L}_][\p{L}\p{M}\p{N}_-]*$/u.test(r))throw new Error(`compromise: invalid alias for '#${o}'`);(e?[r,e(r)]:[r]).forEach(e=>{if(Object.hasOwn(t,e)){if(e!==r&&e!==o)throw new Error(`compromise: tag alias '${r}' normalizes to '#${e}'`)}else{if(n[e]&&n[e]!==o)throw new Error(`compromise: duplicate tag alias '${e}'`);n[e]=o}})}})}),n},fr=t=>t?"string"==typeof t?[t]:t.slice():[];var dr={one:{setTag:ir,unTag:(t,e,n,o="untag")=>{e=e.trim().replace(/^#/,"");const r=Go(n[e]?.children);for(let n=0;n<t.length;n+=1){const s=t[n];if(!0===s.frozen)continue;const i=z.tags?z.before(s):null;if("*"!==e){if(r.size>0)for(const t of s.tags)r.has(t)&&s.tags.delete(t);s.tags.delete(e),i&&z.log(s,i,o)}else s.tags.clear(),i&&z.log(s,i,o)}},addTags:(t,e)=>{t=Object.fromEntries(Object.entries(t).map(([t,e])=>[t,{...e}])),Object.keys(e).length>0&&(t=(t=>(Object.entries(t).forEach(([e,n])=>{t[e]={...n,novel:!0}}),t))(t)),t=((t,e)=>(t=Object.fromEntries(Object.keys({...e,...t}).map(n=>[n,{...e[n],...t[n]}])),t=(t=>{const e=pr(t),n=t=>e[t]||t,o=e=>{Object.hasOwn(t,e)||(t[e]={})};return Object.keys(t).forEach(e=>{const r=t[e];r.isA&&(r.is=r.isA),r.notA&&(r.not=r.notA),"string"==typeof r.is&&(r.is=n(r.is)),r.also&&(r.also=fr(r.also).map(n)),r.not&&(r.not=fr(r.not).map(n)),r.is&&"string"==typeof r.is&&o(r.is),fr(r.also).forEach(o),fr(r.not).forEach(o)}),t})(t),Object.keys(t).forEach(e=>{const n=t[e];void 0!==n.aliases&&(n.aliases=fr(n.aliases)),n.children=fr(n.children),n.not=fr(n.not),n.also&&(n.also=fr(n.also))}),Object.keys(t).forEach(e=>{(t[e].not||[]).forEach(n=>{t[n]&&t[n].not&&!t[n].not.includes(e)&&t[n].not.push(e)})}),t))(t,e);const n=(t=>{const e=Object.keys(t).map(e=>{const n=t[e],o={not:new Set(n.not),also:n.also,is:n.is,novel:n.novel};return{id:e,parent:n.is,props:o,children:[],alias:n.alias,aliases:n.aliases?.slice()}});return(n=e,new lr((t=>{const e=new Map;t.forEach(t=>{ar(t),e.set(t.id,t)});const n=ar({});return t.forEach(t=>{if(t.parent)if(e.has(t.parent)){const n=e.get(t.parent);delete t.parent,n.children.push(t)}else console.warn(`[Graph] - missing node '${t.parent}'`);else n.children.push(t)}),(t=>{const e=new Map,n=t.map(t=>[t,!1]);for(;n.length>0;){const[t,o]=n.pop();if(o)e.set(t,2);else{if(1===e.get(t))throw new Error("[Grad] - cyclic input");if(!e.has(t)){e.set(t,1),n.push([t,!0]);for(const e of t.children||[])n.push([e,!1])}}}e.keys()})(t),n})(n))).cache().fillDown().toArray();var n})(t),o=(t=>{const e={},n=t=>Object.keys(e).forEach(t);t.forEach(t=>{const{not:n,also:o,is:r,novel:s}=t.props;let i=t._cache.parents;o&&(i=i.concat(o)),e[t.id]={is:r,not:n,novel:s,also:o,parents:i,children:[],color:hr(t),alias:void 0===t.aliases?t.alias:t.aliases[0],aliases:t.aliases}});const o=new Set,r=new Set,s=t=>{if(o.has(t))return e[t].parents;if(r.has(t))throw new Error(`compromise: cyclic tag inheritance at '${t}'`);r.add(t);const n=new Set;return e[t].parents.forEach(t=>{e[t]&&s(t).forEach(t=>n.add(t)),n.add(t)}),e[t].parents=Array.from(n),r.delete(t),o.add(t),e[t].parents};n(s),n(t=>{e[t].parents.forEach(n=>{e[n]&&e[n].children.push(t)})});const i={};return n(t=>{i[t]=e[t].not}),n(t=>{const n=new Set(i[t]);e[t].parents.forEach(t=>{for(const e of i[t]||[])n.add(e)}),Array.from(n).forEach(t=>{e[t]&&e[t].children.forEach(t=>n.add(t))}),e[t].not=Array.from(n),Go(e[t].not),Go(e[t].children);const o=[t,...e[t].parents].filter(t=>n.has(t));if(o.length>0){const e=o.map(t=>`#${t}`).join(", ");console.warn(`compromise: contradictory tag '#${t}' requires and excludes: ${e}`)}}),e})(n);return o},canBe:tr}};const mr=(t,e)=>{if(!t.found||!e)return null;const n=t.termList();return 0===n.length?null:n},gr={tag:function(t,e="",n){const o=mr(this,t);return o&&(this.methods.one.setTag(o,t,this.world,n,e),this.uncache()),this},tagSafe:function(t,e=""){return this.tag(t,e,!0)},unTag:function(t,e){const n=mr(this,t);if(n){const{methods:o,model:r}=this,{tagSet:s,tagAliases:i}=r.one;(Array.isArray(t)?t:[t]).forEach(t=>o.one.unTag(n,Qo(t.trim(),i),s,e)),this.uncache()}return this},canBe:function(t){const{tagSet:e,tagAliases:n}=this.model.one;t=Qo(t,n);const o=this.methods.one.canBe,r=[];B(this.document,(n,s,i,a)=>{o(n,t,e)||r.push([a,i,i+1])});const s=this.update(r);return this.difference(s)}};var wr={addTags:function(t){const e=this.world(),{model:n,methods:o}=e,r=n.one.tagSet,s=(0,o.one.addTags)(t,r),i=pr(s,t=>o.one.killUnicode(t,e));return n.one.tagSet=s,n.one.tagAliases=i,this}};const br=new Set(["Auxiliary","Possessive"]);var yr={model:{one:{tagSet:{},tagAliases:Object.create(null)}},compute:{tagRank:t=>{const{document:e,world:n}=t,o=n.model.one.tagSet;B(e,t=>{const e=Array.from(t.tags);t.tagRank=((t,e)=>(t=t.sort((t,n)=>{if(br.has(t)||!Object.hasOwn(e,n))return 1;if(br.has(n)||!Object.hasOwn(e,t))return-1;let o=e[t].children||[];const r=o.length;return o=e[n].children||[],r-o.length}),t))(e,o)})}},methods:dr,api:t=>{Object.assign(t.prototype,gr)},lib:wr};const vr=new Set(".!?‽⸘‼⁇⁈⁉।॥؟۔։።፧။។。"),xr=new Set("。!?。"),jr=new Set("「『(【〔《〈“"),Or=new Set("」』)】〕》〉”"),kr=/\s/,Er=/^[.!?‽⸘‼\u2047-\u2049।॥؟۔։።፧။។。]+\s$/,$r=/^(?:[.!?‽⸘‼\u2047-\u2049।॥؟۔։።፧။។。!?。]+\s|[。!?。]+[」』)】〕》〉”]*)$/,Sr=/((?:\r?\n|\r)+)/,Ar=/[\p{L}\p{N}\p{So}]/u,zr=/\S/,Pr=/\p{L}/u,Tr=t=>Boolean(/\n$/.test(t)),_r=[['"','"'],[""","""],["“","”","„"],["‟","”"],["„","”“"],["⹂","”"],["‚","’‘"],["«","»"],["»","«"],["‹","›"],["›","‹"],["‵","′"],["‶","″"],["‷","‴"],["〝","〞"],["〟","〞"],["「","」"],["『","』"]],Cr=new RegExp("["+_r.map(t=>t[0]).join("")+"]"),Lr=(t,e)=>{let n=0;for(const o of t)e.includes(o)&&(n+=1);return n},Nr=t=>!!Cr.test(t)&&_r.some(([e,n,o])=>{const r=Lr(t,e);return!(0===r||o&&t.includes(o))&&(e===n?r%2==1:r>Lr(t,n))}),Mr=/[(\uFF08]/g,qr=/[)\uFF09]/g,Fr=/\S/,Wr=/^\s+/,Br=/\p{L} ?\/ ?\p{L}+$/u,Vr=/\S/,Ur=/^[!?.]+$/,Rr=/(\S+)/,Dr=new Set(Ot("\n.\n?\n!\n:\n;\n-\n–\n—\n--\n...\n(\n)\n[\n]\n\"\n'\n`\n«\n»\n*\n•\n")),Ir=/\p{Letter}/u,Gr=/\p{Mark}/u,Qr=/[\p{Number}\p{Currency_Symbol}]/u,Hr=/^[a-z]\.([a-z]\.)+/i,Zr=/[sn]['’]$/,Jr=/^['’](tis|twas|em|cause|til|bout|round)\b/i,Kr=/^[(+\-]?\d+(th|st|nd|rd)?[)+\-]?$/,Xr={")":"(","]":"[","}":"{"},Yr=(t,e,n)=>{const o=t[n-1];let r=0;for(let s=e;s<n-1;s+=1)t[s]===Xr[o]?r+=1:t[s]===o&&(r-=1);return r>0},ts=(t,e)=>{let n=t.length;for(;n>0&&e.test(t[n-1]);)n--;return t.slice(0,n)},es=[/^([A-Z]\.)+[A-Z]?,?$/,/^([a-z]\.)+[a-z]\.?$/,/^[A-Z]\.,?$/,/^[A-Z]{2,}('s|,)?$/],ns=(t,e)=>{const n=e.methods.one.killUnicode;let o=t.text||"";o=(t=>{t||="";const e=t=(t=t.toLowerCase()).trim();return t=(t=(t=ts(t,/[,;.!?]/)).replaceAll("…","...")).replaceAll("–","-"),/^[:;]/.test(t)||(t=(t=ts(t,/[",.!:;?)]/)).replace(/^['’"(]+/g,"")),""===(t=(t=t.replace(/[\u200B-\u200D\uFEFF]/g,"")).trim())&&(t=e),t.replace(/([0-9]),([0-9])/g,"$1$2")})(o),o=n(o,e),o=(t=>((t=>es.some(e=>e.test(t)))(t)&&(t=t.replace(/\./g,"")),t))(o),t.normal=o},os=/[ .][A-Z]\.? *$/i,rs=/(?:\u2026|\.{2}) *$/,ss=/\p{L}/u,is=/\. *$/,as=/^\p{Lu}\. $/u,cs=/[ .]\p{Lu}\. *$/u;var ls={one:{killUnicode:(t,e)=>{const n=e.model.one.unicode||{};t||="";const o=t.split("");return o.forEach((t,e)=>{n[t]&&(o[e]=n[t])}),o.join("")},tokenize:{splitSentences:(t,e)=>{if(t||="",!(t=String(t))||"string"!=typeof t||!Fr.test(t))return[];const n=(t=>{const e=[],n=/[。!?。]/.test(t),o=n?new Set([...vr,...xr]):vr;for(const r of t.split(Sr)){let t=0;const s=[],i=(e,n)=>{s.push(r.slice(t,e),r.slice(e,n)),t=n};let a=0;for(;a<r.length;){if(!o.has(r[a])){a++;continue}const t=a;for(;a<r.length&&o.has(r[a]);)a++;if(a<r.length&&kr.test(r[a])){i(t,a+1),a++;continue}if(!n)continue;let e=t;for(;e<a;){if(!xr.has(r[e])){e++;continue}const t=e;for(;e<a&&xr.has(r[e]);)e++;let n=e;for(;n<r.length&&Or.has(r[n]);)n++;(n===e||n===r.length||kr.test(r[n])||jr.has(r[n]))&&(i(t,n),n>a&&(a=n))}}s.push(r.slice(t));for(let t=0;t<s.length;t++){const o=s[t+1];o&&(n?$r:Er).test(o)&&(s[t]+=o,s[t+1]=""),s[t]&&e.push(s[t])}}return e})(t);let o=(t=>{const e=[];let n="";for(let o=0;o<t.length;o++){const r=t[o];if(void 0!==r&&""!==r){if(!zr.test(r)||!Ar.test(r)){if(e[e.length-1]){e[e.length-1]+=r;continue}if(t[o+1]){n+=r;continue}}e.push(n+r),n=""}}return e})(n);if(o=((t,e)=>{const n=e.methods.one.tokenize.isSentence,o=e.model.one.abbreviations||new Set,r=[];let s="",i="",a=!1;for(let e=0;e<t.length;e++){const c=t[e];s+=c,i=(i+c).slice(-64),a||=Pr.test(c),(!t[e+1]||n(i,o,a)||Tr(c))&&(s.length>0&&r.push(s),s="",i="",a=!1)}return r})(o,e),o=(t=>{const e=[];for(let n=0;n<t.length;n+=1){let o=t[n];if(Nr(o)){let e="";for(let r=n+1;r<t.length&&r-n<=5&&(e+=t[r],!(e.length>=280));r+=1)if(!Nr(o+e)){o+=e,n=r;break}}e.push(o)}return e})(o),o=(t=>{const e=[];for(let n=0;n<t.length;n+=1){const o=t[n].match(Mr);null!==o&&1===o.length&&t[n+1]&&t[n+1].length<250&&null!==t[n+1].match(qr)&&1===o.length&&!Mr.test(t[n+1])?(t[n]+=t[n+1],e.push(t[n]),t[n+1]="",n+=1):e.push(t[n])}return e})(o),0===o.length)return[t];for(let t=1;t<o.length;t+=1){const e=o[t].match(Wr);null!==e&&(o[t-1]+=e[0],o[t]=o[t].replace(Wr,""))}return o},isSentence:(t,e,n=ss.test(t))=>{if(!1===n)return!1;if(os.test(t)||cs.test(t))return!1;if(3===t.length&&as.test(t))return!1;if(rs.test(t))return!1;const o=t.replace(/[.!?\u203D\u2E18\u203C\u2047-\u2049] *$/,"").split(" "),r=o[o.length-1].toLowerCase();return!Object.hasOwn(e,r)||!is.test(t)},splitTerms:(t,e)=>{let n=[],o=[];if(t||="","number"==typeof t&&(t=String(t)),Array.isArray(t))return t;const r=t.split(Rr);for(let t=0;t<r.length;t++)ln(r[t],e)?o=o.concat(un(r[t])):o.push(r[t]);let s="";for(let t=0;t<o.length;t++){const e=o[t];!Vr.test(e)||Dr.has(e)||Ur.test(e)?s+=e:(n.length>0?(n[n.length-1]+=s,n.push(e)):n.push(s+e),s="")}return s&&(0===n.length&&(n[0]=""),n[n.length-1]+=s),n=(t=>{for(let e=1;e<t.length-1;e++)Br.test(t[e])&&(t[e-1]+=t[e]+t[e+1],t[e]=null,t[e+1]=null);return t})(n),n=(t=>{const e=/^[0-9]{1,4}(:[0-9][0-9])?([a-z]{1,2})? ?[-–—] ?$/,n=/^[0-9]{1,4}([a-z]{1,2})? ?$/;for(let o=0;o<t.length-1;o+=1)t[o+1]&&e.test(t[o])&&n.test(t[o+1])&&(t[o]=t[o]+t[o+1],t[o+1]=null);return t})(n),n=n.filter(t=>t),n},splitWhitespace:(t,e)=>{const{str:n,pre:o,post:r}=((t,e)=>{const{prePunctuation:n,postPunctuation:o,emoticons:r}=e.one,s=t,i=t.trim();let a="",c="";const l=Array.from(t);let u=0,h=l.length;if(Object.hasOwn(r,i))return{str:i,pre:a,post:" "};for(;u<h;){const t=l[u];if(!0===n[t])break;if(("+"===t||"-"===t||"("===t)&&Kr.test(i))break;if(Ir.test(t)||Qr.test(t))break;if(("'"===t||"’"===t)&&Jr.test(l.slice(u).join("")))break;u++}for(;h>u;){const t=l[h-1];if(!0===o[t])break;if(Ir.test(t)||Qr.test(t))break;if(Gr.test(t)){let t=h-2;for(;t>=u&&Gr.test(l[t]);)t--;if(t>=u&&Ir.test(l[t]))break;h=t+1;continue}if("."===t&&Hr.test(s))break;if("'"===t&&Zr.test(s))break;if(("+"===t||")"===t)&&Kr.test(i))break;if(Object.hasOwn(Xr,t)&&Yr(l,u,h))break;h--}if(a=l.slice(0,u).join(""),c=l.slice(h).join(""),""===(t=l.slice(u,h).join(""))){let e=s.length;for(;e>0&&" "===s[e-1];)e--;c=s.slice(e),t=s.slice(0,e),a=""}return{str:t,pre:a,post:c}})(t,e);return{text:n,pre:o,post:r,tags:new Set}},fromString:(t,e)=>{const{methods:n,model:o}=e,{splitSentences:r,splitTerms:s,splitWhitespace:i}=n.one.tokenize;return t||="",r(t,e).map(t=>{let n=s(t,o);return n=n.map(t=>i(t,o)),n.forEach(t=>{ns(t,e)}),n})}}}},us=Ot("\napprox\napt\nbc\ncyn\neg\nesp\nest\netc\nex\nexp\nprob\npron\ngal\nmin\npseud\nfig\njd\nlat\nlng\nvol\nfm\ndef\nmisc\nplz\nea\nps\nsec\npt\npref\npl\npp\nqt\nfr\nsq\nnee\nss\ntel\ntemp\nvet\nver\nfem\nmasc\neng\nadj\nvb\nrb\ninf\nsitu\nvivo\nvitro\nwr\n"),hs=Ot("\nadj\nadm\nadv\nasst\natty\nbldg\nbrig\ncapt\ncmdr\ncomdr\ncpl\ndet\ndr\nesq\ngen\ngov\nhon\njr\nllb\nlt\nmaj\nmessrs\nmlle\nmme\nmr\nmrs\nms\nmstr\nphd\nprof\npvt\nrep\nreps\nres\nrev\nsen\nsens\nsfc\nsgt\nsir\nsr\nsupt\nsurg\n"),ps=Ot("\njan\nfeb\nmar\napr\njun\njul\naug\nsep\nsept\noct\nnov\ndec\n"),fs=Ot("\nad\nal\narc\nba\nbl\nca\ncca\ncol\ncorp\nft\nfy\nie\nlit\nma\nmd\npd\ntce\n"),ds=Ot("\ndept\nuniv\nassn\nbros\ninc\nltd\nco\n"),ms=Ot("\nrd\nst\ndist\nmt\nave\nblvd\ncl\ncres\nhwy\nariz\ncal\ncalif\ncolo\nconn\nfla\nfl\nga\nida\nia\nkan\nkans\nminn\nneb\nnebr\nokla\npenna\npenn\npa\ndak\ntenn\ntex\nut\nvt\nva\nwis\nwisc\nwy\nwyo\nusafa\nalta\nont\nque\nsask\n"),gs=Ot("\ndl\nml\ngal\nqt\npt\ntbl\ntsp\ntbsp\nkm\ndm\ncm\nmm\nmi\ntd\nhr\nhrs\nkg\nhg\ndg\ncg\nmg\nµg\nlb\noz\nsq ft\nhz\nmps\nmph\nkmph\nkb\nmb\ntb\nlx\nlm\nfl oz\nyb\n");const ws={},bs={};[[us],[gs,"Unit"],[fs,"Noun"],[hs,"Honorific"],[ps,"Month"],[ds,"Organization"],[ms,"Place"]].forEach(t=>{t[0].forEach(e=>{ws[e]=!0,bs[e]="Abbreviation",void 0!==t[1]&&(bs[e]=[bs[e],t[1]])})});var ys=kt(Ot("\nanti\nbi\nco\ncontra\nde\nextra\ninfra\ninter\nintra\nmacro\nmicro\nmis\nmono\nmulti\nperi\npre\npro\nproto\npseudo\nre\nsub\nsupra\ntrans\ntri\nun\nout\nex\n")),vs=kt(Ot("\nlike\nish\nless\nable\nelect\ntype\ndesignate\n"));const xs={"!":"¡","?":"¿Ɂ",'"':'“”"❝❞',"'":"‘‛❛❜’","-":"—–",a:"ªÀÁÂÃÄÅàáâãäåĀāĂ㥹ǍǎǞǟǠǡǺǻȀȁȂȃȦȧȺΆΑΔΛάαλАаѦѧӐӑӒӓƛæ",b:"ßþƀƁƂƃƄƅɃΒβϐϦБВЪЬвъьѢѣҌҍ",c:"¢©ÇçĆćĈĉĊċČčƆƇƈȻȼͻͼϲϹϽϾСсєҀҁҪҫ",d:"ÐĎďĐđƉƊȡƋƌ",e:"ÈÉÊËèéêëĒēĔĕĖėĘęĚěƐȄȅȆȇȨȩɆɇΈΕΞΣέεξϵЀЁЕеѐёҼҽҾҿӖӗễ",f:"ƑƒϜϝӺӻҒғſ",g:"ĜĝĞğĠġĢģƓǤǥǦǧǴǵ",h:"ĤĥĦħƕǶȞȟΉΗЂЊЋНнђћҢңҤҥҺһӉӊ",I:"ÌÍÎÏ",i:"ìíîïĨĩĪīĬĭĮįİıƖƗȈȉȊȋΊΐΪίιϊІЇіїi̇",j:"ĴĵǰȷɈɉϳЈј",k:"ĶķĸƘƙǨǩΚκЌЖКжкќҚқҜҝҞҟҠҡ",l:"ĹĺĻļĽľĿŀŁłƚƪǀǏǐȴȽΙӀӏ",m:"ΜϺϻМмӍӎ",n:"ÑñŃńŅņŇňʼnŊŋƝƞǸǹȠȵΝΠήηϞЍИЙЛПийлпѝҊҋӅӆӢӣӤӥπ",o:"ÒÓÔÕÖØðòóôõöøŌōŎŏŐőƟƠơǑǒǪǫǬǭǾǿȌȍȎȏȪȫȬȭȮȯȰȱΌΘΟθοσόϕϘϙϬϴОФоѲѳӦӧӨөӪӫ",p:"ƤΡρϷϸϼРрҎҏÞ",q:"Ɋɋ",r:"ŔŕŖŗŘřƦȐȑȒȓɌɍЃГЯгяѓҐґ",s:"ŚśŜŝŞşŠšƧƨȘșȿЅѕ",t:"ŢţŤťŦŧƫƬƭƮȚțȶȾΓΤτϮТт",u:"ÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųƯưƱƲǓǔǕǖǗǘǙǚǛǜȔȕȖȗɄΰυϋύ",v:"νѴѵѶѷ",w:"ŴŵƜωώϖϢϣШЩшщѡѿ",x:"×ΧχϗϰХхҲҳӼӽӾӿ",y:"ÝýÿŶŷŸƳƴȲȳɎɏΎΥΫγψϒϓϔЎУучўѰѱҮүҰұӮӯӰӱӲӳ",z:"ŹźŻżŽžƵƶȤȥɀΖ"},js={};Object.keys(xs).forEach(t=>{xs[t].split("").forEach(e=>{js[e]=t})});for(let t=33;t<=126;t+=1)js[String.fromCharCode(t+65248)]=String.fromCharCode(t);const Os="\ufeff",ks=kt(("#@_°"+Os).split("")),Es=kt(("%_°"+Os).split("")),$s=kt("<3 </3 <\\3 :^P :^p :^O :^3".split(" ")),Ss=/\//,As=/[a-z]\.[a-z]/i,zs=/[0-9]/,Ps=(t,e)=>{const n=t.normal||t.text||t.machine,o=e.model.one.aliases;if(Object.hasOwn(o,n)&&(t.alias||=[],t.alias.push(o[n])),Ss.test(n)&&!As.test(n)&&!zs.test(n)){const e=n.split(Ss);e.length<=3&&e.forEach(e=>{""!==(e=e.trim())&&(t.alias||=[],t.alias.push(e))})}return t},Ts=/^\p{Letter}+-\p{Letter}+$/u,_s=t=>{let e=t.implicit||t.normal||t.text;e=e.replace(/['’]s$/,""),e=e.replace(/s['’]$/,"s"),e=e.replace(/([aeiou][ktrp])in'$/,"$1ing"),Ts.test(e)&&(e=e.replace(/-/g,"")),e=e.replace(/^[#@]/,""),e!==t.normal&&(t.machine=e)},Cs=(t,e)=>B(t.docs,n=>e(n,t.world));var Ls={compute:{alias:t=>Cs(t,Ps),machine:t=>Cs(t,_s),normal:t=>Cs(t,ns),freq:t=>{const e=t.docs,n=Object.create(null);B(e,t=>{const e=t.machine||t.normal;n[e]??=0,n[e]+=1}),B(e,t=>{t.freq=n[t.machine||t.normal]})},offset:t=>{let e=0,n=0;B(t.document,t=>{t.offset={index:n,start:e+t.pre.length,length:t.text.length},e+=t.pre.length+t.text.length+t.post.length,n+=1})},index:t=>{B(t.document,(t,e,n,o)=>{t.index=[o,n]})},wordCount:t=>{let e=0;B(t.docs,t=>{""!==t.normal&&(e+=1,t.wordCount=e)})}},methods:ls,model:{one:{aliases:{"&":"and","@":"at","%":"percent",plz:"please",bein:"being"},abbreviations:ws,prefixes:ys,suffixes:vs,prePunctuation:ks,postPunctuation:Es,lexicon:bs,unicode:js,emoticons:$s}},hooks:["alias","machine","index","id"]},Ns={typeahead:t=>{const e=t.model.one.typeahead,n=t.docs;if(0===n.length||0===Object.keys(e).length)return;const o=n.at(-1)?.at(-1);if(o&&!o.post&&Object.hasOwn(e,o.normal)){const n=e[o.normal];o.implicit=n,o.machine=n,o.typeahead=!0,t.compute.preTagger&&t.last().unTag("*").compute(["lexicon","preTagger"])}}};const Ms=function(){const t=this.docs;if(0===t.length)return this;const e=t.at(-1)?.at(-1);return!0===e?.typeahead&&e.machine&&(e.text=e.machine,e.normal=e.machine),this},qs={safe:!0,min:3};var Fs={typeahead:function(t=[],e={}){const n=this.model();e={...qs,...e},_(t)&&(Object.assign(n.one.lexicon,t),t=Object.keys(t));const o=((t,e,n)=>{let o={};const r=[],s=n.prefixes||{};return t.forEach(t=>{let i=(t=t.toLowerCase().trim()).length;e.max&&i>e.max&&(i=e.max);for(let a=e.min;a<i;a+=1){const i=t.substring(0,a);e.safe&&Object.hasOwn(n.model.one.lexicon,i)||(Object.hasOwn(s,i)||Object.hasOwn(o,i)?r.push(i):o[i]=t)}}),o={...s,...o},r.forEach(t=>{delete o[t]}),o})(t,e,this.world());return Object.keys(o).forEach(t=>{Object.hasOwn(n.one.typeahead,t)?delete n.one.typeahead[t]:n.one.typeahead[t]=o[t]}),this}},Ws={model:{one:{typeahead:{}}},api:t=>{t.prototype.autoFill=Ms},lib:Fs,compute:Ns,hooks:["typeahead"]};return M.extend(xt),M.extend(Lo),M.extend(Gn),M.extend(Ro),M.extend(yr),M.plugin(Yt),M.extend(Ls),M.extend(ee),M.plugin(W),M.extend(fe),M.extend(Ws),M.extend(ae),M.extend(nr),M});