Example #1
0
        public static string SayWhat(string inquery, string youser)
        {
            string  what      = string.Empty;
            dynamic cognition = null;

            try
            {
                dynamic jsonO = SearchOnInquery(inquery);
                dynamic items = jsonO.items;
                if (items != null)
                {
                    var oneD  = items[0].data;
                    var blarg = oneD.@abstract;
                    var blug  = blarg.consumer;
                    var langO = blug["en-us"];
                    what = GetTheFirstSentence((string)langO);
                    //what = jsonO.items[0].data.abstract.consumer.en-us;
                    what = EmoticonifyIt(what);
                }
                //check the semantics of the inquiry
                cognition = jsonO.cognition;
                int confidence = cognition.confidence;

                //prepend a confidence emoticon/response
                what = Emoticons.EmoticonifyTheConfidence(confidence) + " " + what;

                //specify any replaced terms
                var replaced_terms = cognition.replaced_terms ?? null;
                if (replaced_terms != null)
                {
                    if (replaced_terms.HasValues)
                    {
                        what = $"[{replaced_terms[0]}?] {what}";
                    }
                }
            }
            catch (WebException wex)
            {
                what = wex.Message;
            }
            if (string.IsNullOrWhiteSpace(what))
            {
                what = Responses.GetARandomResponse();
            }
            what = what.Replace("\\r\\n", "");
            what = what.TrimStart();
            what = what.Trim();
            //Log
            LogThisAsync(youser, cognition, what);
            return(what);
        }
Example #2
0
        private static string EmoticonifyIt(string sentence)
        {
            //analyze it
            dynamic blargo    = SearchOnInquery(sentence);
            dynamic cognition = blargo.cognition;

            if (cognition != null)
            {
                dynamic entities = cognition.hw_entities;
                if (entities != null)
                {
                    //any aspects to be matched?
                    dynamic aspects = entities.aspects;
                    if (aspects != null)
                    {
                        string recognized_aspects = aspects[0];
                        return(sentence + " " + Emoticons.EmoticonFromAspect(recognized_aspects));
                    }
                }
            }
            return(sentence);
        }