コード例 #1
0
ファイル: TokensTool.cs プロジェクト: karbazol/FBReaderCS
        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, parser.Anchors, tokens);
            SaveChapters(book.BookID, parser.Chapters, tokens);
        }
コード例 #2
0
ファイル: BookSearch.cs プロジェクト: karbazol/FBReaderCS
        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>());

            if (_bookTokenIterator != null)
            {
                _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));
        }
コード例 #3
0
ファイル: BookTool.cs プロジェクト: karbazol/FBReaderCS
        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);
        }