Configure tokenizers for citation extraction
mainEyecite uses tokenizers to convert source text into a list of tokens (e.g., CitationToken, IdToken, StopWordToken) before scanning them. You can substitute the default tokenizer by passing a tokenizer instance to get_citations(text, tokenizer=...).
Available Tokenizers
- AhocorasickTokenizer (Default): Uses the
pyahocorasicklibrary to filter regexes and the built-inrelibrary for extraction. It is suitable for most use cases. - HyperscanTokenizer: Compiles all extraction regexes into a hyperscan database for single-pass extraction. This is significantly faster but requires the
hyperscandependency.
To install the hyperscan dependency:
pip install hyperscanBecause compiling the hyperscan database is slow, it is recommended to provide a cache_dir to HyperscanTokenizer to store the database.
from eyecite.tokenizers import HyperscanTokenizer
hyperscan_tokenizer = HyperscanTokenizer(cache_dir='.hyperscan')
cites = get_citations(text, tokenizer=hyperscan_tokenizer)