Building blocks for spacy Matcher patterns
Project description
corpus-patterns
A preparatory utils library.
Create a custom tokenizer
from corpus_patterns import set_tokenizer
nlp = spacy.blank("en")
nlp.tokenizer = set_tokenizer(nlp)
The tokenizer:
- Removes dashes from infixes
- Adds prefix/suffix rules for parenthesis/brackets
- Adds special exceptions to treat dotted text as a single token
Add .jsonl files to directory
Each file will contain lines of spacy matcher patterns.
from corpus_patterns import create_rules
from pathlib import Path
create_rules(folder=Path(Path("location-here"))) # check directory
Search database for text fragments
from corpus_patterns import set_txtcat_jsonl_files
jsonl_dir = set_txtcat_jsonl_files() # returns directory `ASSET_PATH/txtcats`
Utils
annotate_fragments()
- given an nlp object and some*.txt
files, create a single annotation*.jsonl
fileextract_lines_from_txt_files()
- accepts an iterator of*.txt
files and yields each line (after sorting the same and ensuring uniqueness of content).split_data()
- given a list of text strings, split the same into two groups and return a dictionary containing these groups based on the ratio provided (defaults to 0.80)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
corpus_patterns-0.0.5.tar.gz
(17.1 kB
view hashes)
Built Distribution
Close
Hashes for corpus_patterns-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f24b8bfcbd76dff4106180fcb653d9c39e14b3b037a6895b1c0fbf79b892e5 |
|
MD5 | b78b1a37a9ff647d4cc4d9672728cc29 |
|
BLAKE2b-256 | 63f186906be8cbfb8ef15b3746cf6fa4919817579ba853bfafa6d5147c3c25ad |