//Creates the necessary objects and sends the request to the service class to update the knowledgebase with the userQuestion
        protected async Task StoreFeedback(IDialogContext context)
        {
            if (this.feedbackRecord != null)
            {
                // Uncomment to check for more than 1 keyword before adding question to phrase
                //var kWords = await Global.TextAnalytics.GetKeyphrases(feedbackRecord.userQuestion);
                //if (kWords.documents[0].keyPhrases.Length >= 2) // if the query contains more than one keyword update the knowledge base with query
                //{
                var kbUpdates = new KbUpdateRequest {
                    update = new ItemsToUpdate {
                        QnaList = new List <KbItemToUpdate>()
                    }
                };
                var questionToUpdate = new KbItemToUpdate()
                {
                    qnaId = this.feedbackRecord.kbQuestionId, questions = new QuestionsUpdateModel {
                        add = new string[] { this.feedbackRecord.userQuestion }
                    }
                };
                kbUpdates.update.QnaList.Add(questionToUpdate);
                await qnaService.UpdateKnowledgebase(kbUpdates);

                //}
            }
        }
예제 #2
0
        private ItemsToUpdate GenerateItemsToUpdateModel(IEnumerable <KbItem> currentKnowledgeBaseItems, List <QnAItem> qnaItems, bool resetQuestion = false)
        {
            var itemsToUpdateModel = new ItemsToUpdate
            {
                name = KnowledgeBaseName,
                urls = new string[] { }
            };

            var kbItemsToUpdate = new List <KbItemToUpdate>();

            foreach (var kbItem in currentKnowledgeBaseItems)
            {
                var kbItemIdMetaDataItem = kbItem.metadata.FirstOrDefault(m => m.name == "itemid");

                if (kbItemIdMetaDataItem != null)
                {
                    // id convert
                    var qnaItem = qnaItems.FirstOrDefault(f => f.ItemId.ToString() == kbItemIdMetaDataItem.value);

                    if (qnaItem != null)
                    {
                        var updatedKbItem = new KbItemToUpdate
                        {
                            qnaId     = kbItem.qnaId,
                            answer    = qnaItem.Answer,
                            questions = new QuestionsUpdateModel()
                        };


                        if (resetQuestion)
                        {
                            var questionsToAdd    = qnaItem.Questions.ToList().Where(q => !kbItem.questions.ToList().Contains(q));
                            var questionsToDelete = kbItem.questions.ToList().Where(q => !questionsToAdd.Contains(q)); // Will delete questions that aren't in the documentation, resets qna-pairing..
                            updatedKbItem.questions.delete = questionsToDelete.ToArray();
                            updatedKbItem.questions.add    = questionsToAdd.ToArray();
                        }
                        else
                        {
                            var questionsToAdd = qnaItem.Questions.ToList();
                            updatedKbItem.questions.add = questionsToAdd.ToArray();
                        }


                        List <MetadataItem> metaDataItemsToDelete = new List <MetadataItem>();
                        metaDataItemsToDelete = kbItem.metadata
                                                .Where(m => !qnaItem.Metadata.Select(f => f.name).Contains(m.name)).ToList();


                        var metaDataItemsToAddOrUpdate = new List <MetadataItem>
                        {
                            new MetadataItem()
                            {
                                name  = "itemid",
                                value = qnaItem.ItemId.ToString()
                            },
                            new MetadataItem()
                            {
                                name  = "isactive",
                                value = qnaItem.IsActive.ToString()
                            }
                        };

                        foreach (var metadataItem in qnaItem.Metadata)
                        {
                            metaDataItemsToAddOrUpdate.Add(new MetadataItem()
                            {
                                name  = metadataItem.name,
                                value = metadataItem.value
                            });
                        }

                        updatedKbItem.metadata = new MetaDataUpdateModel
                        {
                            add    = metaDataItemsToAddOrUpdate.ToArray(),
                            delete = metaDataItemsToDelete.ToArray()
                        };

                        kbItemsToUpdate.Add(updatedKbItem);
                    }
                }
            }

            itemsToUpdateModel.qnaList = kbItemsToUpdate.ToArray();
            return(itemsToUpdateModel);
        }
예제 #3
0
        private ItemsToUpdate GenerateItemsToUpdateModel(IEnumerable <KbItem> currentKnowledgeBaseItems, List <QnAItem> qnaItems)
        {
            var itemsToUpdateModel = new ItemsToUpdate
            {
                name = KnowledgeBaseName,
                urls = new string[] { }
            };

            var kbItemsToUpdate = new List <KbItemToUpdate>();

            foreach (var kbItem in currentKnowledgeBaseItems)
            {
                var kbItemIdMetaDataItem = kbItem.metadata.FirstOrDefault(m => m.name == "itemId");

                if (kbItemIdMetaDataItem != null)
                {
                    var qnaItem = qnaItems.FirstOrDefault(f => f.ItemId == kbItemIdMetaDataItem.value);

                    if (qnaItem != null)
                    {
                        var updatedKbItem = new KbItemToUpdate
                        {
                            qnaId     = kbItem.qnaId,
                            answer    = qnaItem.Answer,
                            questions = new QuestionsUpdateModel()
                        };

                        var questionsToAdd = qnaItem.Questions.ToList();
                        updatedKbItem.questions.add = questionsToAdd.ToArray();

                        var questionsToDelete = kbItem.questions.ToList().Where(q => !questionsToAdd.Contains(q));
                        updatedKbItem.questions.delete = questionsToDelete.ToArray();

                        var metaDataItemsToDelete = kbItem.metadata
                                                    .Where(m => !qnaItem.Metadata.Select(f => f.Key).Contains(m.name)).ToList();

                        var metaDataItemsToAddOrUpdate = new List <MetaDataItem>
                        {
                            new MetaDataItem()
                            {
                                name  = "itemId",
                                value = qnaItem.ItemId
                            }
                        };

                        foreach (var metadataItem in qnaItem.Metadata)
                        {
                            metaDataItemsToAddOrUpdate.Add(new MetaDataItem()
                            {
                                name  = metadataItem.Key,
                                value = metadataItem.Value
                            });
                        }

                        updatedKbItem.metadata = new MetaDataUpdateModel
                        {
                            add    = metaDataItemsToAddOrUpdate.ToArray(),
                            delete = metaDataItemsToDelete.ToArray()
                        };

                        kbItemsToUpdate.Add(updatedKbItem);
                    }
                }
            }

            itemsToUpdateModel.qnaList = kbItemsToUpdate.ToArray();
            return(itemsToUpdateModel);
        }