Files
tai/research/fuzzy-matching-selectors/github-rapidfuzz-fuzz-py.md
T

51 lines
2.1 KiB
Markdown

# RapidFuzz fuzz_py.py (WRatio, partial_ratio)
## Metadata
| Field | Value |
|---|---|
| Institute | Molodetz Institute — Research & Retrieval Division |
| Subject | fuzzy-matching-selectors |
| Document type | Source Dossier |
| Tier | 1 |
| Source title | RapidFuzz fuzz_py.py (WRatio, partial_ratio) |
| Source URL | https://raw.githubusercontent.com/rapidfuzz/RapidFuzz/main/src/rapidfuzz/fuzz_py.py |
| Source publisher / author | maxbachmann and RapidFuzz contributors |
| Source type | repository |
| Source date (published) | Unknown — not stated |
| Date researched | 2026-10-25 |
| Researched by | tai (agent), model: Claude Sonnet 5, on behalf of retoor |
| Research method | direct page fetch |
| Confidence | High |
| Status | Active |
## Summary
The pure-Python reference implementation of RapidFuzz scorers, read for how the weighted WRatio combines ratio, token and partial scorers.
## Key findings
- WRatio constants: UNBASE_SCALE 0.95; PARTIAL_SCALE 0.9 when the length ratio is <= 8.0, else 0.6.
- Length ratio < 1.5: max(ratio, token_ratio * 0.95) where token_ratio is the max of token_set_ratio and token_sort_ratio.
- Length ratio >= 1.5: ratio, then partial_ratio * PARTIAL_SCALE, then partial_token_ratio * 0.95 * PARTIAL_SCALE; score_cutoff is raised after each step so later scorers can prune.
- partial_ratio slides the shorter string over the longer string (prefix windows, full-length windows, suffix windows), scoring each with normalized Indel similarity and keeping the best.
- Empty input or a None input returns 0.
## Pros / strengths
Precise, small and readable; shows the max-of-scaled-scorers pattern tai also uses.
## Cons / limitations / caveats
Designed for sentences and records, not identifiers. The docstring and code disagree for needles longer than 64 characters (noted by the fetch).
## Relevance to tai
Validated the 'max of several scaled signals' structure. Not ported: token_set semantics (a subset scores 100) would make `claude` tie with every `claude-*` id and hide real differences.
## Changelog
| Date | Change |
|---|---|
| 2026-10-25 | Initial dossier created. |