Example #1
0
        public async Task <CloudmersiveNLPResponse> CloudmersiveNLPResponseAsync(string type, string url)
        {
            string CloudmersiveApiKey = _config["CloudmersiveApiKey"];

            string scrapeResult = await ScrapeNewsSiteByUrlAsync(url);

            // Configure API key authorization: Apikey
            Configuration.Default.AddApiKey("Apikey", CloudmersiveApiKey); // Get an API key at, https://account.cloudmersive.com/

            var apiInstance = new AnalyticsApi();

            if (type == "sentimentality")
            {
                var input = new SentimentAnalysisRequest(scrapeResult); // SentimentAnalysisRequest | Input sentiment analysis request

                try
                {
                    // Perform Sentiment Analysis and Classification on Text
                    SentimentAnalysisResponse cloudmersiveResult = apiInstance.AnalyticsSentiment(input);

                    CloudmersiveNLPResponse cloudmersiveNLPResponse = new CloudmersiveNLPResponse
                    {
                        Successful = cloudmersiveResult.Successful,
                        SentimentClassificationResult = cloudmersiveResult.SentimentClassificationResult,
                        SentimentScoreResult          = cloudmersiveResult.SentimentScoreResult,
                        SentenceCount = cloudmersiveResult.SentenceCount,
                    };

                    return(cloudmersiveNLPResponse);
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
            else if (type == "subjectivity")
            {
                var input = new SubjectivityAnalysisRequest(scrapeResult); // SentimentAnalysisRequest | Input sentiment analysis request

                try
                {
                    // Perform Subjectivity Analysis and Classification on Text
                    SubjectivityAnalysisResponse cloudmersiveResult = apiInstance.AnalyticsSubjectivity(input);

                    CloudmersiveNLPResponse cloudmersiveNLPResponse = new CloudmersiveNLPResponse
                    {
                        Successful = cloudmersiveResult.Successful,
                        SubjectivityScoreResult = cloudmersiveResult.SubjectivityScoreResult,
                        SentenceCount           = cloudmersiveResult.SentenceCount,
                    };

                    return(cloudmersiveNLPResponse);
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public async Task <ActionResult <CloudmersiveNLPResponse> > AnalyzeNewsAsync(string type, string url)
        {
            CloudmersiveNLPResponse cloudmersiveNLPResponse = await _newsRepository.CloudmersiveNLPResponseAsync(type, url);

            return(Ok(cloudmersiveNLPResponse));
        }