https://github.com/philippus/osita
🧸 Tiny optimal string alignment distance library
https://github.com/philippus/osita
azerty damerau-levenshtein-distance optimal-string-alignment-distance qwerty qwerty-based-char-distance spelling
Last synced: 3 months ago
JSON representation
🧸 Tiny optimal string alignment distance library
- Host: GitHub
- URL: https://github.com/philippus/osita
- Owner: Philippus
- License: mpl-2.0
- Created: 2022-01-19T20:41:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-25T10:26:11.000Z (9 months ago)
- Last Synced: 2025-02-01T22:23:02.259Z (9 months ago)
- Topics: azerty, damerau-levenshtein-distance, optimal-string-alignment-distance, qwerty, qwerty-based-char-distance, spelling
- Language: Scala
- Homepage:
- Size: 189 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# osita
[](https://github.com/Philippus/osita/actions/workflows/build.yml?query=workflow%3Abuild+branch%3Amain)
[](https://codecov.io/gh/Philippus/osita)

[](https://scala-steward.org)
[](LICENSE)Osita is an implementation of the [Optimal String Alignment distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance)
algorithm. It implements the standard version of the algorithm and an extension of it where the substitution cost has
been replaced by a function which calculates the keyboard distance between characters using the Euclidean distance
between keys on a QWERTY or AZERTY-keyboard.
You can also supply your own substitution cost function.## Installation
Osita is published for Scala 2.12, 2.13 and 3. To start using it add the following to your `build.sbt`:```
libraryDependencies += "nl.gn0s1s" %% "osita" % "0.1.0"
```## Example usage
```scala
import nl.gn0s1s.osita.Osita._osa("abcde", "abcde") // val res0: Double = 0.0
osa("abcde", "abcd") // val res1: Double = 1.0
osaWithSubstitutionCost("abc", "agc")(qwertySubstitutionCost) // val res2: Double = 1.118033988749895```
## Resources
- [Optimal String Alignment distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance)
- [Euclidean Distance](https://en.wikipedia.org/wiki/Euclidean_distance)
- Distances between keys on a QWERTY keyboard on Code Golf - https://codegolf.stackexchange.com/questions/233618/distances-between-keys-on-a-qwerty-keyboard
- Keyboard distance in Perl - https://metacpan.org/release/KRBURTON/String-KeyboardDistance-1.01/source/README## License
The code is available under the [Mozilla Public License, version 2.0](LICENSE).