Пример #1
0
        private async Task<DataFeed> EnrichWithImagesAsync(DataFeed feed)
        {
            const string key = "ZvD71NLFp4EFiActP24HNCNHey1r4m64bwMQPTh8AZg";

            if (!string.IsNullOrEmpty(feed.Image))
            {
                return feed;
            }
                
            if (feed.Concepts == null)
            {
                return null;
            }

            var bingContainer = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/v1/"))
            {
                Credentials = new NetworkCredential(key, key)
            };

            var imagesQuery = bingContainer.Image(string.Join(" ", feed.Concepts), null, null, "Moderate", null, null, "Size:Large");
            IEnumerable<ImageResult> imagesResults = await 
                Task<IEnumerable<ImageResult>>.Factory.FromAsync(imagesQuery.BeginExecute, imagesQuery.EndExecute, null);

            ImageResult image = imagesResults.FirstOrDefault();
            if (image != null)
            {
                feed.Image = image.MediaUrl;
                return feed;
            }

            return null;
        }
Пример #2
0
        private DataFeed EnrichWithConcepts(DataFeed feed)
        {
            try
            {
                var args = new SummarizerArguments
                {
                    DictionaryLanguage = "en",
                    DisplayLines = 1,
                    InputString = feed.Title
                };

                var summary = Summarizer.Summarize(args);
                feed.Concepts = summary.Concepts.ToArray();
            }
            catch (Exception)
            {
            }
            
            return feed;
        }
Пример #3
0
 private DataFeed NormalizeFeed(DataFeed feed)
 {
     feed.Title = HttpUtility.HtmlDecode(feed.Title);
     feed.Text = HttpUtility.HtmlDecode(feed.Text);
     return feed;
 }