Example #1
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));
        }
Example #2
0
 public void Init()
 {
     if (_bookTokenIterator != null && _book != null)
     {
         int tokenId = _bookTokenIterator.Current.ID;
         _bookTokenIterator.Dispose();
         _bookTokenIterator = new BookTokenIterator(_book.GetTokensPath(), TokensTool.GetTokens(_book.BookID));
         _bookTokenIterator.MoveTo(tokenId);
         _bookTokenIterator.MoveNext();
     }
 }
Example #3
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>()));
            }

            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)));
        }