public LibraryCataloguer(BookParserConfig configuration, ConcurrentQueue <Exception> exceptions,
                                 IBookParserTrace tracer, Action <int> progress)
        {
            Progress = progress ?? throw new ArgumentNullException(nameof(progress));

            Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            GetMetadataFromFileDictionaryDelegate = new Dictionary <String, Delegate>()
            {
                { ".pdf", new Func <string, BookAtHome>(new PdfTextReaderFileInfoExtractor().GetPocoBook) },
                { ".txt", new Func <string, BookAtHome>(new FileInfoExtractor().GetPocoBook) },
                { ".rtf", new Func <string, BookAtHome>(new RtfFileInfoExtractor().GetPocoBook) },
                { ".epub", new Func <string, BookAtHome>(new EpubFileInfoExtractor().GetPocoBook) },
                { ".lit", new Func <string, BookAtHome>(new LitFileInfoExtractor().GetPocoBook) },
                { ".doc", new Func <string, BookAtHome>(new FileInfoExtractor().GetPocoBook) }
            };


            _mongoServerManager = new MongodbServerManager(Configuration.libraryContext.hostname);

            BooksInLibrary = new BooksCollectedDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            BookToReview = new BookToBeReviewedDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            LibStatistics = new LibraryStatisticsDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            _tracer = tracer;

            _exceptions = exceptions;

            Init();
        }
Beispiel #2
0
        private static BookAtHome FindTheBookInfoFromCollection(string fileunderanalysis, List <PocoBook> booksFromProvider,
                                                                string maytitle, IBookParserTrace trace)
        {
            var titlecomparer       = new TitleCompareBookFinder(fileunderanalysis, trace);
            var levenshteincomparer = new LevenshteinBookFinder(fileunderanalysis, trace);

            titlecomparer.SetNext(levenshteincomparer);

            return(titlecomparer.HandleTheBookFromList(maytitle, booksFromProvider));
        }
Beispiel #3
0
        private Rootobject ExecuteGoogleRequest(PocoBook book, IRestClient restclient, IBookParserTrace trace)
        {
            trace.TraceInfo("GetBooks start for book {0}", book.Title);

            string url = String.Format("https://www.googleapis.com/books/v1/volumes?q={0}&maxResults=40&country=IT", BuildQuery(book));

            Rootobject root = GoogleRestBooksRequest(restclient, url);

            if (root == null)
            {
                string query = string.Format("intitle:{0}", book.Title);
                url = String.Format("https://www.googleapis.com/books/v1/volumes?q={0}&maxResults=40&country=IT", query);

                return(GoogleRestBooksRequest(restclient, url));
            }
            else
            {
                return(root);
            }
        }
Beispiel #4
0
        public override List <PocoBook> GetBooks(PocoBook book, IRestClient restclient, IBookParserTrace trace)
        {
            Rootobject rootresponse = ExecuteGoogleRequest(book, restclient, trace);

            return(GetBookFromRest(rootresponse, book.File));
        }
Beispiel #5
0
 public abstract List <PocoBook> GetBooks(PocoBook book, IRestClient restclient, IBookParserTrace trace);
Beispiel #6
0
        public static BookAtHome AnalyzeResults(PocoBook minimalbookinfo, List <PocoBook> booksFromProvider, IBookParserTrace trace)
        {
            trace?.TraceInfo("AnalyzeResults start");
            if (booksFromProvider == null || booksFromProvider.Count == 0)
            {
                if (!String.IsNullOrEmpty(minimalbookinfo?.Title) && minimalbookinfo.Authors.Count != 0)
                {
                    minimalbookinfo.BookReliability = PocoBook.Reliability.Medium;
                    return(minimalbookinfo);
                }

                throw new ArgumentNullException(nameof(booksFromProvider));
            }

            if (booksFromProvider.Count == 1)
            {
                booksFromProvider.First().BookReliability = PocoBook.Reliability.High;
                return(booksFromProvider.First());
            }

            if (!string.IsNullOrEmpty(minimalbookinfo.SearchPhrase))
            {
                booksFromProvider.First().BookReliability = PocoBook.Reliability.Medium;
                return(booksFromProvider.First());
            }

            return(FindTheBookInfoFromCollection(minimalbookinfo.File, booksFromProvider, minimalbookinfo.SearchTitle, trace));
        }
 public TitleCompareBookFinder(string fileunderanalysis, IBookParserTrace trace) : base(fileunderanalysis)
 {
     _trace = trace;
 }
Beispiel #8
0
 public LevenshteinBookFinder(string fileunderanalysis, IBookParserTrace trace) : base(fileunderanalysis)
 {
     _trace = trace;
 }
 public override BookatHome HandleTheBook(string fileunderanalysis, List <PocoBook> booklist, string maybetitle, IBookParserTrace trace)
 {
     trace.TraceInfo("TitleCompareBookFinder --> HandleTheBook start");
     foreach (var book in booklist)
     {
         if (book.Title.Contains(maybetitle, StringComparison.OrdinalIgnoreCase))
         {
             return(book);
         }
     }
     return(base.HandleTheBook(fileunderanalysis, booklist, maybetitle, trace));
 }
Beispiel #10
0
 public virtual BookatHome HandleTheBook(string fileunderanalysis, List <PocoBook> booklist, string maybetitle, IBookParserTrace trace)
 {
     if (this._nextHandler != null)
     {
         return(this._nextHandler.HandleTheBook(fileunderanalysis, booklist, maybetitle, trace));
     }
     else
     {
         return(new BookToBeReviewed(fileunderanalysis, "book not handled"));
     }
 }
Beispiel #11
0
        public override BookatHome HandleTheBook(string fileunderanalysis, List <PocoBook> booklist, string maybetitle, IBookParserTrace trace)
        {
            trace.TraceInfo("LevenshteinBookFinder --> HandleTheBook start");

            int bookindex  = -1;
            int lddistance = int.MaxValue;
            int i          = 0;

            foreach (var book in booklist)
            {
                if (string.Compare(book.Title, maybetitle, true) != 0)
                {
                    // non trovato il libro
                    int retval = LevenshteinDistance.Compute(book.Title, maybetitle);
                    if (retval < lddistance)
                    {
                        lddistance = retval;
                        bookindex  = i;
                    }
                }
                else
                {
                    lddistance = 0;
                    bookindex  = i;
                    break;
                }
                i++;
            }
            if (lddistance < Levenshteinthreshold)
            {
                if (lddistance < 4)
                {
                    booklist[bookindex].BookReliability = PocoBook.Reliability.High;
                }
                else
                {
                    booklist[bookindex].BookReliability = PocoBook.Reliability.Low;
                }

                return(booklist[bookindex]);
            }
            return(base.HandleTheBook(fileunderanalysis, booklist, maybetitle, trace));
        }