Skip to main content

Stringalign

Two cute caterpillars dancing under bunting with the letters 'STRING ALIGN'

A string comparison library that adhers to the quirks of Unicode.

What is this?

Stringalign is a library for comparing strings. At its base, Stringalign takes two strings, a reference string and a predicted string, and aligns them. Based on this alignment, we can then compute many interesting performance metrics, such as the edit distance (Levenshtein), error rates and much more.

For more information, see Stringalign's extensive documentation on http://stringalign.com/.

A little example

For example, if the reference string is Banana pancakes and the predicted string is bananana pancake, then string align will align it

 Reference: B--anana pancakes
Prediction: bananana pancake-

This alignment is stored as a collection of replacements, insertions, deletions and keeps, that describe what we need to do with the predicted string to make it equal to the reference string. For the string above, we get

[Replaced('B', 'b'), Inserted('a'), Inserted('n'), Kept('a'), Kept('n'), Kept('a'), Kept('n'), Kept('a'), Kept(' '), Kept('p'), Kept('a'), Kept('n'), Kept('c'), Kept('a'), Kept('k'), Kept('e'), Deleted('s')]

or, if we join consequtive the Deleted, Inserted and Replaced:

[Replaced('B', 'ban'), Kept('anana pancake'), Deleted('s')]

Based on these alignments, we can compute standard string comparison metrics such as the Levenshtein distance and character error rate. However, Stringalign also contains functions to do more in-depth analysis of the types of errors that occur when you have a whole collection of reference and predicted strings. Examples of this is: the most common character confusions, the letters most often omitted in the prediction, the letters most often incorrectly included in the prediction, etc. See our gallery of examples for more information.

What's the point?

Stringalign might sound similar to other Python libraries, like Jiwer and Levenshtein (which both use Rapidfuzz behind-the-scenes). However, what puts Stringalign apart is that it handles Unicode "correctly" and provides easy-to-use tools for going in-depth in the analysis.

Take this example:

import Levenshtein

print(Levenshtein.distance('ñ', 'ñ'))
2

What happened here? The first 'ñ' consists of two code points: an n and a "put a tilde on the previous character" code point, while the second 'ñ' only consists of the single code point 'ñ'. Let's try it with Stringalign instead:

from stringalign.align import levenshtein_distance

print(levenshtein_distance('ñ', 'ñ'))
0

We see the expected behaviour. By default, Stringalign will normalize your text and segment it into Unicode extended grapheme clusters before aligning. An extended grapheme cluster is essentially just what a computer should display as one letter, and while a grapheme cluster usually is just one code-point, it's not always that. Since tools like Jiwer and Levenshtein work directly on the code-points, they will miss these edge cases.

Emojis

Often, we don't need to worry about separating between code-points and grapheme clusters. However, the moment emojis come into the picture, this changes. Many emojis are just the single code point. However, some are created by combining two or more other emojis --- like '🏳️‍🌈', which is created by combining the white-flag emoji, '🏳', a variant selector '\uFE0F', a zero width joiner '\u200D' and the rainbow emoji, '🌈'. Because Stringalign takes care of aligning normalized grapheme clusters automatically, it will also work correctly with emoiis

import Levenshtein
from stringalign.align import levenshtein_distance

print("Levenshtein", Levenshtein.distance('🏳️‍🌈', '🌈'))
print("Stringalign", levenshtein_distance('🏳️‍🌈', '🌈'))
Levenshtein 3
stringalign 1

How does it work?

Stringalign works in a two-step process: first, the input strings are tokenized into normalised extended grapheme clusters, before they are aligned using the Needleman-Wunsch algorithm. You can customise this if you want, e.g. switching out the tokenizer with one that casefolds all extended grapheme clusters, to get a case-insensitive alignment, or words to e.g. compute the word-error rate.

We use an extension module written in Rust for two important parts of Stringalign: grouping unicode code-points into extended grapheme clusters (with the unicode_segmentation crate) and assembling the Needleman-Wunsch cost-matrix (which has O(n²) time- and memory-complexity).

Citing Stringalign

If you use Stringalign for your research, then please cite this repo. For example:

Moe, Y. M., & Roald, M. (2024). Stringalign [Computer software]. https://github.com/yngvem/stringalign

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

stringalign-0.1.5-cp311-abi3-win_amd64.whl (384.8 kB view details)

Uploaded CPython 3.11+Windows x86-64

stringalign-0.1.5-cp311-abi3-win32.whl (378.8 kB view details)

Uploaded CPython 3.11+Windows x86

