/// <summary> /// Analyses the query using Kibana and Watson /// </summary> /// <param name="objA"></param> /// <param name="objB"></param> /// <param name="aspects"></param> /// <param name="quickSearch">enables quickSearch</param> /// <returns>Returns a QueryResult object containing the results of the analysis</returns> public Capsule <QueryResult> AnalyseQuery(string objA, string objB, ICollection <string> aspects, bool quickSearch) { return // fetch elastic search data (from d in _elasticSearch.FetchData(objA, objB, aspects, quickSearch) // remove aspects from target list that do not contain any data let targets = d.AspectData != null ? (from k in d.AspectData where k.Value.ObjAData.Count > 0 && k.Value.ObjBData.Count > 0 select k.Key).ToList() : null let features = new Features { Emotion = new EmotionOptions { Targets = targets != null && targets.Any() ? targets : null, Document = true }, Keywords = new KeywordsOptions { Sentiment = true, Limit = 5 }, Sentiment = new SentimentOptions { Document = true, Targets = targets != null && targets.Any() ? targets : null, } } // perform watson analysis from arObjA in _watson.AnalyseText( string.Join(" ", d.ClassifiedData.ObjAData), features) from arObjB in _watson.AnalyseText( string.Join(" ", d.ClassifiedData.ObjBData), features) // build and return query result object let prefersObjA = (double)d.ClassifiedData.ObjAData.Count / (d.ClassifiedData.ObjAData.Count + d.ClassifiedData.ObjBData.Count) let prefersObjB = (double)d.ClassifiedData.ObjBData.Count / (d.ClassifiedData.ObjAData.Count + d.ClassifiedData.ObjBData.Count) let aspectResults = d.AspectData let objAEmotions = arObjA.Emotion?.Document?.Emotion let objBEmotions = arObjB.Emotion?.Document?.Emotion let objAKeywords = arObjA.Keywords?.Select(k => new Keyword { Text = k.Text, Relevance = k.Relevance, Sentiment = k.Sentiment.Score, }) let objBKeywords = arObjB.Keywords?.Select(k => new Keyword { Text = k.Text, Relevance = k.Relevance, Sentiment = k.Sentiment.Score, }) let objAAspectEmotions = arObjA.Emotion?.Targets?.ToDictionary(r => r.Text, r => r.Emotion) let objBAspectEmotions = arObjB.Emotion?.Targets?.ToDictionary(r => r.Text, r => r.Emotion) let objAAspectSentiment = arObjA.Sentiment?.Targets?.ToDictionary(r => r.Text, r => r.Score) let objBAspectSentiment = arObjB.Sentiment?.Targets?.ToDictionary(r => r.Text, r => r.Score) select new QueryResult { Results = d.ClassifiedData, ObjAEmotions = objAEmotions, ObjBEmotions = objBEmotions, ObjAKeywords = objAKeywords, ObjBKeywords = objBKeywords, ObjASentimentScore = arObjA.Sentiment?.Document?.Score, ObjBSentimentScore = arObjB.Sentiment?.Document?.Score, AspectResults = aspectResults, ObjAAspectEmotions = objAAspectEmotions, ObjBAspectEmotions = objBAspectEmotions, ObjAAspectSentimentScores = objAAspectSentiment, ObjBAspectSentimentScores = objBAspectSentiment }); }