示例#1
0
        public Task<List<BookSearchResult>> Search(BookModel book, string query, int count)
        {
            if (string.IsNullOrEmpty(query) || book == null)
                return Task<List<BookSearchResult>>.Factory.StartNew(() => new List<BookSearchResult>());

            _bookTokenIterator?.Dispose();

            _book = book;
            _bookTokenIterator = new BookTokenIterator(_book.GetTokensPath(), TokensTool.GetTokens(_book.BookID));

            _query = PrepareQuery(query);

            return Task<List<BookSearchResult>>
                .Factory.StartNew(() => Load(_bookTokenIterator, _query, count));
        }
示例#2
0
        public string GetLastParagraphByToken(BookModel book, int tokenOffset, out string pointer)
        {
            var result = new List<string>();

            using (var tokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID)))
            {                
                var token = FindNewToken(tokenOffset, tokenIterator);
                pointer = token.Pointer;
                var tokenId = token.ID;
                tokenIterator.MoveTo(tokenId);
                while (tokenIterator.MoveNext())
                {
                    if (tokenIterator.Current is TagOpenToken && result.Count > 0)
                        break;

                    var textToken = tokenIterator.Current as TextToken;
                    if (textToken == null)
                        continue;                    
                    result.Add(textToken.Text);                    
                }
            }
            return string.Join(" ", result);
        }
示例#3
0
        public string GetText(BookModel book, int tokenOffset, int wordsCount, out int lastTokenId)
        {
            lastTokenId = -1;
            var result = new List<string>();
            
            using (var tokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID)))
            {
                int words = 0;
                tokenIterator.MoveTo(tokenOffset);
                while (tokenIterator.MoveNext() && words < wordsCount)
                {
                    if (tokenIterator.Current is NewPageToken && result.Count > 0)
                        break;

                    var textToken = tokenIterator.Current as TextToken;
                    if (textToken == null)
                        continue;
                    lastTokenId = textToken.ID;
                    result.Add(textToken.Text);
                    words++;
                }
            }
            return string.Join(" ", result);
        }
示例#4
0
        public static void SaveTokens(BookModel book, IBookSummaryParser parser)
        {
            var tokens = parser.GetTokenParser().GetTokens().ToList();
            var positions = SaveTokensWithPosition(book.GetTokensPath(), tokens);

            SaveTokenPosition(book.GetTokensRefPath(), positions);

            book.TokenCount = positions.Count;
            book.WordCount = tokens.Count(t => t is TextToken);
            book.CurrentTokenID = Math.Min(tokens.Count - 1, book.CurrentTokenID);

            parser.BuildChapters();

            SaveAnchors(book.BookID, book.GetAnchorsPath(), parser.Anchors, tokens);

            SaveChapters(book.BookID, book.GetChaptersPath(), parser.Chapters, tokens);
           
            SaveInfo(book.GetFolderPath(), book.TokenCount, book.WordCount);
        }
示例#5
0
 public BookSearch(BookModel book)
 {
     _book = book;
     _bookTokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID));
 }