Skip to main content

corpus-patterns

Github CI

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:

  1. Removes dashes from infixes
  2. Adds prefix/suffix rules for parenthesis/brackets
  3. Adds special exceptions to treat dotted text as a single token

Use with modified config file:

@spacy.registry.tokenizers("test")  # type: ignore
def create_corpus_tokenizer():
    def create_tokenizer(nlp):
        return set_tokenizer(nlp)
    return create_tokenizer

nlp = spacy.load("en_core_web_sm", config={"nlp": {"tokenizer": {"@tokenizers": "test"}}},
)

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("location-here"))  # check directory

Utils

  1. annotate_fragments() - given an nlp object and some *.txt files, create a single annotation *.jsonl file
  2. extract_lines_from_txt_files() - accepts an iterator of *.txt files and yields each line (after sorting the same and ensuring uniqueness of content).
  3. 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)

Release files for corpus-patterns 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for corpus-patterns 0.1.2
File Size Uploaded
corpus_patterns-0.1.2.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for corpus-patterns 0.1.2
File Interpreter ABI Platform
corpus_patterns-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 41.6 kB

Release files / corpus_patterns-0.1.2.tar.gz

Download URL corpus_patterns-0.1.2.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dacdacaee24d28d3fd674839d3385aaf0cc562de0f1f358664ceb68cd28c5143
BLAKE2b-256 checksum
How to use checksums
47dbfe0d9a2c8a2acf831713e9482e355a88f5521dffd93a2369c0381a1ec50e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/23.2.0

Release files / corpus_patterns-0.1.2-py3-none-any.whl

Download URL corpus_patterns-0.1.2-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5544f0bebc839864c400edcc8d4a90524aaeec6de4816a5e57606bee6bf1336d
BLAKE2b-256 checksum
How to use checksums
5c70f24432a621cc1cddda79b8b1b95d411953dd49adbf339607890437e5af11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.6 Darwin/23.2.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page