stringalign-0.1.5-cp311-abi3-musllinux_1_2_x86_64.whl (731.6 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

stringalign-0.1.5-cp311-abi3-musllinux_1_2_i686.whl (766.6 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ i686

stringalign-0.1.5-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (532.0 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

stringalign-0.1.5-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (542.0 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ s390x

stringalign-0.1.5-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (646.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ppc64le

stringalign-0.1.5-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (530.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARMv7l

stringalign-0.1.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (522.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

stringalign-0.1.5-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl (548.2 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.5+ i686

stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl (494.0 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (770.5 kB view details)

Uploaded CPython 3.11+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file stringalign-0.1.5-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: stringalign-0.1.5-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 384.8 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dd4633d5c075a81148b85a76eb0be594a8d35aebcab2952ad254d4fa795f4ff6
MD5 f7d1e2daa9990992bd3167c1b2ee008b
BLAKE2b-256 7a891a60fad86f664268d8b5fa0fad782d1858fea841e7c377e9d1ac34824ec7

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-win_amd64.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-win32.whl.

File metadata

  • Download URL: stringalign-0.1.5-cp311-abi3-win32.whl
  • Upload date:
  • Size: 378.8 kB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 2a5f6f83d31240d41d22ebfadb77403b9809a84fa46bfd2bc46fa311a4e054f7
MD5 894e2e6f24e38d240a060945c4e935ca
BLAKE2b-256 74b4cc45f98f597a0a393ef628a96d469415638017feed4d42c0c37387babb7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-win32.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7c22c4343f88672e3b6c5adff35f6aa988a868058a49b230075b82c0121dd67
MD5 5a4e1434536ba9ce9e6c2ba02420e473
BLAKE2b-256 9b0a7fbc11103301443497d5421265e67ef34ffc1ff60c90e0a9cfa5094579c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 77fd60c0c17684b523e6f44341222feb6f6054f00307ec3a4d00d216aa296981
MD5 933cbe29512d93135379302d69aff13b
BLAKE2b-256 fdbcd5302102517d154361ecc02b9d264b593cc240a118dde8f4cfde592753ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-musllinux_1_2_i686.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d779b36dcfa87bee508a00f2bdc8f82a6b1e2584922676460c4df44e32f0010
MD5 fe1286ffaddd79407b182aaeb9c7e9b6
BLAKE2b-256 346cc25a87f7b6d8aa4f55faaac137ce1e1fa067ace530d8ba88a11c293405e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d23d09db4cf9f839e1bdec2a433866411f0c4fe5ab6e43a17ef446a3bde09e59
MD5 08244d90d9ed86454bab9ef169171626
BLAKE2b-256 147bedfa124ae485d487f587be8e9af9da99e175dc9578c347bcb919d922561e

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 a8d40fe41473102e9cb6e9fae2c854314bd511634ef0aa5ee0a02fa2cd36bfa1
MD5 0157666ba98154ed3fc8ddb0dedcf968
BLAKE2b-256 2075bb429931852ccf9d72a789326ea97baab3dce450918f0bb36b07ba839706

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 33082795941f1337931ccdb602f139d17fbc1e8986d5c794da30686098ac16f4
MD5 c918ac9d91d35397d354b16a9ee11c59
BLAKE2b-256 f99c139082e3d0e2b19a52a07ad1758c924b2aaf0f5118c06caec7bf1725cee2

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0122e7b05e7e1777a6bb69c566845359cdbe993baf645a746b799be95b3e79cd
MD5 cf291626b42be336c69e1ab8c75497da
BLAKE2b-256 7670a593faa7a4c3dd0be556723aa8fb700f596053ae6465f885c23a52d7eaa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 c0395402cd51521eea8130dd0c3c6fa07f03a4ebd582cdee8e0660fce6037e6e
MD5 01af91de246faa0ae2e1597a5b94ff3e
BLAKE2b-256 35f7d2778bce05175f4bf98c9829b5648ddc32e82c7d2b781c0c2a9c14baa73d

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 015440642a8422e5de2d0f23de4df2f91fc26bdb4971a8e0eb78724178f7571c
MD5 3f3ce82dafb9e7301f67be2bf9876664
BLAKE2b-256 54d336df44b1c3e572d816c1a87f93e3407d4b556b7f984dc988099cb46e21cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 eaaa18243bc872502fc26f525f59d2f320692525af16b8f1d2b8b627108e3590
MD5 476d57a0c4565f97bd1fac1cef066031
BLAKE2b-256 bbfc0190b6c6a799f534757d381f2c5ae0d4a31611b31b7db1a6b7b220524edb

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringalign-0.1.5-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: publish.yml on yngvem/stringalign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.5 This release

12 files

0.1.4

12 files

0.1.3

12 files

0.1.2

12 files

0.0.3

13 files

0.0.2

13 files

0.0.1

13 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