Exemple #1
0
        public void OnItemClick(AdapterView parent, View view, int position, long id)
        {
            IntentItem clickedIntentItem = (IntentItem)intentItems[position];

            Intent intent;

            switch (clickedIntentItem.Type)
            {
            case IntentType.PLAY_VIDEO:
                intent = YouTubeIntents.CreatePlayVideoIntentWithOptions(this, VIDEO_ID, true, false);
                StartActivity(intent);
                break;

            case IntentType.OPEN_PLAYLIST:
                intent = YouTubeIntents.CreateOpenPlaylistIntent(this, PLAYLIST_ID);
                StartActivity(intent);
                break;

            case IntentType.PLAY_PLAYLIST:
                intent = YouTubeIntents.CreatePlayPlaylistIntent(this, PLAYLIST_ID);
                StartActivity(intent);
                break;

            case IntentType.OPEN_SEARCH:
                intent = YouTubeIntents.CreateSearchIntent(this, USER_ID);
                StartActivity(intent);
                break;

            case IntentType.OPEN_USER:
                intent = YouTubeIntents.CreateUserIntent(this, USER_ID);
                StartActivity(intent);
                break;

            case IntentType.OPEN_CHANNEL:
                intent = YouTubeIntents.CreateChannelIntent(this, CHANNEL_ID);
                StartActivity(intent);
                break;

            case IntentType.UPLOAD_VIDEO:
                // This will load a picker view in the users' gallery.
                // The upload activity is started in the function onActivityResult.
                intent = new Intent(Intent.ActionPick, null).SetType("video/*");
                intent.PutExtra(EXTRA_LOCAL_ONLY, true);
                StartActivityForResult(intent, SELECT_VIDEO_REQUEST);
                break;
            }
        }
Exemple #2
0
        private async Task InsertIntentItem(IntentItem IntentItem)
        {
            try
            {
                // This code inserts a new IntentItem into the database. After the operation completes
                // and the mobile app backend has assigned an id, the item is added to the CollectionView.
                await intentTable.InsertAsync(IntentItem);

                items.Add(IntentItem);

                await MobileService.SyncContext.PushAsync(); // offline sync
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Exemple #3
0
        //private TextProcessor()
        //{
        //}

        //public static TextProcessor Instance
        //{
        //    get
        //    {
        //        if (instance == null)
        //        {
        //            instance = new TextProcessor();
        //        }
        //        return instance;
        //    }
        //}

        public async Task <ProcessingResult> Predict(string textToPredict)
        {
            textToPredict = textToPredict.Trim();
            textToPredict = textToPredict.ToLower();

            MobileServiceInvalidOperationException exception = null;

            try
            {
                // This code refreshes the entries in the list view by querying the IntentItems table.
                // The query excludes completed IntentItems.
                items = await intentTable
                        .Where(IntentItem => IntentItem.Utterance == (textToPredict))
                        .ToCollectionAsync();

                telemetryItems = await telemetryTable.Take(1)
                                 .ToCollectionAsync();

                if (items.Count > 0)
                {
                    var item             = items[0];
                    var processingResult = new ProcessingResult();
                    processingResult.Entities    = JsonConvert.DeserializeObject <Dictionary <string, string> >(item.JsonEntities);
                    processingResult.Intent      = item.Intent;
                    processingResult.IsFromCache = true;

                    await Track(TelemetryEvents.CACHE_HIT, textToPredict);
                    await Track(TelemetryEvents.LUIS_INTENT, processingResult.Intent);

                    return(processingResult);
                }
            }
            catch (MobileServiceInvalidOperationException e)
            {
                exception = e;
                Debug.WriteLine(e);
                throw e;
            }


            await Track(TelemetryEvents.CACHE_MISS, textToPredict);

            try
            {
                LuisResult res = await _client.Predict(textToPredict);

                var intent = processRes(res);

                var temp = new ProcessingResult();
                temp.Confidence  = intent.Confidence;
                temp.Entities    = intent.Entities;
                temp.Intent      = intent.Intent;
                temp.IsFromCache = true;

                var intentItem = new IntentItem();
                intentItem.Intent       = temp.Intent;
                intentItem.Utterance    = textToPredict;
                intentItem.IsProcessed  = true;
                intentItem.JsonEntities = JsonConvert.SerializeObject(temp.Entities);

                // Insert into database
                await InsertIntentItem(intentItem);
                await Track(TelemetryEvents.LUIS_INTENT, intentItem.Intent);

                return(intent);
            }
            catch (MobileServicePushFailedException push)
            {
                //
                Debug.WriteLine(push);
                throw push;
            }
            // TODO: Refactor to have a better error handling
            catch (System.Exception e)
            {
                // Check App ID,  Luis Key , Luis URL
                // Trace error
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e);
            }

            // Save offline
            var offlineIntent = new IntentItem();

            offlineIntent.Utterance   = textToPredict;
            offlineIntent.IsProcessed = false;

            await InsertIntentItem(offlineIntent);

            return(null);
        }
Exemple #4
0
        public Object GetKBDataByPage(string q, string domain, string intent_domain, string intent_id, string pageNum)
        {
            var        emptyObject = new { result = false, msg = "未找到查询结果!" };
            IntentItem itentItem   = null;

            Domain.Intent intent = new Answer(domain).GetIntent(q);
            if (intent.qt_parsed_rst == null)
            {
                return(null);
            }

            foreach (var item in intent.qt_parsed_rst)
            {
                if (item.results == null)
                {
                    continue;
                }

                if (item.qt_domain == domain && item.results[0].domain == intent_domain && item.intent_no == intent_id)
                {
                    itentItem = item;
                    break;
                }
            }
            string intentItem = string.Empty;

            int pnum = 0;

            try
            {
                pnum = int.Parse(pageNum);
            }
            catch { return(emptyObject); }

            //try
            //{
            //    itentItem = Newtonsoft.Json.JsonConvert.DeserializeObject<IntentItem>(intentItem);
            //}
            //catch (System.Exception ex)
            //{
            //    CBase.Log.Logger.Error(ex);
            //}
            if (itentItem == null)
            {
                return(emptyObject);
            }

            itentItem.results[0].pagenum = pnum;

            CMKArea karea = null;
            var     qc    = new KB().GetItem(itentItem);

            if (qc != null && qc.Total > 0)
            {
                karea = qc.MetaList[0];
                karea.Page.PageNum = pnum;
                return(new { result = true, karea });
            }
            else
            {
                return(emptyObject);
            }

            //GetBookInfo(karea);
        }