private async Task<IEnumerable<NewsItem>> GetNewsItemsFromWebhoseResponse(WebhoseResponse webhoseResponse, int keywordCount, double namedEntitiesThreshold)
        {
            var newsItems = new List<NewsItem>();

            if (webhoseResponse.posts.Count > 0)
            {
                Dictionary<string, double>[] keywords = await nlpClient.GetKeywordsAsync(webhoseResponse.posts.Select(p => p.text));
                double[] sentimentAnalysisResults = await nlpClient.AnalyseSentimentAsync(webhoseResponse.posts.Select(p => p.text));
                Dictionary<string, NamedEntity>[] namedEntities = await nlpClient.GetNamedEntities(webhoseResponse.posts.Select(p => p.text), namedEntitiesThreshold);

                for (int i = 0; i < webhoseResponse.posts.Count; ++i)
                {
                    var webhosePost = webhoseResponse.posts[i];
                    newsItems.Add(new NewsItem()
                    {
                        Author = webhosePost.author,
                        KeyWords = keywords[i],
                        PerformanceScore = int.Parse(webhosePost.thread.performanceScore),
                        Published = webhosePost.published,
                        SectionTitle = webhosePost.thread.sectionTitle,
                        SentimentScore = sentimentAnalysisResults[i],
                        SiteSection = webhosePost.thread.siteSection,
                        Title = webhosePost.title,
                        Url = webhosePost.url,
                        Website = webhosePost.thread.site,
                        NamedEntities = namedEntities[i],
                        PoliticalSentiments = await nlpClient.GetPoliticalSentimentsAsync(webhosePost.text)
                    });
                }
            }
            
            return newsItems;
        }
 private async Task<NewsLookupResult> CreateNewsLookupResult(int performanceScore, int keywordCount, double namedEntitiesThreshold, WebhoseResponse webhoseResponse)
 {
     return new NewsLookupResult()
     {
         NextUrl = webhoseResponse.moreResultsAvailable != 0 ? webhoseResponse.next : null,
         NewsItems = FilterNewsItemsByPerformanceScore(await GetNewsItemsFromWebhoseResponse(webhoseResponse, keywordCount, namedEntitiesThreshold), performanceScore)
     };
 }
Пример #3
0
        public static void Main(string[] args)
        {
//			//for better console output
//			Console.OutputEncoding = Encoding.UTF8;
//			Console.InputEncoding = Encoding.UTF8;

            WebhoseRequest  clientRequest = new WebhoseRequest("YOUR_APIKEY");
            WebhoseResponse response      = clientRequest.getResponse("aftonbladet");

            foreach (WebhosePost post in response.posts)
            {
                //Console.WriteLine (post);
            }
            Console.WriteLine();

            //exapmle for query
            WebhoseQuery clientQuery = new WebhoseQuery();

            clientQuery.AddAllTerms("apple");                            // what you want to search
            clientQuery.AddSomeTerms("apple iphone", "samsung", "esny"); // words that may be in the search
            clientQuery.AddLanguages(Languages.english);
            clientQuery.AddSiteSuffix("com");                            // Limit the results to a specific site suffix
            //clientQuery.AddSites ("macnn.com", "appleinsider.com");
            //clientQuery.AddOrganization ("apple", "MNM Media");
            clientQuery.ResponseSize = 50;
            clientQuery.Author       = "";
            clientQuery.AddCountries("US");              // filtring by country  - give much less data - To get the full country code list, visit countrycode.org.

            Console.WriteLine("responceWithQuery");
            WebhoseResponse responceWithQuery = clientRequest.getResponse(clientQuery);

            Console.WriteLine(responceWithQuery);

            Console.ReadKey();

            //Just change NEW_API_KEY to your new API
            //clientRequest.setAPI("NEW_API_KEY");

            WebhoseResponse moreFromResponse = response.getNext();

            Console.WriteLine(moreFromResponse.posts.Count);
            Console.WriteLine(response.posts [5].title);

            //for getting post every 5 minutes
            //			while(true) {
            //				try {
            //					foreach (webhosePost post in response.posts)
            //					{
            //						//just change the performAction to what you want to do with your posts
            //						//performAction(post);
            //					}
            //					Thread.Sleep(300000);
            //					response = response.getNext();
            //
            //				} catch (ThreadInterruptedException e) {
            //					Console.WriteLine (e.Message);
            //					break;
            //				}
            //			}

            Console.WriteLine("total:" + response.totalResults);
            Console.WriteLine("response" + response.posts.Count);
        }
        public void  getDataFromWebhose(String searchKeyword)
        {
            WebhoseRequest  clientRequest = new WebhoseRequest("cd385b5f-6734-426d-bbe2-0b4d938d46bf");
            WebhoseResponse response      = clientRequest.getResponse("aftonbladet");

            //foreach (WebhosePost post in response.posts)
            //{
            //Console.WriteLine (post);
            //}
            //Console.WriteLine();

            //exapmle for query
            WebhoseQuery clientQuery = new WebhoseQuery();

            clientQuery.AddAllTerms(txtSearchKeyword.Text); // what you want to search
            //clientQuery.AddSomeTerms("apple iphone", "samsung", "esny"); // words that may be in the search
            clientQuery.AddLanguages(Languages.english);
            //clientQuery.AddSiteSuffix("com"); // Limit the results to a specific site suffix
            //clientQuery.AddOrganization("apple", "");
            //clientQuery.AddSites ("macnn.com", "appleinsider.com");
            //clientQuery.AddOrganization ("apple", "MNM Media");
            clientQuery.ResponseSize = 50;
            //clientQuery.Author = "";
            clientQuery.AddCountries("US"); // filtring by country  - give much less data - To get the full country code list, visit countrycode.org.

            Console.WriteLine("responceWithQuery");
            WebhoseResponse responceWithQuery = clientRequest.getResponse(clientQuery);

            Console.WriteLine(responceWithQuery);

            //Console.ReadKey();

            //Just change NEW_API_KEY to your new API
            //clientRequest.setAPI("NEW_API_KEY");

            WebhoseResponse moreFromResponse = response.getNext();

            Console.WriteLine(moreFromResponse.posts.Count);

            List <Text> blogText = new List <Text>();

            int i = 0;

            foreach (WebhosePost post in moreFromResponse.posts)
            {
                blogText.Add(new Text()
                {
                    BlobTitle = moreFromResponse.posts[i].title, BlobText = moreFromResponse.posts[i].text, FetchTimestamp = moreFromResponse.posts[i].crawled
                });
                i++;
            }
            if (IsPostBack)
            {
                repPeople.DataSource = blogText;
                repPeople.DataBind();
            }

            Console.WriteLine(response.posts[5].title);

            //for getting post every 5 minutes
            //			while(true) {
            //				try {
            //					foreach (webhosePost post in response.posts)
            //					{
            //						//just change the performAction to what you want to do with your posts
            //						//performAction(post);
            //					}
            //					Thread.Sleep(300000);
            //					response = response.getNext();
            //
            //				} catch (ThreadInterruptedException e) {
            //					Console.WriteLine (e.Message);
            //					break;
            //				}
            //			}

            Console.WriteLine("total:" + response.totalResults);
            Console.WriteLine("response" + response.posts.Count);
            txtRevPost.Text = response.posts.Count.ToString();
            //var client = new WebhoseClient(token: "cd385b5f-6734-426d-bbe2-0b4d938d46bf");
            //var output =  client.QueryAsync("filterWebData", new Dictionary<string, string> { { "q", txtSearchKeyword.Text } }).Result;
        }