/// <summary> /// Generates a correctness score based on a set of keywords. /// </summary> /// <param name="scoredStatements"></param> /// <param name="keywords"></param> /// <returns></returns> public static double ScoreFromKeywords(this string answer, IEnumerable <string> keywords) { var answerKeywords = WebSearchHelper.SplitSenteceToKeywords(answer); double amountCorrect = 0; foreach (string keyword in keywords) { if (answerKeywords.Contains(keyword)) { amountCorrect++; } } return(amountCorrect / keywords.Count()); }
/// <summary> /// Invokes the vectorization/ web search with a question. /// </summary> /// <param name="question">Question being asked</param> /// <returns>Vectorized answers</returns> public Dictionary <string, double> Invoke(string question) { string domainRootUrl = SearchDomain.GenerateRootUrl(question); var searchDomainDocument = new DocumentNodeSelector(domainRootUrl); var documentLinks = searchDomainDocument .FindAllLinks() .Select(link => SearchDomain.ParseSearchUrl(link)) .Where(link => link != null) .Distinct() .ToList(); documentLinks // resize the links .RemoveRange(SearchSettings.MaxLinks, documentLinks.Count - SearchSettings.MaxLinks); var originalKeywords = WebSearchHelper.SplitSenteceToKeywords(question); var paragraphs = _generateParagraphsFromLinks(documentLinks); var scoredKeywords = _createScoredKeywords(paragraphs, originalKeywords); return(_createScoredStatements(paragraphs, scoredKeywords)); }