コード例 #1
0
        public DocumentRetrievalActor()
        {
            Receive <RetrieveDocumentRequestMessage>(async r =>
            {
                try
                {
                    var request  = new HttpRequestMessage(HttpMethod.Get, r.DocumentUri);
                    var response = await DoHttpRequestAsync(request, r.Timeout);

                    if (response.Content.Headers.ContentType.MediaType != MimeTypeNames.Html)
                    {
                        throw new UnsupportedDocumentContentTypeException(response.Content.Headers.ContentType.MediaType, r.DocumentUri);
                    }

                    var htmlResult      = await response.Content.ReadAsStringAsync();
                    var documentVector  = vectorizeDocument(htmlResult);
                    var searchResultDoc = new SearchResultDocument(r.SearchUri, r.FoodNameQuery, r.DocumentUri, documentVector);
                    Sender.Tell(new RetrieveDocumentResultMessage(r, searchResultDoc));
                }
                catch (Exception exp)
                {
                    Sender.Tell(new RetrieveDocumentFailedMessage(r, exp));
                }
            });
        }
コード例 #2
0
        public DocumentRetrievalActor()
        {
            Receive<RetrieveDocumentRequestMessage>(async r =>
            {
                try
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, r.DocumentUri);
                    var response = await DoHttpRequestAsync(request, r.Timeout);

                    if (response.Content.Headers.ContentType.MediaType != MimeTypeNames.Html)
                    {
                        throw new UnsupportedDocumentContentTypeException(response.Content.Headers.ContentType.MediaType, r.DocumentUri);
                    }

                    var htmlResult = await response.Content.ReadAsStringAsync();
                    var documentVector = vectorizeDocument(htmlResult);
                    var searchResultDoc = new SearchResultDocument(r.SearchUri, r.FoodNameQuery, r.DocumentUri, documentVector);
                    Sender.Tell(new RetrieveDocumentResultMessage(r, searchResultDoc));
                }
                catch (Exception exp)
                {
                    Sender.Tell(new RetrieveDocumentFailedMessage(r, exp));
                }
            });
        }
コード例 #3
0
        private DocumentScore scoreDocumentForTermsAsync(SearchResultDocument document, FoodNameTerms terms)
        {
            var documentVector = document.DocumentVector;
            var score          = new Double[documentVector.Length];

            for (var i = 0; i < documentVector.Length; i++)
            {
                if (terms.Contains(documentVector[i]))
                {
                    score[i] = 1.0;
                }
            }

            return(new DocumentScore(document, terms, new FoodNameScoreVector(score)));
        }
コード例 #4
0
        private DocumentScore scoreDocumentForTermsAsync(SearchResultDocument document, FoodNameTerms terms)
        {
            var documentVector = document.DocumentVector;
            var score = new Double[documentVector.Length];

            for (var i = 0; i < documentVector.Length; i++)
            {
                if (terms.Contains(documentVector[i]))
                {
                    score[i] = 1.0;
                }
            }

            return new DocumentScore(document, terms, new FoodNameScoreVector(score));
        }
コード例 #5
0
        public DocumentScore(SearchResultDocument document, FoodNameTerms terms, FoodNameScoreVector foodNameScoreVector)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (terms == null)
            {
                throw new ArgumentNullException(nameof(terms));
            }
            if (foodNameScoreVector == null)
            {
                throw new ArgumentNullException(nameof(foodNameScoreVector));
            }

            Document      = document;
            FoodNameTerms = terms;
            ScoreVector   = foodNameScoreVector;
        }
コード例 #6
0
        public DocumentScore(SearchResultDocument document, FoodNameTerms terms, FoodNameScoreVector foodNameScoreVector)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (terms == null)
            {
                throw new ArgumentNullException(nameof(terms));
            }
            if (foodNameScoreVector == null)
            {
                throw new ArgumentNullException(nameof(foodNameScoreVector));
            }

            Document = document;
            FoodNameTerms = terms;
            ScoreVector = foodNameScoreVector;
        }
コード例 #7
0
        public ScoreDocumentRequestMessage(SearchResultDocument document, FoodNameTerms foodNameTerms, FoodNameTerms sourceFoodTerms)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (foodNameTerms == null)
            {
                throw new ArgumentNullException(nameof(foodNameTerms));
            }

            if (sourceFoodTerms == null)
            {
                throw new ArgumentNullException(nameof(sourceFoodTerms));
            }

            Document        = document;
            FoodNameTerms   = foodNameTerms;
            SourceFoodTerms = sourceFoodTerms;
        }
コード例 #8
0
        public ScoreDocumentRequestMessage(SearchResultDocument document, FoodNameTerms foodNameTerms, FoodNameTerms sourceFoodTerms)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (foodNameTerms == null)
            {
                throw new ArgumentNullException(nameof(foodNameTerms));
            }

            if (sourceFoodTerms == null)
            {
                throw new ArgumentNullException(nameof(sourceFoodTerms));
            }

            Document = document;
            FoodNameTerms = foodNameTerms;
            SourceFoodTerms = sourceFoodTerms;
        }