ocr-stringdist 0.2.0__cp311-cp311-musllinux_1_1_i686.whl → 0.2.2__cp311-cp311-musllinux_1_1_i686.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: ocr-stringdist
3
+ Version: 0.2.2
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python
6
+ Classifier: Operating System :: OS Independent
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
10
+ Project-URL: repository, https://github.com/NiklasvonM/ocr-stringdist
11
+ Project-URL: documentation, https://niklasvonm.github.io/ocr-stringdist/
12
+
13
+ # OCR-StringDist
14
+
15
+ A Python library for fast string distance calculations that account for common OCR (optical character recognition) errors.
16
+
17
+ Documentation: https://niklasvonm.github.io/ocr-stringdist/
18
+
19
+ [![PyPI](https://img.shields.io/badge/PyPI-Package-blue)](https://pypi.org/project/ocr-stringdist/)
20
+ [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
21
+
22
+ ## Overview
23
+
24
+ Standard string distances (like Levenshtein) treat all character substitutions equally. This is suboptimal for text read from images via OCR, where errors like `O` vs `0` are far more common than, say, `O` vs `X`.
25
+
26
+ OCR-StringDist uses a **weighted Levenshtein distance**, assigning lower costs to common OCR errors.
27
+
28
+ **Example:** Matching against the correct word `CODE`:
29
+
30
+ * **Standard Levenshtein:**
31
+ * $d(\text{"CODE"}, \text{"C0DE"}) = 1$ (O → 0)
32
+ * $d(\text{"CODE"}, \text{"CXDE"}) = 1$ (O → X)
33
+ * Result: Both appear equally likely/distant.
34
+
35
+ * **OCR-StringDist (Weighted):**
36
+ * $d(\text{"CODE"}, \text{"C0DE"}) \approx 0.1$ (common error, low cost)
37
+ * $d(\text{"CODE"}, \text{"CXDE"}) = 1.0$ (unlikely error, high cost)
38
+ * Result: Correctly identifies `C0DE` as a much closer match.
39
+
40
+ This makes it ideal for matching potentially incorrect OCR output against known values (e.g., product codes, database entries).
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install ocr-stringdist
46
+ ```
47
+
48
+ ## Features
49
+
50
+ - **High Performance**: The core logic is implemented in Rust with speed in mind.
51
+ - **Weighted Levenshtein Distance**: Calculates Levenshtein distance with customizable costs for substitutions, insertions, and deletions. Includes an efficient batch version (`batch_weighted_levenshtein_distance`) for comparing one string against many candidates.
52
+ - **Explainable Edit Path**: Returns the optimal sequence of edit operations (substitutions, insertions, and deletions) used to transform one string into another.
53
+ - **Substitution of Multiple Characters**: Not just character pairs, but string pairs may be substituted, for example the Korean syllable "이" for the two letters "OI".
54
+ - **Pre-defined OCR Distance Map**: A built-in distance map for common OCR confusions (e.g., "0" vs "O", "1" vs "l", "5" vs "S").
55
+ - **Unicode Support**: Works with arbitrary Unicode strings.
56
+ - **Best Match Finder**: Includes a utility function `find_best_candidate` to efficiently find the best match from a list based on _any_ distance function.
57
+
58
+ ## Usage
59
+
60
+ ### Basic usage
61
+
62
+ ```python
63
+ from ocr_stringdist import WeightedLevenshtein
64
+
65
+ # Default substitution costs are ocr_stringdist.ocr_distance_map.
66
+ wl = WeightedLevenshtein()
67
+
68
+ print(wl.distance("CXDE", "CODE")) # == 1
69
+ print(wl.distance("C0DE", "CODE")) # < 1
70
+ ```
71
+
72
+ ### Explain the Edit Path
73
+
74
+ ```python
75
+ edit_path = wl.explain("C0DE", "CODE")
76
+ print(edit_path)
77
+ # EditOperation(op_type='substitute', source_token='0', target_token='O', cost=0.1)]
78
+ ```
79
+
80
+ ### Fast Batch Calculations
81
+
82
+ Quickly compare a string to a list of candidates.
83
+
84
+ ```python
85
+ distances: list[float] = wl.batch_distance("CODE", ["CXDE", "C0DE"])
86
+ # [1.0, 0.1]
87
+ ```
88
+
89
+ ### Multi-character Substitutions
90
+
91
+ ```python
92
+ # Custom costs with multi-character substitution
93
+ wl = WeightedLevenshtein(substitution_costs={("In", "h"): 0.5})
94
+
95
+ print(wl.distance("hi", "Ini")) # 0.5
96
+ ```
97
+
98
+
99
+ ## Acknowledgements
100
+
101
+ This project is inspired by [jellyfish](https://github.com/jamesturk/jellyfish), providing the base implementations of the algorithms used here.
102
+
@@ -1,11 +1,11 @@
1
- ocr_stringdist-0.2.0.dist-info/METADATA,sha256=OVF3jUKVM038ogWfwZIHmpu3eUXdeuS1Cy-t96G8Tgo,304
2
- ocr_stringdist-0.2.0.dist-info/WHEEL,sha256=nTH9UaXhMe2Z7vYjzTFaj4VIXUvQaRiC6yVlzzX1nis,105
3
- ocr_stringdist-0.2.0.dist-info/licenses/LICENSE,sha256=5BPRcjlnbl2t4TidSgpfGrtC_birSf8JlZfA-qmVoQE,1072
4
- ocr_stringdist.libs/libgcc_s-b5472b99.so.1,sha256=wh8CpjXz9IccAyeERcB7YDEx7NH2jF-PykwOyYNeRRI,453841
1
+ ocr_stringdist-0.2.2.dist-info/METADATA,sha256=2KjG6DHqpsannN0lPK4EwkYBbY3adZrl1oTCq-elnL8,3868
2
+ ocr_stringdist-0.2.2.dist-info/WHEEL,sha256=nTH9UaXhMe2Z7vYjzTFaj4VIXUvQaRiC6yVlzzX1nis,105
3
+ ocr_stringdist-0.2.2.dist-info/licenses/LICENSE,sha256=5BPRcjlnbl2t4TidSgpfGrtC_birSf8JlZfA-qmVoQE,1072
4
+ ocr_stringdist.libs/libgcc_s-27e5a392.so.1,sha256=x5sO63liVwXxrjGGP371wB0RyQe1KEnIynYm82T0G0M,449745
5
5
  ocr_stringdist/__init__.py,sha256=ApxqraLRcWAkzXhGJXSf3EqGEVFbxghrYrfJ9dmQjQU,467
6
- ocr_stringdist/_rust_stringdist.cpython-311-i386-linux-musl.so,sha256=QS_4-aXp3qJeK28rq8dpoXh5K5um5w3MOGaI9hDwmVU,776585
6
+ ocr_stringdist/_rust_stringdist.cpython-311-i386-linux-musl.so,sha256=Upv_g-UfBmugHL7FC_rFjOsGjXJcF8wtHSE99Oi6Ctw,776585
7
7
  ocr_stringdist/default_ocr_distances.py,sha256=oSu-TpHjPA4jxKpLAfmap8z0ZsC99jsOjnRVHW7Hj_Y,1033
8
8
  ocr_stringdist/levenshtein.py,sha256=Jypg31BQyULipJ_Yh3dcBQDKNnbvEIlmf28tDr_gySw,11243
9
9
  ocr_stringdist/matching.py,sha256=rr8R63Ttu2hTf5Mni7_P8aGBbjWs6t2QPV3wxKXspAs,3293
10
10
  ocr_stringdist/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- ocr_stringdist-0.2.0.dist-info/RECORD,,
11
+ ocr_stringdist-0.2.2.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ocr_stringdist
3
- Version: 0.2.0
4
- Classifier: Programming Language :: Rust
5
- Classifier: Programming Language :: Python
6
- Classifier: Operating System :: OS Independent
7
- License-File: LICENSE
8
- Requires-Python: >=3.9
9
- Project-URL: repository, https://github.com/NiklasvonM/ocr-stringdist