bravey
Version:
A simple JavaScript NLP-like library to help you creating your own bot.
2 lines • 74.3 kB
JavaScript
// Bravey v0.1 - http://github.com/braveyjs/bravey - MIT Licensed
var Bravey={REVISION:"0.1"};"function"==typeof define&&define.amd?define("Bravey",Bravey):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=Bravey),Bravey.DATA={},Bravey.Language={},Bravey.Nlp={},Bravey.Filter={},Bravey.SessionManager={},Bravey.File={},Bravey.File.load=function(e,r,t,n){if("undefined"!=typeof module&&module.exports)Bravey.DATA.fs||(Bravey.DATA.fs=require("fs")),r(Bravey.DATA.fs.readFileSync(e,"utf8"));else{var i=null;i=new XMLHttpRequest,i.onreadystatechange=function(){4==i.readyState&&(200==i.status?r(i.responseText):r())},i.open(t||"GET",e),i.send(null)}},Bravey.Text={},Bravey.Text.WORDSEP="[^(a-zA-ZA-Яa-я0-9_!?.:)+s]*",Bravey.Text.TRIMSTART=new RegExp("^("+Bravey.Text.WORDSEP+")","gi"),Bravey.Text.TRIMEND=new RegExp("("+Bravey.Text.WORDSEP+")$","gi"),Bravey.Text.generateGUID=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},Bravey.Text.calculateScore=function(e,r){for(var t=0,n=0;n<r.length;n++)e[r[n]]&&t++;return t},Bravey.Text.entityTrim=function(e){var r=e.string.match(Bravey.Text.TRIMSTART),t=e.string.match(Bravey.Text.TRIMEND),n=r?r[0].length:0,i=t?t[0].length:0;return e.position+=n,e.string=e.string.substr(n,e.string.length-n-i),e},Bravey.Text.RegexMap=function(e,r){for(var t=0;t<e.length;t++){e[t].mtch=[];for(var n=0;n<e[t].str.length;n++)e[t].mtch.push(e[t].str[n].replace(/~/g,""))}this.regex=function(r){for(var t="(",n=0;n<e.length;n++)for(var i=0;i<e[n].str.length;i++)t+=e[n].str[i].replace(/~/g,"\\b")+"|";return t.substr(0,t.length-1)+")"+(r?"":"?")},this.get=function(t,n,i){for(var a=0;a<e.length;a++)for(var s=0;s<e[a].mtch.length;s++)if(t[n]==e[a].mtch[s])return e[a].val;return void 0==i?r:i}},Bravey.Text.unique=function(e){for(var r={},t=[],n=0,i=e.length;n<i;++n)r.hasOwnProperty(e[n])||(t.push(e[n]),r[e[n]]=1);return t},Bravey.Text.clean=function(e){return Bravey.Text.removeDiacritics(e).toLowerCase().trim().replace(/ +(?= )/g,"").replace(/[()\[\]]/g,"")},Bravey.Text.pad=function(e,r,t){return t=t||"0",e+="",e.length>=r?e:new Array(r-e.length+1).join(t)+e},Bravey.Text.tokenize=function(e){var r=e.replace(/[^(a-zA-ZA-Яa-я0-9_)+\s]/g," ").trim().replace(/ +(?= )/g,"");return Bravey.Text.unique(r.split(/\s+/))},Bravey.DATA.diacriticsMap={},Bravey.Text.removeDiacritics=function(e){return e.replace(/[^\u0000-\u007E]/g,function(e){return Bravey.DATA.diacriticsMap[e]||e})},function(){defaultDiacriticsRemovalap=[{base:" ",letters:" "},{base:"0",letters:"߀"},{base:"A",letters:"ⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ"},{base:"AA",letters:"Ꜳ"},{base:"AE",letters:"ÆǼǢ"},{base:"AO",letters:"Ꜵ"},{base:"AU",letters:"Ꜷ"},{base:"AV",letters:"ꜸꜺ"},{base:"AY",letters:"Ꜽ"},{base:"B",letters:"ⒷBḂḄḆɃƁ"},{base:"C",letters:"ⒸCꜾḈĆCĈĊČÇƇȻ"},{base:"D",letters:"ⒹDḊĎḌḐḒḎĐƊƉᴅꝹ"},{base:"Dh",letters:"Ð"},{base:"DZ",letters:"DZDŽ"},{base:"Dz",letters:"DzDž"},{base:"E",letters:"ɛⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎᴇ"},{base:"F",letters:"ꝼⒻFḞƑꝻ"},{base:"G",letters:"ⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾɢ"},{base:"H",letters:"ⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ"},{base:"I",letters:"ⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ"},{base:"J",letters:"ⒿJĴɈȷ"},{base:"K",letters:"ⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ"},{base:"L",letters:"ⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ"},{base:"LJ",letters:"LJ"},{base:"Lj",letters:"Lj"},{base:"M",letters:"ⓂMḾṀṂⱮƜϻ"},{base:"N",letters:"ꞤȠⓃNǸŃÑṄŇṆŅṊṈƝꞐᴎ"},{base:"NJ",letters:"NJ"},{base:"Nj",letters:"Nj"},{base:"O",letters:"ⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ"},{base:"OE",letters:"Œ"},{base:"OI",letters:"Ƣ"},{base:"OO",letters:"Ꝏ"},{base:"OU",letters:"Ȣ"},{base:"P",letters:"ⓅPṔṖƤⱣꝐꝒꝔ"},{base:"Q",letters:"ⓆQꝖꝘɊ"},{base:"R",letters:"ⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ"},{base:"S",letters:"ⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ"},{base:"T",letters:"ⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ"},{base:"Th",letters:"Þ"},{base:"TZ",letters:"Ꜩ"},{base:"U",letters:"ⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ"},{base:"V",letters:"ⓋVṼṾƲꝞɅ"},{base:"VY",letters:"Ꝡ"},{base:"W",letters:"ⓌWẀẂŴẆẄẈⱲ"},{base:"X",letters:"ⓍXẊẌ"},{base:"Y",letters:"ⓎYỲÝŶỸȲẎŸỶỴƳɎỾ"},{base:"Z",letters:"ⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ"},{base:"a",letters:"ⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ"},{base:"aa",letters:"ꜳ"},{base:"ae",letters:"æǽǣ"},{base:"ao",letters:"ꜵ"},{base:"au",letters:"ꜷ"},{base:"av",letters:"ꜹꜻ"},{base:"ay",letters:"ꜽ"},{base:"b",letters:"ⓑbḃḅḇƀƃɓƂ"},{base:"c",letters:"cⓒćĉċčçḉƈȼꜿↄ"},{base:"d",letters:"ⓓdḋďḍḑḓḏđƌɖɗƋᏧԁꞪ"},{base:"dh",letters:"ð"},{base:"dz",letters:"dzdž"},{base:"e",letters:"ⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇǝ"},{base:"f",letters:"ⓕfḟƒ"},{base:"ff",letters:"ff"},{base:"fi",letters:"fi"},{base:"fl",letters:"fl"},{base:"ffi",letters:"ffi"},{base:"ffl",letters:"ffl"},{base:"g",letters:"ⓖgǵĝḡğġǧģǥɠꞡꝿᵹ"},{base:"h",letters:"ⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ"},{base:"hv",letters:"ƕ"},{base:"i",letters:"ⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı"},{base:"j",letters:"ⓙjĵǰɉ"},{base:"k",letters:"ⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ"},{base:"l",letters:"ⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇɭ"},{base:"lj",letters:"lj"},{base:"m",letters:"ⓜmḿṁṃɱɯ"},{base:"n",letters:"ⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ"},{base:"nj",letters:"nj"},{base:"o",letters:"ⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿꝋꝍɵɔᴑ"},{base:"oe",letters:"œ"},{base:"oi",letters:"ƣ"},{base:"oo",letters:"ꝏ"},{base:"ou",letters:"ȣ"},{base:"p",letters:"ⓟpṕṗƥᵽꝑꝓꝕρ"},{base:"q",letters:"ⓠqɋꝗꝙ"},{base:"r",letters:"ⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ"},{base:"s",letters:"ⓢsśṥŝṡšṧṣṩșşȿꞩꞅẛʂ"},{base:"ss",letters:"ß"},{base:"t",letters:"ⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ"},{base:"th",letters:"þ"},{base:"tz",letters:"ꜩ"},{base:"u",letters:"ⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ"},{base:"v",letters:"ⓥvṽṿʋꝟʌ"},{base:"vy",letters:"ꝡ"},{base:"w",letters:"ⓦwẁẃŵẇẅẘẉⱳ"},{base:"x",letters:"ⓧxẋẍ"},{base:"y",letters:"ⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ"},{base:"z",letters:"ⓩzźẑżžẓẕƶȥɀⱬꝣ"}];for(var e=0;e<defaultDiacriticsRemovalap.length;e++)for(var r=defaultDiacriticsRemovalap[e].letters,t=0;t<r.length;t++)Bravey.DATA.diacriticsMap[r[t]]=defaultDiacriticsRemovalap[e].base}(),Bravey.Date={},Bravey.Date.SECOND=1e3,Bravey.Date.MINUTE=60*Bravey.Date.SECOND,Bravey.Date.HOUR=60*Bravey.Date.MINUTE,Bravey.Date.DAY=24*Bravey.Date.HOUR,Bravey.Date.formatDate=function(e){var r=new Date(e);return Bravey.Text.pad(r.getFullYear(),4)+"-"+Bravey.Text.pad(r.getMonth()+1,2)+"-"+Bravey.Text.pad(r.getDate(),2)},Bravey.Date.formatTime=function(e){return Bravey.Text.pad(Math.floor(e/Bravey.Date.HOUR),2)+":"+Bravey.Text.pad(Math.floor(e%Bravey.Date.HOUR/Bravey.Date.MINUTE),2)+":"+Bravey.Text.pad(Math.floor(e%Bravey.Date.MINUTE/Bravey.Date.SECOND),2)},Bravey.Date.centuryFinder=function(e){return e<100?e>20?e+1900:e+2e3:e},Bravey.Data={},Bravey.Data.getEntityValue=function(e,r,t){var n;return e&&(void 0!==e.result&&void 0!==e.result.entitiesIndex&&void 0!==e.result.entitiesIndex[r]&&(n=e.result.entitiesIndex[r].value),n==t&&(n=void 0),void 0==n&&void 0!==e.sessionData&&(n=e.sessionData[r])),n},Bravey.Data.isExplicit=function(e,r){return e&&void 0!==e.result&&void 0!==e.result.entitiesIndex&&void 0!==e.result.entitiesIndex[r]},Bravey.stemmerSupport={Among:function(e,r,t,n){if(this.toCharArray=function(e){for(var r=e.length,t=new Array(r),n=0;n<r;n++)t[n]=e.charCodeAt(n);return t},!e&&""!=e||!r&&0!=r||!t)throw"Bad Among initialisation: s:"+e+", substring_i: "+r+", result: "+t;this.s_size=e.length,this.s=this.toCharArray(e),this.substring_i=r,this.result=t,this.method=n},SnowballProgram:function(){var e;return{bra:0,ket:0,limit:0,cursor:0,limit_backward:0,setCurrent:function(r){e=r,this.cursor=0,this.limit=r.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},getCurrent:function(){var r=e;return e=null,r},in_grouping:function(r,t,n){if(this.cursor<this.limit){var i=e.charCodeAt(this.cursor);if(i<=n&&i>=t&&(i-=t,r[i>>3]&1<<(7&i)))return this.cursor++,!0}return!1},in_grouping_b:function(r,t,n){if(this.cursor>this.limit_backward){var i=e.charCodeAt(this.cursor-1);if(i<=n&&i>=t&&(i-=t,r[i>>3]&1<<(7&i)))return this.cursor--,!0}return!1},out_grouping:function(r,t,n){if(this.cursor<this.limit){var i=e.charCodeAt(this.cursor);if(i>n||i<t)return this.cursor++,!0;if(i-=t,!(r[i>>3]&1<<(7&i)))return this.cursor++,!0}return!1},out_grouping_b:function(r,t,n){if(this.cursor>this.limit_backward){var i=e.charCodeAt(this.cursor-1);if(i>n||i<t)return this.cursor--,!0;if(i-=t,!(r[i>>3]&1<<(7&i)))return this.cursor--,!0}return!1},eq_s:function(r,t){if(this.limit-this.cursor<r)return!1;for(var n=0;n<r;n++)if(e.charCodeAt(this.cursor+n)!=t.charCodeAt(n))return!1;return this.cursor+=r,!0},eq_s_b:function(r,t){if(this.cursor-this.limit_backward<r)return!1;for(var n=0;n<r;n++)if(e.charCodeAt(this.cursor-r+n)!=t.charCodeAt(n))return!1;return this.cursor-=r,!0},find_among:function(r,t){for(var n=0,i=t,a=this.cursor,s=this.limit,o=0,u=0,c=!1;;){for(var l=n+(i-n>>1),f=0,g=o<u?o:u,v=r[l],d=g;d<v.s_size;d++){if(a+g==s){f=-1;break}if(f=e.charCodeAt(a+g)-v.s[d])break;g++}if(f<0?(i=l,u=g):(n=l,o=g),i-n<=1){if(n>0||i==n||c)break;c=!0}}for(;;){var v=r[n];if(o>=v.s_size){if(this.cursor=a+v.s_size,!v.method)return v.result;var m=v.method();if(this.cursor=a+v.s_size,m)return v.result}if((n=v.substring_i)<0)return 0}},find_among_b:function(r,t){for(var n=0,i=t,a=this.cursor,s=this.limit_backward,o=0,u=0,c=!1;;){for(var l=n+(i-n>>1),f=0,g=o<u?o:u,v=r[l],d=v.s_size-1-g;d>=0;d--){if(a-g==s){f=-1;break}if(f=e.charCodeAt(a-1-g)-v.s[d])break;g++}if(f<0?(i=l,u=g):(n=l,o=g),i-n<=1){if(n>0||i==n||c)break;c=!0}}for(;;){var v=r[n];if(o>=v.s_size){if(this.cursor=a-v.s_size,!v.method)return v.result;var m=v.method();if(this.cursor=a-v.s_size,m)return v.result}if((n=v.substring_i)<0)return 0}},replace_s:function(r,t,n){var i=n.length-(t-r),a=e.substring(0,r),s=e.substring(t);return e=a+n+s,this.limit+=i,this.cursor>=t?this.cursor+=i:this.cursor>r&&(this.cursor=r),i},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>e.length)throw"faulty slice operation"},slice_from:function(e){this.slice_check(),this.replace_s(this.bra,this.ket,e)},slice_del:function(){this.slice_from("")},insert:function(e,r,t){var n=this.replace_s(e,r,t);e<=this.bra&&(this.bra+=n),e<=this.ket&&(this.ket+=n)},slice_to:function(){return this.slice_check(),e.substring(this.bra,this.ket)},eq_v_b:function(e){return this.eq_s_b(e.length,e)}}}},Bravey.FreeTextEntityRecognizer=function(e,r){var t=/\"([^\"]*)\"/,n=[],i=[];this.getName=function(){return e},this.addPrefix=function(e){-1==n.indexOf(e)&&n.push(e)},this.addConjunction=function(e){i.push(new RegExp("^\\b"+e+"\\b","gi")),i.push(new RegExp("\\b"+e+"\\b$","gi"))},this.getEntities=function(e,r){return r},this.expand=function(e){var r,a,s=-1,o=-1;if(null!=(a=t.exec(e.string)))e.position+=a.index+1,e.string=a[1];else{for(var u=0;u<n.length;u++)-1!=(r=e.string.indexOf(n[u]))&&(-1==o||r<o)&&(o=r,s=r+n[u].length);-1!=s&&(e.position+=s,e.string=e.string.substr(s)),Bravey.Text.entityTrim(e);do{o=0;for(var u=0;u<i.length;u++)null!=(a=i[u].exec(e.string))&&(o=1,0==a.index?(e.string=e.string.substr(a[0].length),e.position+=a[0].length):e.string=e.string.substr(0,a.index),Bravey.Text.entityTrim(e))}while(o);-1!=(r=e.string.lastIndexOf("."))&&(e.string=e.string.substr(0,r)),Bravey.Text.entityTrim(e)}e.value=e.string}},Bravey.StringEntityRecognizer=function(e,r){function t(){n.sort(function(e,r){return e.text.length>r.text.length?-1:e.text.length<r.text.length?1:0})}var n=[],i={},a=!1;this.getName=function(){return e},this.addMatch=function(e,r){return r=Bravey.Text.clean(r),i[r]||(i[r]=1,a=!1,n.push({text:r,id:e,regex:new RegExp("\\b"+r+"\\b","gi")})),!0},this.getEntities=function(i,s){i=Bravey.Text.clean(i),a||(a=!0,t());var o,u;s||(s=[]);for(var c,l=i,f=0;f<n.length;f++)for(;null!=(u=n[f].regex.exec(l));){o=i.substr(u.index,u[0].length),s.push({position:u.index,entity:e,value:n[f].id,string:o,priority:r||0}),c=l.substr(0,u.index);for(var g=0;g<u[0].length;g++)c+=" ";c+=l.substr(u.index+u[0].length),l=c}return s}},Bravey.NumberEntityRecognizer=function(e){var r=new RegExp("\\b[0-9]+\\b","gi");this.getName=function(){return e},this.getEntities=function(t,n){t=Bravey.Text.clean(t);var i,a;n||(n=[]);for(var s=t;null!=(a=r.exec(s));)i=t.substr(a.index,a[0].length),n.push({position:a.index,entity:e,value:1*i,string:i});return n}},Bravey.RegexEntityRecognizer=function(e){function r(e){e.sort(function(e,r){return e.position<r.position?-1:e.position>r.position?1:e.string.length>r.string.length?-1:e.string.length<r.string.length?1:e.priority>r.priority?-1:e.priority<r.priority?1:0})}var t=[];this.addMatch=function(e,r,n){t.push({regex:e,callback:r,priority:n||0})},this.getName=function(){return e},this.getEntities=function(n,i){n=Bravey.Text.clean(n);var a,s,o,u=[],c=-1;i||(i=[]);for(var l=n,f=0;f<t.length;f++)for(;null!=(o=t[f].regex.exec(l));)s=n.substr(o.index,o[0].length),void 0!==(a=t[f].callback(o))&&u.push(Bravey.Text.entityTrim({value:a,entity:e,position:o.index,string:s,priority:t[f].priority}));r(u);for(var f=0;f<u.length;f++)u[f].position>=c&&(i.push(u[f]),c=u[f].position+u[f].string.length);return i},this.bindTo=function(e){var r=this;e.getName=function(){return r.getName()},e.getEntities=function(e,t){return r.getEntities(e,t)}}},Bravey.EMailEntityRecognizer=function(e,r){var t=/(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g;this.getName=function(){return e},this.getEntities=function(n,i){var a,s;for(i||(i=[]);null!=(s=t.exec(n));)a=n.substr(s.index,s[0].length),i.push({position:s.index,entity:e,value:a,string:a,priority:r||0});return i}},Bravey.DocumentClassifier=function(e){e=e||{};var r={},t=function(e,r){return"stem:"+e+"::label:"+r},n=function(e){return"docCount:"+e},i=function(e){return"stemCount:"+e},a=function(e){},s=function(){var e=r.registeredLabels;return e||(e=""),e.split(",").filter(function(e){return e.length})},o=function(e){var t=s();return-1===t.indexOf(e)&&(t.push(e),r.registeredLabels=t.join(",")),!0},u=function(e,n){var i=parseInt(r[t(e,n)]);return i||(i=0),i},c=function(e,r){for(var t=s(),n=0,i=0,a=t.length;i<a;i++)t[i]!==r&&(n+=parseInt(u(e,t[i])));return n},l=function(e){var t=parseInt(r[i(e)]);return t||(t=0),t},f=function(e){var t=parseInt(r[n(e)]);return t||(t=0),t},g=function(e){for(var r=s(),t=0,n=0,i=r.length;n<i;n++)r[n]!==e&&(t+=parseInt(f(r[n])));return t},v=function(e){var t=parseInt(r[e]);return t||(t=0),r[e]=parseInt(t)+1,t+1},d=function(e,r){v(i(e)),v(t(e,r))},m=function(e){return v(n(e))},b=function(r,t){o(t);var n=Bravey.Text.tokenize(Bravey.Text.clean(r));e.filter&&(n=e.filter(n));for(var i=n.length,a=0;a<i;a++)d(e.stemmer?e.stemmer(n[a]):n[a],t);m(t)},h=function(r){var t=Bravey.Text.tokenize(Bravey.Text.clean(r));e.filter&&(t=e.filter(t));for(var n=t.length,i=s(),o=0,v={},d={},m={},b={},h=0;h<i.length;h++){var w=i[h];v[w]=f(w),d[w]=g(w),o+=parseInt(v[w])}for(var h=0;h<i.length;h++){var w=i[h],y=0;b[w]=v[w]/o;for(var p=0;p<n;p++){var x=e.stemmer?e.stemmer(t[p]):t[p],_=l(x);if(0!==_){var B=u(x,w)/v[w],D=c(x,w)/d[w],T=B/(B+D);T=(.5+_*T)/(1+_),0===T?T=.01:1===T&&(T=.99),y+=Math.log(1-T)-Math.log(T),a(w+"icity of "+x+": "+T)}}m[w]=1/(1+Math.exp(y))}return m},w=function(e){var r=0,t=null;for(var n in e)e[n]>r&&(r=e[n],t=n);return{label:t,score:r}};this.addDocument=function(e,r){return b(e,r),e},this.classifyDocument=function(e){var r=h(e);return{scores:r,winner:w(r)}},this.addDocument("","none")},Bravey.Language.IT={},Bravey.Language.IT.Stemmer=function(){var e=Bravey.stemmerSupport.Among,r=Bravey.stemmerSupport.SnowballProgram,t=new function(){function t(e,r,t){return!(!M.eq_s(1,e)||(M.ket=M.cursor,!M.in_grouping(S,97,249)))&&(M.slice_from(r),M.cursor=t,!0)}function n(){for(var e,r,n,i,a=M.cursor;;){if(M.bra=M.cursor,e=M.find_among(x,7))switch(M.ket=M.cursor,e){case 1:M.slice_from("à");continue;case 2:M.slice_from("è");continue;case 3:M.slice_from("ì");continue;case 4:M.slice_from("ò");continue;case 5:M.slice_from("ù");continue;case 6:M.slice_from("qU");continue;case 7:if(M.cursor>=M.limit)break;M.cursor++;continue}break}for(M.cursor=a;;)for(r=M.cursor;;){if(n=M.cursor,M.in_grouping(S,97,249)){if(M.bra=M.cursor,i=M.cursor,t("u","U",n))break;if(M.cursor=i,t("i","I",n))break}if(M.cursor=n,M.cursor>=M.limit)return void(M.cursor=r);M.cursor++}}function i(e){if(M.cursor=e,!M.in_grouping(S,97,249))return!1;for(;!M.out_grouping(S,97,249);){if(M.cursor>=M.limit)return!1;M.cursor++}return!0}function a(){if(M.in_grouping(S,97,249)){var e=M.cursor;if(M.out_grouping(S,97,249)){for(;!M.in_grouping(S,97,249);){if(M.cursor>=M.limit)return i(e);M.cursor++}return!0}return i(e)}return!1}function s(){var e,r=M.cursor;if(!a()){if(M.cursor=r,!M.out_grouping(S,97,249))return;if(e=M.cursor,M.out_grouping(S,97,249)){for(;!M.in_grouping(S,97,249);){if(M.cursor>=M.limit)return M.cursor=e,void(M.in_grouping(S,97,249)&&M.cursor<M.limit&&M.cursor++);M.cursor++}return void(p=M.cursor)}if(M.cursor=e,!M.in_grouping(S,97,249)||M.cursor>=M.limit)return;M.cursor++}p=M.cursor}function o(){for(;!M.in_grouping(S,97,249);){if(M.cursor>=M.limit)return!1;M.cursor++}for(;!M.out_grouping(S,97,249);){if(M.cursor>=M.limit)return!1;M.cursor++}return!0}function u(){var e=M.cursor;p=M.limit,y=p,w=p,s(),M.cursor=e,o()&&(y=M.cursor,o()&&(w=M.cursor))}function c(){for(var e;;){if(M.bra=M.cursor,!(e=M.find_among(_,3)))break;switch(M.ket=M.cursor,e){case 1:M.slice_from("i");break;case 2:M.slice_from("u");break;case 3:if(M.cursor>=M.limit)return;M.cursor++}}}function l(){return p<=M.cursor}function f(){return y<=M.cursor}function g(){return w<=M.cursor}function v(){var e;if(M.ket=M.cursor,M.find_among_b(B,37)&&(M.bra=M.cursor,(e=M.find_among_b(D,5))&&l()))switch(e){case 1:M.slice_del();break;case 2:M.slice_from("e")}}function d(){var e;if(M.ket=M.cursor,!(e=M.find_among_b(E,51)))return!1;switch(M.bra=M.cursor,e){case 1:if(!g())return!1;M.slice_del();break;case 2:if(!g())return!1;M.slice_del(),M.ket=M.cursor,M.eq_s_b(2,"ic")&&(M.bra=M.cursor,g()&&M.slice_del());break;case 3:if(!g())return!1;M.slice_from("log");break;case 4:if(!g())return!1;M.slice_from("u");break;case 5:if(!g())return!1;M.slice_from("ente");break;case 6:if(!l())return!1;M.slice_del();break;case 7:if(!f())return!1;M.slice_del(),M.ket=M.cursor,e=M.find_among_b(T,4),e&&(M.bra=M.cursor,g()&&(M.slice_del(),1==e&&(M.ket=M.cursor,M.eq_s_b(2,"at")&&(M.bra=M.cursor,g()&&M.slice_del()))));break;case 8:if(!g())return!1;M.slice_del(),M.ket=M.cursor,e=M.find_among_b(k,3),e&&(M.bra=M.cursor,1==e&&g()&&M.slice_del());break;case 9:if(!g())return!1;M.slice_del(),M.ket=M.cursor,M.eq_s_b(2,"at")&&(M.bra=M.cursor,g()&&(M.slice_del(),M.ket=M.cursor,M.eq_s_b(2,"ic")&&(M.bra=M.cursor,g()&&M.slice_del())))}return!0}function m(){var e,r;M.cursor>=p&&(r=M.limit_backward,M.limit_backward=p,M.ket=M.cursor,e=M.find_among_b(R,87),e&&(M.bra=M.cursor,1==e&&M.slice_del()),M.limit_backward=r)}function b(){var e=M.limit-M.cursor;if(M.ket=M.cursor,M.in_grouping_b(C,97,242)&&(M.bra=M.cursor,l()&&(M.slice_del(),M.ket=M.cursor,M.eq_s_b(1,"i")&&(M.bra=M.cursor,l()))))return void M.slice_del();M.cursor=M.limit-e}function h(){b(),M.ket=M.cursor,M.eq_s_b(1,"h")&&(M.bra=M.cursor,M.in_grouping_b(z,99,103)&&l()&&M.slice_del())}var w,y,p,x=[new e("",-1,7),new e("qu",0,6),new e("á",0,1),new e("é",0,2),new e("í",0,3),new e("ó",0,4),new e("ú",0,5)],_=[new e("",-1,3),new e("I",0,1),new e("U",0,2)],B=[new e("la",-1,-1),new e("cela",0,-1),new e("gliela",0,-1),new e("mela",0,-1),new e("tela",0,-1),new e("vela",0,-1),new e("le",-1,-1),new e("cele",6,-1),new e("gliele",6,-1),new e("mele",6,-1),new e("tele",6,-1),new e("vele",6,-1),new e("ne",-1,-1),new e("cene",12,-1),new e("gliene",12,-1),new e("mene",12,-1),new e("sene",12,-1),new e("tene",12,-1),new e("vene",12,-1),new e("ci",-1,-1),new e("li",-1,-1),new e("celi",20,-1),new e("glieli",20,-1),new e("meli",20,-1),new e("teli",20,-1),new e("veli",20,-1),new e("gli",20,-1),new e("mi",-1,-1),new e("si",-1,-1),new e("ti",-1,-1),new e("vi",-1,-1),new e("lo",-1,-1),new e("celo",31,-1),new e("glielo",31,-1),new e("melo",31,-1),new e("telo",31,-1),new e("velo",31,-1)],D=[new e("ando",-1,1),new e("endo",-1,1),new e("ar",-1,2),new e("er",-1,2),new e("ir",-1,2)],T=[new e("ic",-1,-1),new e("abil",-1,-1),new e("os",-1,-1),new e("iv",-1,1)],k=[new e("ic",-1,1),new e("abil",-1,1),new e("iv",-1,1)],E=[new e("ica",-1,1),new e("logia",-1,3),new e("osa",-1,1),new e("ista",-1,1),new e("iva",-1,9),new e("anza",-1,1),new e("enza",-1,5),new e("ice",-1,1),new e("atrice",7,1),new e("iche",-1,1),new e("logie",-1,3),new e("abile",-1,1),new e("ibile",-1,1),new e("usione",-1,4),new e("azione",-1,2),new e("uzione",-1,4),new e("atore",-1,2),new e("ose",-1,1),new e("ante",-1,1),new e("mente",-1,1),new e("amente",19,7),new e("iste",-1,1),new e("ive",-1,9),new e("anze",-1,1),new e("enze",-1,5),new e("ici",-1,1),new e("atrici",25,1),new e("ichi",-1,1),new e("abili",-1,1),new e("ibili",-1,1),new e("ismi",-1,1),new e("usioni",-1,4),new e("azioni",-1,2),new e("uzioni",-1,4),new e("atori",-1,2),new e("osi",-1,1),new e("anti",-1,1),new e("amenti",-1,6),new e("imenti",-1,6),new e("isti",-1,1),new e("ivi",-1,9),new e("ico",-1,1),new e("ismo",-1,1),new e("oso",-1,1),new e("amento",-1,6),new e("imento",-1,6),new e("ivo",-1,9),new e("ità",-1,8),new e("istà",-1,1),new e("istè",-1,1),new e("istì",-1,1)],R=[new e("isca",-1,1),new e("enda",-1,1),new e("ata",-1,1),new e("ita",-1,1),new e("uta",-1,1),new e("ava",-1,1),new e("eva",-1,1),new e("iva",-1,1),new e("erebbe",-1,1),new e("irebbe",-1,1),new e("isce",-1,1),new e("ende",-1,1),new e("are",-1,1),new e("ere",-1,1),new e("ire",-1,1),new e("asse",-1,1),new e("ate",-1,1),new e("avate",16,1),new e("evate",16,1),new e("ivate",16,1),new e("ete",-1,1),new e("erete",20,1),new e("irete",20,1),new e("ite",-1,1),new e("ereste",-1,1),new e("ireste",-1,1),new e("ute",-1,1),new e("erai",-1,1),new e("irai",-1,1),new e("isci",-1,1),new e("endi",-1,1),new e("erei",-1,1),new e("irei",-1,1),new e("assi",-1,1),new e("ati",-1,1),new e("iti",-1,1),new e("eresti",-1,1),new e("iresti",-1,1),new e("uti",-1,1),new e("avi",-1,1),new e("evi",-1,1),new e("ivi",-1,1),new e("isco",-1,1),new e("ando",-1,1),new e("endo",-1,1),new e("Yamo",-1,1),new e("iamo",-1,1),new e("avamo",-1,1),new e("evamo",-1,1),new e("ivamo",-1,1),new e("eremo",-1,1),new e("iremo",-1,1),new e("assimo",-1,1),new e("ammo",-1,1),new e("emmo",-1,1),new e("eremmo",54,1),new e("iremmo",54,1),new e("immo",-1,1),new e("ano",-1,1),new e("iscano",58,1),new e("avano",58,1),new e("evano",58,1),new e("ivano",58,1),new e("eranno",-1,1),new e("iranno",-1,1),new e("ono",-1,1),new e("iscono",65,1),new e("arono",65,1),new e("erono",65,1),new e("irono",65,1),new e("erebbero",-1,1),new e("irebbero",-1,1),new e("assero",-1,1),new e("essero",-1,1),new e("issero",-1,1),new e("ato",-1,1),new e("ito",-1,1),new e("uto",-1,1),new e("avo",-1,1),new e("evo",-1,1),new e("ivo",-1,1),new e("ar",-1,1),new e("ir",-1,1),new e("erà",-1,1),new e("irà",-1,1),new e("erò",-1,1),new e("irò",-1,1)],S=[17,65,16,0,0,0,0,0,0,0,0,0,0,0,0,128,128,8,2,1],C=[17,65,0,0,0,0,0,0,0,0,0,0,0,0,0,128,128,8,2],z=[17],M=new r;this.setCurrent=function(e){M.setCurrent(e)},this.getCurrent=function(){return M.getCurrent()},this.stem=function(){var e=M.cursor;return n(),M.cursor=e,u(),M.limit_backward=e,M.cursor=M.limit,v(),M.cursor=M.limit,d()||(M.cursor=M.limit,m()),M.cursor=M.limit,h(),M.cursor=M.limit_backward,c(),!0}};return function(e){return t.setCurrent(e),t.stem(),t.getCurrent()}}(),Bravey.Language.IT.TimeEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t=new Bravey.Text.RegexMap([{str:["meno un quarto~"],val:-45*Bravey.Date.MINUTE},{str:["meno venti~"," meno 20"],val:-20*Bravey.Date.MINUTE},{str:["meno un quarto~"],val:-15*Bravey.Date.MINUTE},{str:["mezza~","trenta"],val:30*Bravey.Date.MINUTE},{str:["venti~"],val:30*Bravey.Date.MINUTE},{str:["un quarto~","quindici~","un quarto~"],val:15*Bravey.Date.MINUTE}],0),n=new Bravey.Text.RegexMap([{str:["di mattina~","del mattino~","am~","antimeridiane~"],val:0},{str:["di pomeriggio~","del pomeriggio~","di sera~","della sera~","pomeridiane~","pm~"],val:12*Bravey.Date.HOUR}],0);r.addMatch(new RegExp("\\b(per le\\b|l\\b|alle\\b|la\\b|le\\b)?"+Bravey.Text.WORDSEP+"(ore\\b)?"+Bravey.Text.WORDSEP+"([0-9]+)"+Bravey.Text.WORDSEP+"(e\\b|:\\b)?"+Bravey.Text.WORDSEP+"([0-9]+)?"+Bravey.Text.WORDSEP+t.regex()+Bravey.Text.WORDSEP+"( minuti)?"+Bravey.Text.WORDSEP+n.regex()+"\\b","gi"),function(e){var r=1*e[3]*Bravey.Date.HOUR;if(e[4]&&e[5]&&(r+=1*e[5]*Bravey.Date.MINUTE),r+=t.get(e,6),r+=n.get(e,8),Bravey.Text.calculateScore(e,[1,2,5,6,7,8]))return Bravey.Date.formatTime(r)}),r.bindTo(this)},Bravey.Language.IT.TimePeriodEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t=new Bravey.Text.RegexMap([{str:["secondo~","secondi~"],val:Bravey.Date.SECOND},{str:["minuti~","minuto~"],val:Bravey.Date.MINUTE},{str:["ore~","ora~"],val:Bravey.Date.HOUR}],0);r.addMatch(new RegExp("\\b(entro\\b|tra\\b|in\\b)"+Bravey.Text.WORDSEP+"([0-9]+)"+Bravey.Text.WORDSEP+t.regex(1),"gi"),function(e){var r,n,i=new Date;if(r=n=i.getHours()*Bravey.Date.HOUR+i.getMinutes()*Bravey.Date.MINUTE,n+=e[2]*t.get(e,3),Bravey.Text.calculateScore(e,[1,3]))return{start:Bravey.Date.formatTime(r),end:Bravey.Date.formatTime(n)}}),r.addMatch(new RegExp("\\b(di sera|della sera|in serata|nella serata|la sera|sera|stasera)\\b","gi"),function(e){return{start:"12:00:00",end:"23:59:00"}}),r.addMatch(new RegExp("\\b(di pomeriggio|del pomeriggio|nel pomeriggio|il pomeriggio|pomeriggio)\\b","gi"),function(e){return{start:"15:00:00",end:"23:59:00"}}),r.addMatch(new RegExp("\\b(di mattina|del mattino|in mattinata|della mattinata|la mattinata|mattina|stamattina)\\b","gi"),function(e){return{start:"08:00:00",end:"12:00:00"}}),r.bindTo(this)},Bravey.Language.IT.DateEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t="\\b(per il\\b|di\\b|nel giorno di\\b|nella giornata di\\b|la giornata di\\b|il\\b|nel\\b|lo scorso\\b)?"+Bravey.Text.WORDSEP,n=new Bravey.Text.RegexMap([{str:["gennaio~","gen~","1~","01~"],val:0},{str:["febbraio~","feb~","2~","02~"],val:1},{str:["marzo~","mar~","3~","03~"],val:2},{str:["aprile~","apr~","4~","04~"],val:3},{str:["maggio~","mag~","5~","05~"],val:4},{str:["giugno~","giu~","6~","06~"],val:5},{str:["luglio~","lug~","7~","07~"],val:6},{str:["agosto~","ago~","8~","08~"],val:7},{str:["settembre~","set~","sept~","9~","09~"],val:8},{str:["ottobre~","ott~","10~"],val:9},{str:["novembre~","nov~","11~"],val:10},{str:["dicembre~","dic~","12~"],val:11}],0);r.addMatch(new RegExp(t+"([0-9]{1,2})"+Bravey.Text.WORDSEP+"(di\\b|,\\b|/\\b|-\\b|\\b)"+Bravey.Text.WORDSEP+n.regex()+Bravey.Text.WORDSEP+"(del\\b|dell'\\b|nel\\b|,\\b|/\\b|-\\b)?"+Bravey.Text.WORDSEP+"([0-9]{2,4})?\\b","gi"),function(e){var r=new Date,t=r.getFullYear(),i=r.getMonth(),a=r.getDate();if(a=1*e[2],i=n.get(e,4,i),e[6]&&(t=1*e[6]),t=Bravey.Date.centuryFinder(t),Bravey.Text.calculateScore(e,[1,4,6]))return Bravey.Date.formatDate(new Date(t,i,a,0,0,0,0).getTime())},10),r.addMatch(new RegExp(t+n.regex(1)+Bravey.Text.WORDSEP+"([0-9]{1,2})?"+Bravey.Text.WORDSEP+"(del\\b|dell'\\b|,\\b)?"+Bravey.Text.WORDSEP+"([0-9]{2,4})?\\b","gi"),function(e){var r=new Date,t=r.getFullYear(),i=r.getMonth(),a=1;if(i=n.get(e,2,i),e[3]&&(a=1*e[3]),e[5]&&(t=1*e[5]),t=Bravey.Date.centuryFinder(t),Bravey.Text.calculateScore(e,[1,3,4]))return Bravey.Date.formatDate(new Date(t,i,a,0,0,0,0).getTime())},5),t="\\b(per\\b|di\\b|nel giorno di\\b|nella giornata di\\b|la giornata di\\b|lo scorso\\b)?"+Bravey.Text.WORDSEP,r.addMatch(new RegExp(t+"(oggi)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime())}),r.addMatch(new RegExp(t+"(domani)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()+Bravey.Date.DAY)}),r.addMatch(new RegExp(t+"(dopodomani)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()+2*Bravey.Date.DAY)}),r.addMatch(new RegExp(t+"(ieri)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()-Bravey.Date.DAY)}),r.addMatch(new RegExp(t+"(l'altro ieri|ieri l'altro)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()-2*Bravey.Date.DAY)}),r.bindTo(this)},Bravey.Language.IT.FreeTextEntityRecognizer=function(e,r){var t=["grazie","per favore"],n=new Bravey.FreeTextEntityRecognizer(e,r);n.addConjunction("il"),n.addConjunction("lo"),n.addConjunction("la"),n.addConjunction("i"),n.addConjunction("gli"),n.addConjunction("le"),n.addConjunction("è"),n.addConjunction("é"),n.addConjunction("e"),n.addConjunction("ed"),n.addConjunction("e'"),n.addConjunction("sia"),n.addConjunction("mi pare"),n.addConjunction("dovrebbe essere"),n.addConjunction("sarebbe");for(var i=0;i<t.length;i++)n.addConjunction(t[i]),n.addConjunction(","+t[i]),n.addConjunction(", "+t[i]);return n},Bravey.Language.IT.Numbers=[{prefix:"zero",value:0},{prefix:"vent",value:20},{prefix:"trent",value:30},{prefix:"quarant",value:40},{prefix:"cinquant",value:50},{prefix:"sessant",value:60},{prefix:"settant",value:70},{prefix:"ottant",value:80},{prefix:"novant",value:90},{prefix:"uno",value:1},{prefix:"quattro",value:4},{prefix:"quattor",value:4},{prefix:"cinque",value:5},{prefix:"quin",value:5},{prefix:"sei",value:6},{prefix:"sette",value:7},{prefix:"otto",value:8},{prefix:"nove",value:9},{prefix:"dieci",value:10},{prefix:"dici",value:10},{prefix:"se",value:6},{prefix:"un",value:1},{prefix:"due",value:2},{prefix:"do",value:2},{prefix:"tre",value:3},{prefix:"a",skip:1},{prefix:"tor",skip:1},{prefix:"i",skip:1},{prefix:"n",skip:1},{prefix:"s",skip:1},{prefix:"cento",mul:100},{prefix:"mila",mul:1e3,end:1},{prefix:"mille",mul:1e3,end:1},{prefix:"milion",mul:1e6,end:1},{prefix:"miliard",mul:1e9,end:1},{prefix:"e",skip:1},{prefix:"i",skip:1},{prefix:"o",skip:1}],Bravey.Language.IT.NumberEntityRecognizer=function(e,r){var t=new RegExp("^[0-9]+$","gi"),n=new Bravey.RegexEntityRecognizer(e);return n.addMatch(new RegExp("(\\w+)","gi"),function(e){var r,n,i=e[0].toLowerCase(),a=0,s=0,o=9990,u=!1;if(i.match(t))return 1*i;do{r=!1;for(var c=0;c<Bravey.Language.IT.Numbers.length&&(n=Bravey.Language.IT.Numbers[c],i.substr(0,n.prefix.length)!=n.prefix||(i=i.substr(n.prefix.length),n.skip?r=!0:(o?n.end?(c<o&&(a+=s,s=0),o=c):(a+=s,s=0,o=0):n.end&&(o=c),void 0!==n.value&&(s+=n.value,r=!0,u=!0),void 0!==n.mul&&(s?s*=n.mul:s=n.mul,r=!0,u=!0)),!r));c++);}while(r);return a+=s,!i&&u?a:void 0}),n},Bravey.Language.EN={},Bravey.Language.EN.Stemmer=function(){var e=Bravey.stemmerSupport.Among,r=Bravey.stemmerSupport.SnowballProgram,t=new function(){function t(){var e,r=I.cursor;for(w=!1,I.bra=I.cursor,I.eq_s(1,"'")&&(I.ket=I.cursor,I.slice_del()),I.cursor=r,I.bra=r,I.eq_s(1,"y")&&(I.ket=I.cursor,I.slice_from("Y"),w=!0),I.cursor=r;;)if(e=I.cursor,I.in_grouping(M,97,121)&&(I.bra=I.cursor,I.eq_s(1,"y")))I.ket=I.cursor,I.cursor=e,I.slice_from("Y"),w=!0;else{if(e>=I.limit)return void(I.cursor=r);I.cursor=e+1}}function n(){var e=I.cursor;if(p=I.limit,y=p,!I.find_among(x,3)&&(I.cursor=e,i()))return void(I.cursor=e);p=I.cursor,i()||(y=I.cursor)}function i(){for(;!I.in_grouping(M,97,121);){if(I.cursor>=I.limit)return!0;I.cursor++}for(;!I.out_grouping(M,97,121);){if(I.cursor>=I.limit)return!0;I.cursor++}return!1}function a(){var e=I.limit-I.cursor;return!(!(I.out_grouping_b(O,89,121)&&I.in_grouping_b(M,97,121)&&I.out_grouping_b(M,97,121))&&(I.cursor=I.limit-e,!I.out_grouping_b(M,97,121)||!I.in_grouping_b(M,97,121)||I.cursor>I.limit_backward))}function s(){return p<=I.cursor}function o(){return y<=I.cursor}function u(){var e,r=I.limit-I.cursor;if(I.ket=I.cursor,e=I.find_among_b(_,3),e?(I.bra=I.cursor,1==e&&I.slice_del()):I.cursor=I.limit-r,I.ket=I.cursor,e=I.find_among_b(B,6))switch(I.bra=I.cursor,e){case 1:I.slice_from("ss");break;case 2:var t=I.cursor-2;if(I.limit_backward>t||t>I.limit){I.slice_from("ie");break}I.cursor=t,I.slice_from("i");break;case 3:do{if(I.cursor<=I.limit_backward)return;I.cursor--}while(!I.in_grouping_b(M,97,121));I.slice_del()}}function c(){var e,r,t,n;if(I.ket=I.cursor,e=I.find_among_b(T,6))switch(I.bra=I.cursor,e){case 1:s()&&I.slice_from("ee");break;case 2:for(r=I.limit-I.cursor;!I.in_grouping_b(M,97,121);){if(I.cursor<=I.limit_backward)return;I.cursor--}if(I.cursor=I.limit-r,I.slice_del(),t=I.limit-I.cursor,e=I.find_among_b(D,13))switch(I.cursor=I.limit-t,e){case 1:var i=I.cursor;I.insert(I.cursor,I.cursor,"e"),I.cursor=i;break;case 2:I.ket=I.cursor,I.cursor>I.limit_backward&&(I.cursor--,I.bra=I.cursor,I.slice_del());break;case 3:if(I.cursor==p&&(n=I.limit-I.cursor,a())){I.cursor=I.limit-n;var i=I.cursor;I.insert(I.cursor,I.cursor,"e"),I.cursor=i}}}}function l(){var e=I.limit-I.cursor;I.ket=I.cursor,(I.eq_s_b(1,"y")||(I.cursor=I.limit-e,I.eq_s_b(1,"Y")))&&(I.bra=I.cursor,I.out_grouping_b(M,97,121)&&I.cursor>I.limit_backward&&I.slice_from("i"))}function f(){var e;if(I.ket=I.cursor,(e=I.find_among_b(k,24))&&(I.bra=I.cursor,s()))switch(e){case 1:I.slice_from("tion");break;case 2:I.slice_from("ence");break;case 3:I.slice_from("ance");break;case 4:I.slice_from("able");break;case 5:I.slice_from("ent");break;case 6:I.slice_from("ize");break;case 7:I.slice_from("ate");break;case 8:I.slice_from("al");break;case 9:I.slice_from("ful");break;case 10:I.slice_from("ous");break;case 11:I.slice_from("ive");break;case 12:I.slice_from("ble");break;case 13:I.eq_s_b(1,"l")&&I.slice_from("og");break;case 14:I.slice_from("ful");break;case 15:I.slice_from("less");break;case 16:I.in_grouping_b(N,99,116)&&I.slice_del()}}function g(){var e;if(I.ket=I.cursor,(e=I.find_among_b(E,9))&&(I.bra=I.cursor,s()))switch(e){case 1:I.slice_from("tion");break;case 2:I.slice_from("ate");break;case 3:I.slice_from("al");break;case 4:I.slice_from("ic");break;case 5:I.slice_del();break;case 6:o()&&I.slice_del()}}function v(){var e,r;if(I.ket=I.cursor,(e=I.find_among_b(R,18))&&(I.bra=I.cursor,o()))switch(e){case 1:I.slice_del();break;case 2:if(r=I.limit-I.cursor,!I.eq_s_b(1,"s")&&(I.cursor=I.limit-r,!I.eq_s_b(1,"t")))return;I.slice_del()}}function d(){var e,r;if(I.ket=I.cursor,e=I.find_among_b(S,2))switch(I.bra=I.cursor,e){case 1:if(r=I.limit-I.cursor,!o()){if(I.cursor=I.limit-r,!s()||a())return;I.cursor=I.limit-r}I.slice_del();break;case 2:if(!o()||!I.eq_s_b(1,"l"))return;I.slice_del()}}function m(){return I.ket=I.cursor,!!I.find_among_b(C,8)&&(I.bra=I.cursor,I.cursor<=I.limit_backward)}function b(){var e;if(I.bra=I.cursor,(e=I.find_among(z,18))&&(I.ket=I.cursor,I.cursor>=I.limit)){switch(e){case 1:I.slice_from("ski");break;case 2:I.slice_from("sky");break;case 3:I.slice_from("die");break;case 4:I.slice_from("lie");break;case 5:I.slice_from("tie");break;case 6:I.slice_from("idl");break;case 7:I.slice_from("gentl");break;case 8:I.slice_from("ugli");break;case 9:I.slice_from("earli");break;case 10:I.slice_from("onli");break;case 11:I.slice_from("singl")}return!0}return!1}function h(){var e;if(w)for(;;)if(e=I.cursor,I.bra=e,I.eq_s(1,"Y"))I.ket=I.cursor,I.cursor=e,I.slice_from("y");else{if(I.cursor=e,I.cursor>=I.limit)return;I.cursor++}}var w,y,p,x=[new e("arsen",-1,-1),new e("commun",-1,-1),new e("gener",-1,-1)],_=[new e("'",-1,1),new e("'s'",0,1),new e("'s",-1,1)],B=[new e("ied",-1,2),new e("s",-1,3),new e("ies",1,2),new e("sses",1,1),new e("ss",1,-1),new e("us",1,-1)],D=[new e("",-1,3),new e("bb",0,2),new e("dd",0,2),new e("ff",0,2),new e("gg",0,2),new e("bl",0,1),new e("mm",0,2),new e("nn",0,2),new e("pp",0,2),new e("rr",0,2),new e("at",0,1),new e("tt",0,2),new e("iz",0,1)],T=[new e("ed",-1,2),new e("eed",0,1),new e("ing",-1,2),new e("edly",-1,2),new e("eedly",3,1),new e("ingly",-1,2)],k=[new e("anci",-1,3),new e("enci",-1,2),new e("ogi",-1,13),new e("li",-1,16),new e("bli",3,12),new e("abli",4,4),new e("alli",3,8),new e("fulli",3,14),new e("lessli",3,15),new e("ousli",3,10),new e("entli",3,5),new e("aliti",-1,8),new e("biliti",-1,12),new e("iviti",-1,11),new e("tional",-1,1),new e("ational",14,7),new e("alism",-1,8),new e("ation",-1,7),new e("ization",17,6),new e("izer",-1,6),new e("ator",-1,7),new e("iveness",-1,11),new e("fulness",-1,9),new e("ousness",-1,10)],E=[new e("icate",-1,4),new e("ative",-1,6),new e("alize",-1,3),new e("iciti",-1,4),new e("ical",-1,4),new e("tional",-1,1),new e("ational",5,2),new e("ful",-1,5),new e("ness",-1,5)],R=[new e("ic",-1,1),new e("ance",-1,1),new e("ence",-1,1),new e("able",-1,1),new e("ible",-1,1),new e("ate",-1,1),new e("ive",-1,1),new e("ize",-1,1),new e("iti",-1,1),new e("al",-1,1),new e("ism",-1,1),new e("ion",-1,2),new e("er",-1,1),new e("ous",-1,1),new e("ant",-1,1),new e("ent",-1,1),new e("ment",15,1),new e("ement",16,1)],S=[new e("e",-1,1),new e("l",-1,2)],C=[new e("succeed",-1,-1),new e("proceed",-1,-1),new e("exceed",-1,-1),new e("canning",-1,-1),new e("inning",-1,-1),new e("earring",-1,-1),new e("herring",-1,-1),new e("outing",-1,-1)],z=[new e("andes",-1,-1),new e("atlas",-1,-1),new e("bias",-1,-1),new e("cosmos",-1,-1),new e("dying",-1,3),new e("early",-1,9),new e("gently",-1,7),new e("howe",-1,-1),new e("idly",-1,6),new e("lying",-1,4),new e("news",-1,-1),new e("only",-1,10),new e("singly",-1,11),new e("skies",-1,2),new e("skis",-1,1),new e("sky",-1,-1),new e("tying",-1,5),new e("ugly",-1,8)],M=[17,65,16,1],O=[1,17,65,208,1],N=[55,141,2],A=[c,l,f,g,v,d],I=new r;this.setCurrent=function(e){I.setCurrent(e)},this.getCurrent=function(){return I.getCurrent()},this.stem=function(){var e=I.cursor;if(!b()){I.cursor=e;var r=I.cursor+3;if(0<=r&&r<=I.limit){if(I.cursor=e,t(),I.cursor=e,n(),I.limit_backward=e,I.cursor=I.limit,u(),I.cursor=I.limit,!m())for(var i=0;i<A.length;i++)I.cursor=I.limit,A[i]();I.cursor=I.limit_backward,h()}}return!0}};return function(e){return t.setCurrent(e),t.stem(),t.getCurrent()}}(),Bravey.Language.EN.TimeEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t=new Bravey.Text.RegexMap([{str:["quarter to~"],val:-15*Bravey.Date.MINUTE},{str:["half past~"],val:30*Bravey.Date.MINUTE},{str:["quarter past~"],val:15*Bravey.Date.MINUTE}],0),n=new Bravey.Text.RegexMap([{str:["in the morning~","am~"],val:0},{str:["in the afternoon~","in the evening~","pm~"],val:12*Bravey.Date.HOUR}],0);r.addMatch(new RegExp("\\b(at\\b)?"+Bravey.Text.WORDSEP+t.regex()+Bravey.Text.WORDSEP+"([0-9]+)"+Bravey.Text.WORDSEP+"(and\\b|:\\b)?"+Bravey.Text.WORDSEP+"([0-9]+)?"+Bravey.Text.WORDSEP+"(minutes\\b)?"+Bravey.Text.WORDSEP+"(o'clock\\b)?"+Bravey.Text.WORDSEP+n.regex(),"gi"),function(e){var r=1*e[3]*Bravey.Date.HOUR;if(e[5]&&(r+=1*e[5]*Bravey.Date.MINUTE),r+=t.get(e,2),r+=n.get(e,8),Bravey.Text.calculateScore(e,[1,2,4,5,6,7,8]))return Bravey.Date.formatTime(r)}),r.bindTo(this)},Bravey.Language.EN.TimePeriodEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t=new Bravey.Text.RegexMap([{str:["second","seconds"],val:Bravey.Date.SECOND},{str:["minute","minutes"],val:Bravey.Date.MINUTE},{str:["hour","hours"],val:Bravey.Date.HOUR}],0);r.addMatch(new RegExp("\\b(in\\b)?"+Bravey.Text.WORDSEP+"([0-9]+)"+Bravey.Text.WORDSEP+t.regex(1)+"\\b","gi"),function(e){var r,n,i=new Date;if(n=r=i.getHours()*Bravey.Date.HOUR+i.getMinutes()*Bravey.Date.MINUTE,r+=e[2]*t.get(e,3),Bravey.Text.calculateScore(e,[1,3]))return{start:Bravey.Date.formatTime(n),end:Bravey.Date.formatTime(r)}}),r.addMatch(new RegExp("\\b(in the evening|this evening|evening)\\b","gi"),function(e){return{start:"12:00:00",end:"23:59:00"}}),r.addMatch(new RegExp("\\b(in the afternoon|this afternoon|afternoon)\\b","gi"),function(e){return{start:"15:00:00",end:"23:59:00"}}),r.addMatch(new RegExp("\\b(in the morning|this morning|morning)\\b","gi"),function(e){return{start:"08:00:00",end:"12:00:00"}}),r.bindTo(this)},Bravey.Language.EN.DateEntityRecognizer=function(e){var r=new Bravey.RegexEntityRecognizer(e),t="\\b(day of|last\\b)?"+Bravey.Text.WORDSEP,n=new Bravey.Text.RegexMap([{str:["january~","jan~","1~","01~"],val:0},{str:["february~","feb~","2~","02~"],val:1},{str:["march~","mar~","3~","03~"],val:2},{str:["april~","apr~","4~","04~"],val:3},{str:["may~","may~","5~","05~"],val:4},{str:["june~","june~","6~","06~"],val:5},{str:["july~","july~","7~","07~"],val:6},{str:["august~","aug~","8~","08~"],val:7},{str:["september~","sep~","sept~","9~","09~"],val:8},{str:["october~","oct~","10~"],val:9},{str:["november~","nov~","11~"],val:10},{str:["december~","dec~","12~"],val:11}],0);r.addMatch(new RegExp(t+n.regex(1)+Bravey.Text.WORDSEP+"([0-9]{1,2})?"+Bravey.Text.WORDSEP+"(st\\b|nd\\b|rd\\b|th\\b)?"+Bravey.Text.WORDSEP+"(of\\b|,\\b)?"+Bravey.Text.WORDSEP+"([0-9]{2,4})?\\b","gi"),function(e){var r=new Date,t=r.getFullYear(),i=r.getMonth(),a=1;if(i=n.get(e,2,i),e[3]&&(a=1*e[3]),e[6]&&(t=1*e[6]),t=Bravey.Date.centuryFinder(t),Bravey.Text.calculateScore(e,[1,3,6]))return Bravey.Date.formatDate(new Date(t,i,a,0,0,0,0).getTime())}),r.addMatch(new RegExp(t+"([0-9]{1,2})"+Bravey.Text.WORDSEP+"(st\\b|nd\\b|rd\\b|th\\b)?"+Bravey.Text.WORDSEP+"(of\\b|,\\b|/\\b|-\\b|\\b)"+Bravey.Text.WORDSEP+n.regex()+"(of\\b|,\\b|/\\b|-\\b)?"+Bravey.Text.WORDSEP+"([0-9]{2,4})?\\b","gi"),function(e){var r=new Date,t=r.getFullYear(),i=r.getMonth(),a=r.getDate();if(a=1*e[2],i=n.get(e,5,i),e[7]&&(t=1*e[7]),t=Bravey.Date.centuryFinder(t),Bravey.Text.calculateScore(e,[1,5,7]))return Bravey.Date.formatDate(new Date(t,i,a,0,0,0,0).getTime())},10),r.addMatch(new RegExp(t+"(today)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime())}),r.addMatch(new RegExp(t+"(tomorrow)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()+Bravey.Date.DAY)}),r.addMatch(new RegExp(t+"(the day after tomorrow)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()+2*Bravey.Date.DAY)}),r.addMatch(new RegExp(t+"(yesterday)\\b","gi"),function(e){return Bravey.Date.formatDate((new Date).getTime()-Bravey.Date.DAY)}),r.bindTo(this)},Bravey.Language.EN.FreeTextEntityRecognizer=function(e,r){var t=["thanks","please"],n=new Bravey.FreeTextEntityRecognizer(e,r);n.addConjunction("is"),n.addConjunction("are"),n.addConjunction("should be"),n.addConjunction("may be");for(var i=0;i<t.length;i++)n.addConjunction(t[i]),n.addConjunction(","+t[i]),n.addConjunction(", "+t[i]);return n},Bravey.Language.EN.Numbers={wordsSeparator:/(\w+)([^\w]+)/gi,sum:{zero:0,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12,thirteen:13,fourteen:14,fifteen:15,sixteen:16,seventeen:17,eighteen:18,nineteen:19,twenty:20,thirty:30,forty:40,fifty:50,sixty:60,seventy:70,eighty:80,ninety:90},mul:{thousand:1e3,million:1e6}},Bravey.Language.EN.NumberEntityRecognizer=function(e,r){this.getName=function(){return e},this.getEntities=function(t,n){n||(n=[]);for(var i,a,s,o,u,c,l=t.toLowerCase().split(/(\w+)/),f=0,g=0,v=0,d=0;d<l.length+1;d++)a=void 0==l[d]?"*":l[d],s=!0,o||(u=0,o={value:0,entity:e,string:"",priority:r||0}),a.trim()&&(null!=Bravey.Language.EN.Numbers.sum[a]?g+=Bravey.Language.EN.Numbers.sum[a]:"hundred"==a?g*=100:isNaN(1*a)?Bravey.Language.EN.Numbers.mul[a]?(i=Bravey.Language.EN.Numbers.mul[a],f+=g*i,g=0):s=!1:u?(d--,a="",s=!1):f=1*a,s?(u=1,c=v+a.length,void 0==o.position&&(o.position=v)):u&&(o.value=f+g,o.string=t.substr(o.position,c-o.position),n.push(o),f=g=o=0)),v+=a.length;return n}},Bravey.Language.PT={},Bravey.Language.PT.Stemmer=function(){function e(){this.setCurrent=function(e){this.current=e,this.cursor=0,this.limit=this.current.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},this.getCurrent=function(){return this.current},this.copy_from=function(e){this.current=e.current,this.cursor=e.cursor,this.limit=e.limit,this.limit_backward=e.limit_backward,this.bra=e.bra,this.ket=e.ket},this.in_grouping=function(e,r,t){if(this.cursor>=this.limit)return!1;var n=this.current.charCodeAt(this.cursor);return!(n>t||n<r)&&(n-=r,0!=(e[n>>>3]&1<<(7&n))&&(this.cursor++,!0))},this.in_grouping_b=function(e,r,t){if(this.cursor<=this.limit_backward)return!1;var n=this.current.charCodeAt(this.cursor-1);return!(n>t||n<r)&&(n-=r,0!=(e[n>>>3]&1<<(7&n))&&(this.cursor--,!0))},this.out_grouping=function(e,r,t){if(this.cursor>=this.limit)return!1;var n=this.current.charCodeAt(this.cursor);return n>t||n<r?(this.cursor++,!0):(n-=r,0==(e[n>>>3]&1<<(7&n))&&(this.cursor++,!0))},this.out_grouping_b=function(e,r,t){if(this.cursor<=this.limit_backward)return!1;var n=this.current.charCodeAt(this.cursor-1);return n>t||n<r?(this.cursor--,!0):(n-=r,0==(e[n>>>3]&1<<(7&n))&&(this.cursor--,!0))},this.eq_s=function(e){return!(this.limit-this.cursor<e.length)&&(this.current.slice(this.cursor,this.cursor+e.length)==e&&(this.cursor+=e.length,!0))},this.eq_s_b=function(e){return!(this.cursor-this.limit_backward<e.length)&&(this.current.slice(this.cursor-e.length,this.cursor)==e&&(this.cursor-=e.length,!0))},this.find_among=function(e){for(var r=0,t=e.length,n=this.cursor,i=this.limit,a=0,s=0,o=!1;;){var u,c=r+(t-r>>>1),l=0,f=a<s?a:s,g=e[c];for(u=f;u<g[0].length;u++){if(n+f==i){l=-1;break}if(0!=(l=this.current.charCodeAt(n+f)-g[0].charCodeAt(u)))break;f++}if(l<0?(t=c,s=f):(r=c,a=f),t-r<=1){if(r>0)break;if(t==r)break;if(o)break;o=!0}}for(;;){var g=e[r];if(a>=g[0].length){if(this.cursor=n+g[0].length,g.length<4)return g[2];var v=g[3](this);if(this.cursor=n+g[0].length,v)return g[2]}if((r=g[1])<0)return 0}},this.find_among_b=function(e){for(var r=0,t=e.length,n=this.cursor,i=this.limit_backward,a=0,s=0,o=!1;;){var u,c=r+(t-r>>1),l=0,f=a<s?a:s,g=e[c];for(u=g[0].length-1-f;u>=0;u--){if(n-f==i){l=-1;break}if(0!=(l=this.current.charCodeAt(n-1-f)-g[0].charCodeAt(u)))break;f++}if(l<0?(t=c,s=f):(r=c,a=f),t-r<=1){if(r>0)break;if(t==r)break;if(o)break;o=!0}}for(;;){var g=e[r];if(a>=g[0].length){if(this.cursor=n-g[0].length,g.length<4)return g[2];var v=g[3](this);if(this.cursor=n-g[0].length,v)return g[2]}if((r=g[1])<0)return 0}},this.replace_s=function(e,r,t){var n=t.length-(r-e);return this.current=this.current.slice(0,e)+t+this.current.slice(r),this.limit+=n,this.cursor>=r?this.cursor+=n:this.cursor>e&&(this.cursor=e),n},this.slice_check=function(){return!(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>this.current.length)},this.slice_from=function(e){var r=!1;return this.slice_check()&&(this.replace_s(this.bra,this.ket,e),r=!0),r},this.slice_del=function(){return this.slice_from("")},this.insert=function(e,r,t){var n=this.replace_s(e,r,t);e<=this.bra&&(this.bra+=n),e<=this.ket&&(this.ket+=n)},this.slice_to=function(){var e="";return this.slice_check()&&(e=this.current.slice(this.bra,this.ket)),e},this.assign_to=function(){return this.current.slice(0,this.limit)}}function r(){function r(){var e;e:for(;;){var r=f.cursor;r:if(f.bra=f.cursor,0!=(e=f.find_among(g))){switch(f.ket=f.cursor,e){case 0:break r;case 1:if(!f.slice_from("a~"))return!1;break;case 2:if(!f.slice_from("o~"))return!1;break;case 3:if(f.cursor>=f.limit)break r;f.cursor++}continue e}f.cursor=r;break e}return!0}function t(){D=f.limit,B=f.limit,_=f.limit;var e=f.cursor;e:{r:{var r=f.cursor;t:if(f.in_grouping(x,97,250)){n:{var t=f.cursor;i:if(f.out_grouping(x,97,250)){a:for(;;){if(f.in_grouping(x,97,250))break a;if(f.cursor>=f.limit)break i;f.cursor++}break n}if(f.cursor=t,!f.in_grouping(x,97,250))break t;i:for(;;){if(f.out_grouping(x,97,250))break i;if(f.cursor>=f.limit)break t;f.cursor++}}break r}if(f.cursor=r,!f.out_grouping(x,97,250))break e;t:{var n=f.cursor;n:if(f.out_grouping(x,97,250)){i:for(;;){if(f.in_grouping(x,97,250))break i;if(f.cursor>=f.limit)break n;f.cursor++}break t}if(f.cursor=n,!f.in_grouping(x,97,250))break e;if(f.cursor>=f.limit)break e;f.cursor++}}D=f.cursor}f.cursor=e;var i=f.cursor;e:{r:for(;;){if(f.in_grouping(x,97,250))break r;if(f.cursor>=f.limit)break e;f.cursor++}r:for(;;){if(f.out_grouping(x,97,250))break r;if(f.cursor>=f.limit)break e;f.cursor++}B=f.cursor;r:for(;;){if(f.in_grouping(x,97,250))break r;if(f.cursor>=f.limit)break e;f.cursor++}r:for(;;){if(f.out_grouping(x,97,250))break r;if(f.cursor>=f.limit)break e;f.cursor++}_=f.cursor}return f.cursor=i,!0}function n(){var e;e:for(;;){var r=f.cursor;r:if(f.bra=f.cursor,0!=(e=f.find_among(v))){switch(f.ket=f.cursor,e){case 0:break r;case 1:if(!f.slice_from("ã"))return!1;break;case 2:if(!f.slice_from("õ"))return!1;break;case 3:if(f.cursor>=f.limit)break r;f.cursor++}continue e}f.cursor=r;break e}return!0}function i(){return D<=f.cursor}function a(){return B<=f.cursor}function s(){return _<=f.cursor}function o(){var e;if(f.ket=f.cursor,0==(e=f.find_among_b(h)))return!1;switch(f.bra=f.cursor,e){case 0:return!1;case 1:if(!s())return!1;if(!f.slice_del())return!1;break;case 2:if(!s())return!1;if(!f.slice_from("log"))return!1;break;case 3:if(!s())return!1;if(!f.slice_from("u"))return!1;break;case 4:if(!s())return!1;if(!f.slice_from("ente"))return!1;break;case 5:if(!a())return!1;if(!f.slice_del())return!1;var r=f.limit-f.cursor;e:if(f.ket=f.cursor,0!=(e=f.find_among_b(d)))if(f.bra=f.cursor,s()){if(!f.slice_del())return!1;switch(e){case 0:f.cursor=f.limit-r;break e;case 1:if(f.ket=f.cursor,!f.eq_s_b("at")){f.cursor=f.limit-r;break e}if(f.bra=f.cursor,!s()){f.cursor=f.limit-r;break e}if(!f.slice_del())return!1}}else f.cursor=f.limit-r;else f.cursor=f.limit-r;break;case 6:if(!s())return!1;if(!f.slice_del())return!1;var t=f.limit-f.cursor;e:if(f.ket=f.cursor,0!=(e=f.find_among_b(m)))switch(f.bra=f.cursor,e){case 0:f.cursor=f.limit-t;break e;case 1:if(!s()){f.cursor=f.limit-t;break e}if(!f.slice_del())return!1}else f.cursor=f.limit-t;break;case 7:if(!s())return!1;if(!f.slice_del())return!1;var n=f.limit-f.cursor;e:if(f.ket=f.cursor,0!=(e=f.find_among_b(b)))switch(f.bra=f.cursor,e){case 0:f.cursor=f.limit-n;break e;case 1:if(!s()){f.cursor=f.limit-n;break e}if(!f.slice_del())return!1}else f.cursor=f.limit-n;break;case 8:if(!s())return!1;if(!f.slice_del())return!1;var o=f.limit-f.cursor;if(f.ket=f.cursor,f.eq_s_b("at"))if(f.bra=f.cursor,s()){if(!f.slice_del())return!1}else f.cursor=f.limit-o;else f.cursor=f.limit-o;break;case 9:if(!i())return!1;if(!f.eq_s_b("e"))return!1;if(!f.slice_from("ir"))return!1}return!0}function u(){var e,r=f.limit-f.cursor;if(f.cursor<D)return!1;f.cursor=D;var t=f.limit_backward;if(f.limit_backward=f.cursor,f.cursor=f.limit-r,f.ket=f.cursor,0==(e=f.find_among_b(w)))return f.limit_backward=t,!1;switch(f.bra=f.cursor,e){case 0:return f.limit_backward=t