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)); } }); }
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)); } }); }
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))); }
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)); }
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; }
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; }