public ParsedBookInfo ParseBookTitleFuzzy(string title) { var bestScore = 0.0; Author bestAuthor = null; Book bestBook = null; var possibleAuthors = _authorService.GetReportCandidates(title); foreach (var author in possibleAuthors) { _logger.Trace($"Trying possible author {author}"); var authorMatch = title.FuzzyMatch(author.Metadata.Value.Name, 0.5); var possibleBooks = _bookService.GetCandidates(author.AuthorMetadataId, title); foreach (var book in possibleBooks) { var bookMatch = title.FuzzyMatch(book.Title, 0.5); var score = (authorMatch.Item3 + bookMatch.Item3) / 2; _logger.Trace($"Book {book} has score {score}"); if (score > bestScore) { bestAuthor = author; bestBook = book; } } var possibleEditions = _editionService.GetCandidates(author.AuthorMetadataId, title); foreach (var edition in possibleEditions) { var editionMatch = title.FuzzyMatch(edition.Title, 0.5); var score = (authorMatch.Item3 + editionMatch.Item3) / 2; _logger.Trace($"Edition {edition} has score {score}"); if (score > bestScore) { bestAuthor = author; bestBook = edition.Book.Value; } } } _logger.Trace($"Best match: {bestAuthor} {bestBook}"); if (bestAuthor != null) { return(Parser.ParseBookTitleWithSearchCriteria(title, bestAuthor, new List <Book> { bestBook })); } return(null); }
private List <CandidateEdition> GetDbCandidatesByAuthor(LocalEdition localEdition, Author author, bool includeExisting) { _logger.Trace("Getting candidates for {0}", author); var candidateReleases = new List <CandidateEdition>(); var bookTag = localEdition.LocalBooks.MostCommon(x => x.FileTrackInfo.BookTitle) ?? ""; if (bookTag.IsNotNullOrWhiteSpace()) { var possibleBooks = _bookService.GetCandidates(author.AuthorMetadataId, bookTag); foreach (var book in possibleBooks) { candidateReleases.AddRange(GetDbCandidatesByBook(book, includeExisting)); } var possibleEditions = _editionService.GetCandidates(author.AuthorMetadataId, bookTag); candidateReleases.AddRange(GetDbCandidatesByEdition(possibleEditions, includeExisting)); } return(candidateReleases); }