Ejemplo n.º 1
0
        private static async Task <float> ScoreFeedAsync(IFeedSubscription feedSubscription)
        {
            float score = 0;

            var requestUrl = new Uri("https://viewpointreaderwebapi.azurewebsites.net/api/subscriptions/scorefeed");

            using (var request = new HttpRequestMessage(HttpMethod.Post, requestUrl))
            {
                using (var stringContent =
                           new StringContent(JsonConvert.SerializeObject(feedSubscription), Encoding.UTF8, "application/json"))
                {
                    var httpClient = new HttpClient();
                    request.Content = stringContent;

                    var responseMessage = await httpClient.SendAsync(request);

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        float.TryParse(await responseMessage.Content.ReadAsStringAsync(), out score);
                    }
                }
            }

            return(score);
        }
Ejemplo n.º 2
0
        public async Task <float> ScoreFeed(IFeedSubscription feedSubscription)
        {
            if (!feedSubscription.KeyPhrases.Any())
            {
                return(0);
            }

            await LoadModel();

            var testFeedData = new FeedData
            {
                KeyPhrases = feedSubscription.KeyPhrases.ToArray()
            };

            try
            {
                MLContext mlContext        = new MLContext();
                var       predictionEngine =
                    mlContext.Model.CreatePredictionEngine <FeedData, FeedRecommendation>(_trainedModel);

                var prediction = predictionEngine.Predict(testFeedData);
                return(prediction.Score);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(0);
        }
        private FeedSubscriptionDo TransformToSubscriptionDo(IFeedSubscription feedSubscription)
        {
            var feedSubscriptionDo = new FeedSubscriptionDo
            {
                Id             = feedSubscription.Id,
                Title          = feedSubscription.Title,
                Description    = feedSubscription.Description,
                Url            = feedSubscription.Url,
                ImageUrl       = feedSubscription.ImageUrl,
                LastUpdated    = feedSubscription.LastUpdated,
                KeyPhrases     = BuildCommaDelimitedStringFromStringList(feedSubscription.KeyPhrases),
                SubscribedDate = feedSubscription.SubscribedDate,
            };

            return(feedSubscriptionDo);
        }
        private FeedSubscriptionEntity TransformToFeedSubscriptionEntity(IFeedSubscription feedSubscription)
        {
            var feedSubscriptionEntity = new FeedSubscriptionEntity
            {
                PartitionKey   = feedSubscription.Id.ToString(),
                RowKey         = feedSubscription.Title,
                Description    = feedSubscription.Description,
                Url            = feedSubscription.Url,
                ImageUrl       = feedSubscription.ImageUrl,
                LastUpdated    = feedSubscription.LastUpdated,
                KeyPhrases     = BuildCommaDelimitedStringFromStringList(feedSubscription.KeyPhrases),
                SubscribedDate = feedSubscription.SubscribedDate,
            };

            return(feedSubscriptionEntity);
        }
        public async Task <int> SaveFeedSubscriptionAsync(IFeedSubscription feedSubscription)
        {
            var feedSubscriptionDo = TransformToSubscriptionDo(feedSubscription);

            if (feedSubscription.Id > 0)
            {
                await _databaseConnection.UpdateAsync(feedSubscriptionDo);
            }
            else
            {
                await _databaseConnection.InsertAsync(feedSubscriptionDo);
            }

            if (feedSubscription.FeedItems.Any())
            {
                await SaveFeedItems(feedSubscription.FeedItems, feedSubscriptionDo.Id);
            }

            return(feedSubscriptionDo.Id);
        }
        public async Task <int> SaveFeedSubscriptionAsync(IFeedSubscription feedSubscription)
        {
            var newFeedSubscriptionEntity = TransformToFeedSubscriptionEntity(feedSubscription);

            if (_feedSubscriptionsTable == null)
            {
                _feedSubscriptionsTable = await CreateTableAsync(_feedSubscriptionsTableName);
            }

            try
            {
                TableOperation insertMergeOperation = TableOperation.InsertOrMerge(newFeedSubscriptionEntity);
                TableResult    result = await _feedSubscriptionsTable.ExecuteAsync(insertMergeOperation);

                await UpdateModel();

                return(result.HttpStatusCode);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
 public Task <int> DeleteFeedSubscriptionAsync(IFeedSubscription feedSubscription)
 {
     return(_databaseConnection.DeleteAsync(TransformToSubscriptionDo(feedSubscription)));
 }
 public Task <int> DeleteFeedSubscriptionAsync(IFeedSubscription feedSubscription)
 {
     throw new NotImplementedException();
 }