Beispiel #1
0
        public DetailedResponse <Profile> GetInsights(string text)
        {
            string apiKey      = _appConfiguration["WatsonAPIs:PersonalityInsights:Key"];
            string version     = _appConfiguration["WatsonAPIs:PersonalityInsights:Version"];
            string instanceURL = _appConfiguration["WatsonAPIs:PersonalityInsights:InstanceURL"];

            //Check settings are OK
            if (String.IsNullOrEmpty(apiKey) || String.IsNullOrEmpty(version) || String.IsNullOrEmpty(instanceURL))
            {
                throw new Exception("Invalid PersonalityInsights API configuration. Please check appsettings.json.");
            }

            IamAuthenticator           authenticator       = new IamAuthenticator(apikey: apiKey);
            PersonalityInsightsService personalityInsights = new PersonalityInsightsService(version, authenticator);

            personalityInsights.SetServiceUrl(instanceURL);
            personalityInsights.DisableSslVerification(true);

            Content            content = new Content();
            List <ContentItem> lst     = new List <ContentItem>();

            lst.Add(new ContentItem()
            {
                Content     = text,
                Contenttype = "text/plain",
                Language    = "en"
            });
            content.ContentItems = lst;

            return(personalityInsights.Profile(
                       content: content,
                       contentType: "text/plain",
                       rawScores: true,
                       consumptionPreferences: false
                       ));
        }