autosuggestServiceBundle.min.js 32 KB

12
  1. !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("bi/glass/core-client/js/core-client/ui/core/Class"));else if("function"==typeof define&&define.amd)define(["bi/glass/core-client/js/core-client/ui/core/Class"],t);else{var n="object"==typeof exports?t(require("bi/glass/core-client/js/core-client/ui/core/Class")):t(e["bi/glass/core-client/js/core-client/ui/core/Class"]);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=166)}({166:function(e,t,n){"use strict";var r,s,i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(e){return e&&e.__esModule?e:{default:e}}(n(167)),a=n(17);r=[n(168)],void 0===(s=function(e){return function(t){function n(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n);var t=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.autosuggestServiceCore=new o.default(a.questions),t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,e),i(n,[{key:"initialize",value:function(e){return this.glassContext=e,this.autosuggestServiceCore.initialize(e)}},{key:"suggest",value:function(e){return this.autosuggestServiceCore.suggest(e)}}]),n}()}.apply(t,r))||(e.exports=s)},167:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,s=!1,i=void 0;try{for(var o,a=e[Symbol.iterator]();!(r=(o=a.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){s=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(s)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){function e(t){var n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.questions=t,this.services={conversation:{},content:{},ajax:{}},this.context={request:{},service:{activeSource:{},autosuggestQuestions:[],marker:(n={},o(n,v,[]),o(n,m,[]),o(n,g,[]),o(n,p,[]),n)},external:{conversationSourceHistory:[],conversationSource:{},dashboardSource:{},mru:[]}},this.stats={request:{numRequests:0,responseTime:{last:0,avg:0,min:0,max:0,src:""}},backend:{interestingFields:{numRequests:0,responseTime:{last:0,avg:0,min:0,max:0,src:""}},columns:{numRequests:0,responseTime:{last:0,avg:0,min:0,max:0,src:""}}},data:{interestingFields:{max:0,src:""},columns:{max:0,src:""}}},this.cache={},this.requests={},this.initialized=!1,this.debug=!1}return i(e,[{key:"hasCapability",value:function(e){var t=this.glassContext.getCoreSvc(".UserProfile");return t&&t.capabilities&&t.capabilities.indexOf(e)>=0?this.glassContext.findCollection("com.ibm.bi.assistant.chatContext").then(function(t){if(t){var n=t.find(function(t){return t.label===e});return!n||n.value}return!0}):Promise.resolve(!1)}},{key:"initialize",value:function(t){var n=this;return this.glassContext=t,Promise.all([this.hasCapability(d),t.getSvc(l),t.getSvc(h),t.getSvc(f)]).then(function(t){var r=s(t,4),i=r[0],o=r[1],a=r[2],u=r[3];i&&(n.questions.all=n.questions.all.concat(n.questions.dashboard.all),n.questions.initial.column=n.questions.initial.column.concat(n.questions.dashboard.initial));var c=n.questions.all,l=n.context.service;l.autosuggestQuestions=e.getAutosuggestQuestions(c),l.marker[v]=e.getIntentMarkers(c,b),l.marker[m]=e.getIntentMarkers(c,x),l.marker[g]=e.getIntentMarkers(c,y),l.marker[p]=e.getModifierMarkers(c),n.services.conversation=o,n.services.content=a,n.services.ajax=u,n.initialized=!0,setTimeout(function(){return n.updateContext()},0)})}},{key:"suggest",value:function(t){var n=this;return this.initialized?(this.stats.request.timestamp=new Date,this.updateContext().then(function(){var r=[],s=void 0;if(t&&" "!==t){t.endsWith(" ")&&(t=t.trim()+" "),s=n.getIntent(t);var i=[],o=n.getSentenceColumns(t);switch(s.name){case v:i=n.processSourceIntent(t,s);break;case m:i=n.processColumnIntent(t,o,s);break;case g:i=n.processFieldIntent(t,o,s)}0===i.length&&(i=n.processNoIntent(t,o)),n.processIncompleteSuggestions(i),r=(r=(r=n.processTemplates(t,s,i.length)).concat(i)).slice(0,G)}else r=n.processInitialQuestions();return n.debug&&(e.updateStats(n.context.service.activeSource.name,n.stats.request),n.log(t,s,r)),0===r.length&&n.processDebug(t),r})):(console.log("Autosuggest service not initialized"),Promise.resolve([]))}},{key:"updateContext",value:function(){var e=this;return Promise.all([this.getConversationSourceHistory(),this.getConversationSource(),this.getDashboardSource(),this.getMRU()]).then(function(t){var n=s(t,4),r=n[0],i=n[1],o=n[2],a=n[3],u=e.context.external;u.conversationSourceHistory=r,u.conversationSource=i,u.dashboardSource=o,u.mru=a;var c=e.getActiveSource();if(c){var l=e.context.service.activeSource;return l.id=c.id,l.name=c.name,l.origin=c.origin,l.conversationFields=[],l.interestingFields=[],l.columns=[],e.getActiveSourceConversationFields(),e.getActiveSourceInterestingFields(),e.getActiveSourceColumns()}return Promise.resolve()}).then(function(t){t&&(e.context.service.activeSource.columns=t);var n=e.context.request;n.interestingFields=e.getInterestingFields(),n.sortedInterestingFields=n.interestingFields.slice().sort(H),n.fieldsAndColumns=e.getFieldsAndColumns(),n.sortedFieldsAndColumns=n.fieldsAndColumns.slice().sort(H)}).catch(function(){console.log("Error refreshing Autosuggest service context")})}},{key:"getConversationSourceHistory",value:function(){var e=[],t=this.services.conversation.getMessages().slice();return t&&(t.reverse(),e=t.reduce(function(e,t){return t.action&&t.action.id===F&&e.push({id:t.currentSource.module,name:t.currentSource.name}),e},[])),Promise.resolve(e)}},{key:"getConversationSource",value:function(){var e={},t=this.services.conversation.context;return t.module&&t.name&&(e={id:t.module,name:t.name}),Promise.resolve(e)}},{key:"getDashboardSource",value:function(){var e=this.glassContext.getCurrentContentView();return e.dashboardApi?e.dashboardApi.getSources().then(function(e){var t=e.find(function(e){return e.active});if(t)return{id:t.assetId,name:t.name}}):Promise.resolve()}},{key:"getMRU",value:function(){return this.services.content.getMRUList().then(function(e){return e.reduce(function(e,t){return j.includes(t.type)&&e.push({id:t.id,name:t.defaultName}),e},[])}).catch(function(){return[]})}},{key:"getActiveSource",value:function(){var e="",t="",n="",r=this.context.external.conversationSource;if(r&&r.id)e=r.id,t=r.name,n=T;else if((r=this.context.external.dashboardSource)&&r.id)e=r.id,t=r.name,n=N;else{var s=this.context.external.mru;s.length>0&&(e=s[0].id,t=s[0].name,n=U)}return{id:e,name:t,origin:n}}},{key:"getActiveSourceConversationFields",value:function(){var e=this.context.service.activeSource;if(e&&e.name){var t=this.services.conversation.getMessages();if(t&&t.length>0&&(t=t.filter(function(t){return t.action&&t.action.id===k&&t.currentSource&&t.currentSource.name===e.name})).length>0){for(var n=[],r={},s={},i=0;i<t.length;i++){var o=t[i];if(o.action&&o.action.sections){var a=o.action.sections.find(function(e){return e.id===O});a&&a[L]&&a[q]&&function(){var e=a[L],t=M.length,n=e.indexOf(I);e=e.substring(t,n);var i=a[q].find(function(t){return t.endsWith("."+e.replace(" ","_"))}),o=r[i];o=o?o+1:1,r[i]=o,s[i]=e}()}}var u=[];for(var c in r)r.hasOwnProperty(c)&&u.push([c,r[c]]);u.sort(Q);for(var l=0;l<u.length;l++){var h=u[l][0];n.push({id:h,label:s[h]})}e.conversationFields=n}}}},{key:"getActiveSourceInterestingFields",value:function(){var e=this,t=this.context.service.activeSource,n=t.id;if(n){var r=this.getFromCache(n);if(r){var s=r[w];if(s)return void(t.interestingFields=s)}this.getSourceInterestingFields(t).then(function(t){n===e.context.service.activeSource.id&&(e.context.service.activeSource.interestingFields=t)})}}},{key:"getSourceInterestingFields",value:function(t){var n=this,r=t.id,s=t.name,i=[],o=this.services.conversation.getMessages();if(o&&o.length>0&&(o=o.filter(function(e){return e.action&&e.action.id===F&&e.currentSource&&e.currentSource.name===s})).length>0){var a=this.getSectionItems(o.slice(-1)[0].action,O);a.length>0&&(i=a.map(function(e){return{id:e.id,label:e.label}}))}if(i.length>0)return this.addToCache(r,s,w,i),this.debug&&this.updateDataStats(s,w,i),Promise.resolve(i);var u=this.stats.backend.interestingFields;u.responseTime.last=0,u.timestamp=new Date;var l="int_"+r,h=this.requests[l];return h||(h=this.request(P,c,W,JSON.stringify({moduleId:r})).then(function(t){n.debug&&e.updateStats(s,u);var i=t.data.recommendation.recommendedFields.reduce(function(e,t){var s=n.getFieldName(r,t);return s&&e.push({id:t.fieldIDForExpression,label:s}),e},[]).sort(z);return n.addToCache(r,s,w,i),n.debug&&n.updateDataStats(s,w,i),delete n.requests[l],Promise.resolve(i)}).catch(function(e){return delete n.requests[l],e&&400===e.code?(n.addToCache(r,s,w,[]),Promise.resolve([])):Promise.resolve()}),this.requests[l]=h),h}},{key:"getFieldName",value:function(e,t){var n=t.fieldName;if(!n){var r=this.getFromCache(e);if(r){var s=r.columns.find(function(e){return e.id===t.fieldIDForExpression});s&&(n=s.label)}}return n}},{key:"getActiveSourceColumns",value:function(){var e=this.context.service.activeSource.id;if(e){var t=this.getFromCache(e);if(t){var n=t[S];if(n)return Promise.resolve(n)}return this.getSourceColumns(this.context.service.activeSource)}return Promise.resolve()}},{key:"getSourceColumns",value:function(t){var n=this,r=t.id,s=t.name,i=this.stats.backend.columns;i.responseTime.last=0,i.timestamp=new Date;var o="auto_"+r,a=this.requests[o];return a||(a=this.request(D,u,_,E+r).then(function(t){n.debug&&e.updateStats(s,i);var a=t.data.recommendation.recommendedFields.map(function(e){return{id:e.fieldIDForExpression,label:e.fieldName}}).sort(z);return n.addToCache(r,s,S,a),n.debug&&n.updateDataStats(s,S,a),delete n.requests[o],Promise.resolve(a)}).catch(function(e){return delete n.requests[o],e&&400===e.code?(n.addToCache(r,s,S,[]),Promise.resolve([])):Promise.resolve()}),this.requests[o]=a),a}},{key:"getIntent",value:function(t){var n="",r="",s="",i=[],o=e.getMatchedAutosuggestQuestion(t,this.context.service.autosuggestQuestions),a=o.matchedAutosuggestQuestion,u=o.result;if(a&&(r=a.question,(i=u&&u.length>0?u.splice(1):[]).length>0&&(s=i[i.length-1],a.params&&a.params.length>0)))switch(a.params.slice(-1)[0]){case b:n=v;break;case x:n=m;break;case y:n=g}return{name:n,question:r,values:i,filter:s}}},{key:"getSources",value:function(){var e=[],t=this.context.external.conversationSourceHistory;t&&t.length>0&&(e=t.map(function(e){return e.name}).slice());var n=this.context.external.dashboardSource;n&&n.name&&e.push(n.name);var r=this.context.external.mru;r&&r.length>0&&(e=e.concat(r.map(function(e){return e.name}))),e=this.removeDuplicates(e);var s=this.context.external.conversationSource;return s&&(e=e.filter(function(e){return e!==s.name})),e}},{key:"processInitialQuestions",value:function(){var e=[];return this.isSourceSelected()?(e=this.questions.initial.column,0===this.getFieldsAndColumns().length&&(e=e.filter(function(e){return!e.includes(x)})),0===this.getInterestingFields().length&&(e=e.filter(function(e){return!e.includes(y)}))):e=this.questions.initial.source,this.convertSuggestions(e,"")}},{key:"processSourceIntent",value:function(e,t){var n=this,r=this.getSources(),s=t.filter;if(s){var i=s.toLowerCase();r=r.filter(function(e){return e.toLowerCase().startsWith(i)})}return 0!==(r=this.prepareSuggestions(r,e,t,C)).length&&r[0].label!==e||setTimeout(function(){return n.cacheSource(s.trim())},0),r}},{key:"processColumnIntent",value:function(e,t,n){var r=this.context.request.fieldsAndColumns,s=this.context.request.sortedFieldsAndColumns;return this.processColumnFieldIntent(e,t,n,r,s)}},{key:"processFieldIntent",value:function(e,t,n){var r=this.context.request.interestingFields,s=this.context.request.sortedInterestingFields;return this.processColumnFieldIntent(e,t,n,r,s)}},{key:"processColumnFieldIntent",value:function(t,n,r,s,i){var o=[],a=this.getSentenceDataset(i,t);if(a&&(s=e.filterColumnsByDataset(s,a)),s.length>0){var u=t.toLowerCase();s.some(function(e){return u.endsWith(e.label.toLowerCase()+" ")})&&(t+=this.getConnector(r.question),u=t.toLowerCase(),r=this.getIntent(t));var c=r.filter;c&&(c=c.toLowerCase()),o=s.reduce(function(e,t){var r=t.label.toLowerCase();return!u.endsWith(r)&&n.includes(r)||c&&!r.startsWith(c)||e.push(t.label),e},[]),o=this.prepareSuggestions(o,t,r,S)}return o}},{key:"processTemplates",value:function(e,t,n){var r=[];this.addQuestion(r,e,"","");var s=n>0?t.question:"";return this.isSourceSelected()?(this.getFieldsAndColumns().length>0&&this.addQuestion(r,e,s,x),(t.name!==g||0===n)&&this.getInterestingFields().length>0&&this.addQuestion(r,e,s,y)):this.addQuestion(r,e,s,b),r.length>0&&(r=this.convertSuggestions(r,e)),r}},{key:"addQuestion",value:function(e,t,n,r){var s=this,i=t.toLowerCase(),o=this.questions.all.filter(function(e){var t=e.toLowerCase(),s=t!==n&&t.startsWith(i);return s&&(s=r?t.includes(r):!t.includes("{")),s});if(o.length>0){var a=o.find(function(e){return!s.isModifierQuestion(e)});if(a&&e.push(a),!this.isModifierQuestion(n))for(var u=o.filter(function(e){return s.isModifierQuestion(e)}),c=0;c<u.length;c++){var l=u[c],h=l.indexOf("(");-1!==h?((a=l.substring(0,h)).endsWith(" ")||(a+=" "),a+=l.substring(l.indexOf("{"))):a=l,e.push(a)}}}},{key:"processNoIntent",value:function(t,n){var r=[],s=this.context.request.fieldsAndColumns,i=this.context.request.sortedFieldsAndColumns,a=this.getSentenceDataset(i,t);if(a&&(s=e.filterColumnsByDataset(s,a)),!this.isIntentQuestion(t,v)&&!this.isIntentQuestion(t,g)&&n.length<J&&s&&s.length>0){var u=t.split(" ");if(u.length>0){var c=t.toLowerCase(),l="",h="";if(s.some(function(e){return e.label.toLowerCase().startsWith(c)}))l=c;else{for(var f=function(e){var t=u.slice(0,e).join(" ");s.some(function(e){var n=t.toLowerCase(),r=e.label.toLowerCase();return n===r||n.endsWith(" "+r)})&&(h=t+" ")},d=1;d<u.length+1;d++)f(d);l=c.substring(h.length).trim()}if(l||t.endsWith(" ")){var m=[""],p=this.getFunctionWords(t,h,l);p.sentence&&(h=p.prefix,l=p.filter,m=p.functionWords),s=s.map(function(e){return e.label}).filter(function(e){var t=e.toLowerCase();return(c===t||!n.includes(t))&&t.startsWith(l)});var b=h.toLowerCase();this.questions.functionWords.some(function(e){return b.endsWith(e)})&&(m=[""]);for(var x=this.getPrefixLocation(h),y=0;y<s.length;y++)for(d=0;d<m.length;d++){var C=m[d],w=h.length+C.length,k=w+s[y].length,F=x.slice();F.push(w,k),r.push({label:h+C+s[y],value:o({},S,{location:F})})}}}}return r}},{key:"prepareSuggestions",value:function(e,t,n,r){if(e.length>0){e=e.slice(0,G);var s=t;if(n.filter)-1!==t.lastIndexOf(n.filter)&&(s=t.substring(0,t.lastIndexOf(n.filter)));s=s.trim();var i=0,a=0,u=[];if(n.name===m||n.name===g)for(var c=this.context.request.sortedFieldsAndColumns,l=0;l<c.length;l++){var h=c[l].label;h&&-1!==(i=s.indexOf(h,a))&&(a=i+h.length,u.push(i,a))}i=s.length+1,e=e.map(function(e){var t=s+" "+e;a=t.length;var n=u.slice();return n.push(i,a),{label:t,value:o({},r,{location:n})}})}return e}},{key:"request",value:function(e,t,n,r){return this.services.ajax.ajax({type:e,url:t,contentType:n,data:r,xhrFields:{withCredentials:!0}})}},{key:"getConnector",value:function(e){var t="";e+=" ";var n=this.context.service.autosuggestQuestions.reduce(function(t,n){return n.question.startsWith(e)&&t.push(n.question),t},[]);if(n.length>0){var r=(t=n[0].substring(e.length)).indexOf("{");r>0&&(t=t.substring(0,r))}return t}},{key:"getSentenceDataset",value:function(t,n){var r="",s=n.toLowerCase(),i=this.questions.functionWords,o=t.find(function(e){var t=e.label.toLowerCase();if(s.endsWith(t)||s.endsWith(t+" "))return!0;for(var n=0;n<i.length;n++)if(s.endsWith(t+" "+i[n]))return!0;return!1});return o&&(r=e.getColumnDataset(o)),r}},{key:"isSourceSelected",value:function(){var e=this.context.service.activeSource;return e&&(e.origin===T||e.origin===N)}},{key:"getConversationFields",value:function(){var e=[],t=this.context.service.activeSource;return t&&t.conversationFields&&t.conversationFields.length>0&&(e=t.conversationFields.slice()),e}},{key:"getInterestingFields",value:function(){var e=[],t=this.context.service.activeSource;return t&&t.interestingFields&&t.interestingFields.length>0&&(e=t.interestingFields.slice()),e}},{key:"getColumns",value:function(){var e=[],t=this.context.service.activeSource;return t&&t.columns&&t.columns.length>0&&(e=t.columns.slice()),e}},{key:"getFieldsAndColumns",value:function(){var e=this.getInterestingFields().concat(this.getConversationFields(),this.getColumns());return this.removeDuplicatesByLabel(e)}},{key:"convertSuggestions",value:function(e,t){var n=t.length;return e.map(function(e){return{label:n>0?t+e.substring(n):e,value:{}}})}},{key:"isIntentQuestion",value:function(e,t){var n=e.toLowerCase();return this.context.service.marker[t].some(function(e){return n.startsWith(e)})}},{key:"getFunctionWords",value:function(e,t,n){var r=[""],s=this.questions.functionWords;if(n){for(var i=n.toLowerCase(),o=void 0,a=!1,u=0;u<s.length;u++)if(o=s[u],i.startsWith(o)){t+=o,n=n.substring(o.length),a=!0;break}if(o="",a||(o=s.find(function(e){return e.startsWith(n)})),o)t=e=e.substring(0,e.trim().lastIndexOf(" ")+1),n="",r=[o];else{var c=n.lastIndexOf(" ");if(-1!==c){var l=n.substring(0,c+1);(o=s.find(function(e){return e.startsWith(l)}))&&(t=e=t+o,n=n.substring(c+1))}}}else r=s.slice(0,1);return{sentence:e,prefix:t,filter:n,functionWords:r}}},{key:"purgeCache",value:function(){for(var e in this.cache)if(this.cache.hasOwnProperty(e)){var t=new Date,n=this.cache[e].timestamp;(t.getTime()-n.getTime())/1e3>Y&&delete this.cache[e]}}},{key:"getFromCache",value:function(e){var t=this,n=void 0,r=this.cache[e];return r&&(n={interestingFields:r[w],columns:r[S]}),setTimeout(function(){return t.purgeCache()},0),n}},{key:"addToCache",value:function(t,n,r,s){var i=this;if(s){this.cache[t]||(this.cache[t]={});var o=this.cache[t];o.timestamp=new Date,o.moduleName=n,o[r]=s,e.calculateObjectSize(this.cache)+e.calculateObjectSize(o)<X&&(this.cache[t]=o)}setTimeout(function(){return i.purgeCache()},0)}},{key:"removeDuplicatesByLabel",value:function(e){return e.filter(function(e,t,n){return t===n.findIndex(function(t){return t.label===e.label})})}},{key:"removeDuplicates",value:function(e){return e.filter(function(e,t,n){return t===n.findIndex(function(t){return t===e})})}},{key:"filterSuggestions",value:function(e,t){var n=t.toLowerCase();return e.filter(function(e){return e.label.toLowerCase().startsWith(n)})}},{key:"getSectionItems",value:function(e,t){var n=e.sections.find(function(e){return e.id===t});return n?n.items:[]}},{key:"getSentenceColumns",value:function(e){var t=[];if(e)for(var n=e.toLowerCase(),r=this.context.request.sortedFieldsAndColumns,s=0;s<r.length;s++){var i=r[s].label.toLowerCase();n.includes(i)&&(n=n.replace(i,""),t.push(i))}return t}},{key:"getPrefixLocation",value:function(e){for(var t=[],n=e.toLowerCase(),r=this.context.request.sortedFieldsAndColumns,s=0;s<r.length;s++){var i=r[s].label.toLowerCase(),o=n.indexOf(i);-1!==o&&(t.push({start:o,end:o+i.length}),n=n.replace(i,A.repeat(i.length)))}t.sort(B);for(var a=[],u=0;u<t.length;u++){var c=t[u];a.push(c.start,c.end)}return a}},{key:"isModifierQuestion",value:function(e){for(var t=!1,n=this.context.service.marker[p],r=0;r<n.length;r++)if(e.includes(n[r])){t=!0;break}return t}},{key:"processIncompleteSuggestions",value:function(e){for(var t=this,n=this.context.service.marker[p],r=function(r){var s=e[r].label;if(!s.includes(",")&&!t.questions.functionWords.some(function(e){return s.includes(" "+e)}))for(var i=0;i<n.length;i++)if(s.includes(n[i]+" ")){e[r].label+=" ";break}},s=0;s<e.length;s++)r(s)}},{key:"updateDataStats",value:function(e,t,n){var r=this.stats.data;n&&n.length>r[t].max&&(r[t].max=n.length,r[t].src=e)}},{key:"cacheSource",value:function(e){var t=[],n=this.context.external.conversationSourceHistory;n&&n.length>0&&(t=n);var r=this.context.external.conversationSource;r&&r.name&&t.push(r);var s=this.context.external.dashboardSource;s&&s.name&&t.push(s);var i=this.context.external.mru;i&&i.length>0&&(t=t.concat(i));var o=t.find(function(t){return t.name===e});o&&(this.getSourceInterestingFields(o),this.getSourceColumns(o))}},{key:"processDebug",value:function(e){var t=this;setTimeout(function(){Z===e?t.debug=!0:ee===e&&(t.debug=!1)},0)}},{key:"log",value:function(t,n,r){t||(t="");var s=n?n.name:"",i=n?n.question:"",o=n?n.filter:"",a=this.context.service.activeSource,l=this.context.external.conversationSourceHistory?this.context.external.conversationSourceHistory.map(function(e){return e.name}):[],h=this.context.external.conversationSource?this.context.external.conversationSource.name:"",f=this.context.external.dashboardSource?this.context.external.dashboardSource.name:"",d=0,v=[];this.context.external.mru&&(d=(v=this.context.external.mru.map(function(e){return e.name})).length)>V&&(v=v.slice(0,V).push("..."));var m=0,g=[];a.interestingFields&&(m=(g=a.interestingFields.map(function(e){return e.label})).length)>$&&(g=g.slice(0,$)).push("...");var p=0,b=[];a.conversationFields&&(p=(b=a.conversationFields.map(function(e){return e.label})).length)>$&&(b=b.slice(0,$)).push("...");var x=0,y=[];a.columns&&(x=(y=a.columns.map(function(e){return e.label})).length)>$&&(y=y.slice(0,$)).push("...");var C=r.map(function(e){return e.label}),S=C.length;S>K&&(C=C.slice(0,K),r.push("..."));var w=void 0,k=r.find(function(e){return e.value&&(e.value.columns||e.value.sources)});k&&((w=k.value).columns?w="columns "+w.columns.location:w.sources&&(w="sources "+w.sources.location));var F="font-weight:bold";console.log("\n──────────────────────────────────────────────────────────────────────────────────────────────────%c\nAutosuggest service\n──────────────────────────────────────────────────────────────────────────────────────────────────\n",F),console.log("%cContext%c\n\t• Conversation source history: %c"+l+"%c\n\t• Conversation source: %c"+(h||"")+"%c\n\t• Dashboard/Explore source: %c"+(f||"")+"%c\n\t• MRU ("+d+"): %c"+v+"\n",F,F,"",F,"",F,"",F,""),console.log("%cActive Source%c\n\t• Id: %c"+(a.id||"")+"%c\n\t• Name: %c"+(a.name||"")+"%c\n\t• Origin: %c"+(a.origin||"")+"%c\n\t• Interesting fields ("+m+"): %c"+g+"%c\n\t• Conversation fields ("+p+"): %c"+b+"%c\n\t• Columns ("+x+"): %c"+y+"\n",F,F,"",F,"",F,"",F,"",F,"",F,""),console.log("%cRequest%c\n\t• Sentence: %c'"+(t||"")+"'\n",F,F,""),console.log("%cIntent%c\n\t• Name: %c"+(s||"no intent detected")+"%c\n\t• Question: %c"+(i||"no question matched")+"%c\n\t• Filter: %c"+(o||"")+"\n",F,F,"",F,"",F,"");var O=this.stats.request;console.log("%cResponse%c\n\t• Suggestions ("+S+"): %c"+(C||"")+"%c\n\t• Location for first non-template suggestion: %c"+(w?w+" ("+k.label+")":"")+"%c\n\t• Timestamp: %c"+O.timestamp.toLocaleTimeString()+"%c\n\t• Response time: %c"+O.responseTime.last+" ms\n",F,F,"",F,"",F,"",F,""),console.log("%cRequest Statistics%c\n\t• Number of requests: %c"+O.numRequests+"%c\n\t• Average response time: %c"+O.responseTime.avg.toFixed(0)+" ms%c\n\t• Min response time: %c"+O.responseTime.min+" ms%c\n\t• Max response time: %c"+O.responseTime.max+" ms (source: "+O.responseTime.src+")\n",F,F,"",F,"",F,"",F,""),O=this.stats.backend.interestingFields,console.log("%cBackend Statistics ("+c+")%c\n\t• Number of requests: %c"+O.numRequests+"%c\n\t• Average response time: %c"+O.responseTime.avg.toFixed(0)+" ms%c\n\t• Min response time: %c"+O.responseTime.min+" ms%c\n\t• Max response time: %c"+O.responseTime.max+" ms (source: "+O.responseTime.src+")\n",F,F,"",F,"",F,"",F,""),O=this.stats.backend.columns,console.log("%cBackend Statistics ("+u+")%c\n\t• Number of requests: %c"+O.numRequests+"%c\n\t• Average response time: %c"+O.responseTime.avg.toFixed(0)+" ms%c\n\t• Min response time: %c"+O.responseTime.min+" ms%c\n\t• Max response time: %c"+O.responseTime.max+" ms (source: "+O.responseTime.src+")\n",F,F,"",F,"",F,"",F,""),O=this.stats.data,console.log("%cData Stats%c\n\t• Max interesting fields: %c"+O.interestingFields.max+(O.interestingFields.src?" (source: "+O.interestingFields.src+")":"")+"%c\n\t• Max columns: %c"+O.columns.max+" (source: "+O.columns.src+")\n",F,F,"",F,"");var q=e.calculateObjectSize(this.cache);for(var L in console.log("%cCache%c\n\t• Size: %c"+q+" bytes%c\n\t• Capacity: %c"+X+" bytes%c\n\t• Used: %c"+(100*q/X).toFixed(1)+"%%%c\n\t• Expiration interval: %c"+Y+" seconds\n",F,F,"",F,"",F,"",F,""),console.log("%cCached sources",F),this.cache)if(this.cache.hasOwnProperty(L)){var M=this.cache[L].moduleName,I=this.cache[L].timestamp;console.log("%c\t• Source: %c"+M+", %cSize: %c"+e.calculateObjectSize(this.cache[L])+" bytes, %cTimestamp: %c"+I.toLocaleTimeString(),F,"",F,"",F,"")}console.log("──────────────────────────────────────────────────────────────────────────────────────────────────\n")}}],[{key:"getAutosuggestQuestions",value:function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n],s=r,i=r.match(R);if(i&&i.length>0)for(var o=0;o<i.length;o++)s=s.split(i[o]).join("(.+?)");var a=s.lastIndexOf("(.+?)");-1!==a&&(s=s.substring(0,a)+"(.*?)$"),t.push({question:r,params:i,regex:s})}return t}},{key:"getColumnDataset",value:function(e){var t="";if(e.id){var n=e.id.lastIndexOf(".");n>-1&&(t=e.id.substring(0,n))}return t}},{key:"filterColumnsByDataset",value:function(t,n){return t.filter(function(t){return n===e.getColumnDataset(t)})}},{key:"getMatchedAutosuggestQuestion",value:function(e,t){for(var n=void 0,r=void 0,s=0;s<t.length;s++){var i=t[s],o=new RegExp(i.regex,"i"),a=e.match(o);if(a){var u=i.question;if(!(r||u.includes("(")||u.includes("[")||u.includes(","))){n=i,r=a;break}(!r||a.index>r.index)&&(n=i,r=a)}}return{matchedAutosuggestQuestion:n,result:r}}},{key:"getIntentMarkers",value:function(e,t){return e.reduce(function(e,n){return n.includes(t)&&e.push(n.substring(0,n.indexOf(t))),e},[])}},{key:"getModifierMarkers",value:function(e){return e.reduce(function(e,t){var n=t.indexOf("(");if(-1!==n){var r=t.substring(0,n).trim();r.length>1&&e.push(r)}return e},[])}},{key:"updateStats",value:function(e,t){var n=t.responseTime;n.last=new Date-t.timestamp,n.avg=(t.numRequests*n.avg+n.last)/(t.numRequests+1),t.numRequests++,(n.last<n.min||0===n.min)&&(n.min=n.last),n.last>n.max&&(n.max=n.last,n.src=e)}},{key:"calculateObjectSize",value:function(e){for(var t=[e],n=0,s=0;s<t.length;s++){var i=t[s];switch(void 0===i?"undefined":r(i)){case"string":n+=2*i.length;break;case"object":if("[object Array]"!==Object.prototype.toString.call(i))for(var o in i)n+=2*o.length;for(var a in i){for(var u=!1,c=0;c<t.length;c++)if(t[c]===i[a]){u=!0;break}u||t.push(i[a])}}}return n}}]),e}();t.default=a;var u="v1/smarts/insights/autosuggest/fields",c="v1/smarts/insights/interesting-fields",l=".ConversationService",h=".Content",f=".Ajax",d="canAuthorDashboard",v="source",m="column",g="field",p="modifier",b="{source}",x="{column}",y="{field}",C="sources",S="columns",w="interestingFields",k="show_column_info",F="show_query_items",O="column_list",q="click_parameters",L="click_template",M="show chart ",I=" and {{label}}",T="conversation",N="dashboard/explore",U="MRU",A="•",j=["module","uploadedFile","package","dataSet2","data_asset"],D="GET",P="POST",_="application/x-www-form-urlencoded; charset=UTF-8",W="application/json; charset=UTF-8",E="moduleId=",R=new RegExp("{(\\w*?)}","g"),Q=function(e,t){return t[1]-e[1]},z=function(e,t){return e.label>t.label?1:e.label<t.label?-1:0},H=function(e,t){return t.label.length-e.label.length},B=function(e,t){return e.start-t.start},G=200,J=6,V=20,$=20,K=20,X=1048576,Y=300,Z="debug on",ee="debug off"},168:function(t,n){t.exports=e},17:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=t.PLACEHOLDER_TAGS={SOURCE:"source",COLUMN:"column",FIELD:"field"};t.questions={initial:{source:["help","load data {"+r.SOURCE+"}"],column:["help","show {"+r.COLUMN+"}","what impacts {"+r.FIELD+"}"]},all:[", and {"+r.COLUMN+"}",",( )?(?!.*,){"+r.COLUMN+"}","top( [0-9]+%?)?( by)? (?!.*top){"+r.COLUMN+"}","bottom( [0-9]+%?)?( by)? (?!.*bottom){"+r.COLUMN+"}","total (?!.*total){"+r.COLUMN+"}","average (?!.*average){"+r.COLUMN+"}","max (?!.*max){"+r.COLUMN+"}","maximum (?!.*maximum){"+r.COLUMN+"}","min (?!.*min){"+r.COLUMN+"}","minimum (?!.*minimum){"+r.COLUMN+"}","best (?!.*best){"+r.COLUMN+"}","worst (?!.*worst){"+r.COLUMN+"}","help","chart for {"+r.COLUMN+"}","draw chart {"+r.COLUMN+"}","load data {"+r.SOURCE+"}","show column {"+r.COLUMN+"}","show data {"+r.SOURCE+"}","show details about {"+r.COLUMN+"}","show influencers of {"+r.FIELD+"}","show source {"+r.SOURCE+"}","show top {"+r.COLUMN+"}","show bottom {"+r.COLUMN+"}","show total {"+r.COLUMN+"}","show average {"+r.COLUMN+"}","show max {"+r.COLUMN+"}","show maximum {"+r.COLUMN+"}","show min {"+r.COLUMN+"}","show minimum {"+r.COLUMN+"}","show best {"+r.COLUMN+"}","show worst {"+r.COLUMN+"}","show {"+r.COLUMN+"}","tell me about {"+r.COLUMN+"}","what do you know about {"+r.COLUMN+"}","what impacts {"+r.FIELD+"}","what influences column {"+r.FIELD+"}","what influences {"+r.FIELD+"}","what is {"+r.COLUMN+"}","generate questions","suggest questions","suggest starting points","where should I start?","what can you tell me about this dataset?","what can I do here?","I don't know where to start"],dashboard:{all:["generate dashboard","generate dashboard for related charts","create dashboard","create dashboard for charts"],initial:["create dashboard"]},functionWords:["and ","by ","for ","per ","with "]}}})});
  2. //# sourceMappingURL=autosuggestServiceBundle.min.js.map