Skip to main content

Static Hash-Based Lookup for BNC Terms

Project description

BNC Lookup

PyPI version PyPI downloads Python versions License Code style: ruff Pre-commit Tests

Is this token a word? O(1) answer. No setup. No dependencies.

A simple question deserves a simple answer. This library gives you instant yes/no validation against 669,000 word forms from the British National Corpus, plus frequency ranking.

Quick Start

pip install bnc-lookup
import bnc_lookup as bnc

# Check if a word exists
bnc.exists('the')          # True
bnc.exists('however')      # True
bnc.exists('xyzabc123')    # False

# Get frequency bucket (1=most common, 100=least common)
bnc.bucket('the')          # 1
bnc.bucket('python')       # 4
bnc.bucket('qwerty')       # 12
bnc.bucket('xyzabc123')    # None (not found)

# Handles plurals automatically
bnc.exists('computers')    # True
bnc.bucket('computers')    # 1

# Case insensitive
bnc.exists('THE')          # True

Features

  • Zero Dependencies - Pure Python, no external packages
  • Zero I/O - No filesystem access, no database queries
  • Zero Setup - No corpus downloads or configuration
  • Microsecond Lookups - O(1) dictionary access
  • Smart Plurals - Automatically checks singular forms
  • Frequency Ranking - 100 buckets from most to least common
  • Simple API - Two functions: exists() and bucket()

The Problem This Solves

In NLP, you frequently need to answer the question: "Is this token a real word?"

Not "what does it mean?" Not "give me synonyms." Just: is this a word?

bnc.exists('computer') bnc.exists('asdfgh')
True False

That's it. O(1) response. No ambiguity.

Frequency Buckets

Words are ranked into 100 buckets based on their frequency in the BNC corpus:

Bucket Description Examples
1 Most frequent (~6,700 words) the, of, and, is, computer
2-10 Very common algorithm, python, beautiful
11-50 Common qwerty, specialized terms
51-99 Less common Rare but valid words
100 Least frequent Obscure terms
import bnc_lookup as bnc

# Filter by frequency
def is_common_word(word):
    bucket = bnc.bucket(word)
    return bucket is not None and bucket <= 10

Why BNC?

The British National Corpus isn't an academic wordlist (too narrow). It's not a web scrape (too noisy). It's not slang (too ephemeral).

It's a 100-million-word corpus of real British English collected from written and spoken sources between 1991-1994. Books, newspapers, academic papers, conversations. The BNC frequency list captures ~669,000 unique word forms actually used by native speakers.

If a token passes the BNC test, you can be confident it's a word that real people actually use.

When to Use This

  • Tokenization filtering: Keep real words, discard garbage
  • Input validation: Reject nonsense in user input
  • NLP preprocessing: Filter candidates before expensive operations
  • Spell-check pre-filtering: Quick reject obvious non-words before fuzzy matching
  • Data cleaning: Identify malformed or corrupted text
  • Frequency-based filtering: Prefer common words over obscure ones

What This Doesn't Do

  • No definitions, synonyms, or semantic relationships (use spaCy for that)
  • No spell-checking or suggestions (just existence check)
  • No irregular plural handling ("mice" → "mouse")

Documentation

For detailed usage, performance benchmarks, and advanced features, see the API Documentation.

Development

git clone https://github.com/craigtrim/bnc-lookup.git
cd bnc-lookup
make install  # Install dependencies
make test     # Run tests
make all      # Full build pipeline

See API Documentation for detailed development information.

License

This package is dual-licensed:

  • Software: MIT License
  • BNC Data: BNC User Licence

See LICENSE for complete terms.

Attribution

This package contains data derived from the British National Corpus frequency lists:

BNC frequency lists compiled by Adam Kilgarriff. Source: https://www.kilgarriff.co.uk/BNClists/all.num.gz

The British National Corpus, version 3 (BNC XML Edition). 2007. Distributed by Bodleian Libraries, University of Oxford, on behalf of the BNC Consortium.

Note: This is a static snapshot of BNC frequency data. The data is not automatically updated.

See Also

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bnc_lookup-1.1.0.tar.gz (26.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bnc_lookup-1.1.0-py3-none-any.whl (26.3 MB view details)

Uploaded Python 3

File details

Details for the file bnc_lookup-1.1.0.tar.gz.

File metadata

  • Download URL: bnc_lookup-1.1.0.tar.gz
  • Upload date:
  • Size: 26.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for bnc_lookup-1.1.0.tar.gz
Algorithm Hash digest
SHA256 320eb59d1e35bb96f82b6093aa85dd961ca9c3ec708faa680c340ebf46a0d8b4
MD5 2760be4975f90211a111f17feb6d7cd0
BLAKE2b-256 cf6d32f6806591f16b6c4e68d419e72bfb7e289bd265a789435d6ee43203afb1

See more details on using hashes here.

File details

Details for the file bnc_lookup-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: bnc_lookup-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Darwin/24.6.0

File hashes

Hashes for bnc_lookup-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fee34a3a0b35b682f1aa2c1b05cfb2518a997a61317c5ed969b7ced0a83d17a9
MD5 8d3e38165c98aa69e62add1a03c766b2
BLAKE2b-256 7a77fe9511de1d4941e5c013945e30a887c26043e793f839c0671983fa65d20a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page