Typo detector library in Scala.
Typical use case: certain words need to be found in a text, however they might be misspelled in
a variety of ways. Instead of trying to hardcode the possible misspellings of
such an input typo-detector
might be used instead.
<dependency>
<groupId>io.github.antivanov</groupId>
<artifactId>typo-detector_3</artifactId>
<version>0.4.0</version>
</dependency>
For Scala 3:
libraryDependencies += "io.github.antivanov" %% "typo-detector" % "0.4.0"
For Scala 2:
libraryDependencies += ("io.github.antivanov" %% "typo-detector" % "0.4.0")
.cross(CrossVersion.for2_13Use3)
Make sure you have -Ytasty-reader
compiler flag set:
ThisBuild / scalacOptions := Seq(
"-Ytasty-reader",
)
Enhancing the String
class with containsExactOrTypoOf
method
import io.github.antivanov.typo.detector.syntax._
"Quick bron fox jumps over the lazy dog".containsExactOrTypoOf("brown fox")
Using API object TypoDetector
if using implicits is not desirable
import io.github.antivanov.typo.detector.TypoDetector
TypoDetector.containsExactOrTypoOf("Quick bron fox jumps over the lazy dog", "brown fox")
Enhancing the String
class with isTypoOf
method
import io.github.antivanov.typo.detector.syntax._
val acknowlegmentText = "acknowlege"
val isAcknowledged = acknowlegmentText.isTypoOf("acknowledge")
Using API object TypoDetector
if using implicits is not desirable
import io.github.antivanov.typo.detector.TypoDetector
val acknowlegmentText = "acknowlege"
val isAcknowledged = TypoDetector.isTypoOf(acknowlegmentText, "acknowledge")
equalsOrTypoOf
is very similar in usage to isTypoOf
, but returns true if another
string is either a typo or is equal to the current string
By default the number of wrongly typed symbols for a string to be considered a typo
is 2
, in the case of longer strings it might make sense to allow for more mistyped symbols
to detect typos, for example:
Enhancing the String
class with isTypoOf
method
import io.github.antivanov.typo.detector.syntax._
val misspelledWord = "gementeradverkiezingen"
val isMisspelled = misspelledWord.isTypoOf("gemeenteraadsverkiezingen", maxMistypedSymbols = 5)
Using API object TypoDetector
if using implicits is not desirable
import io.github.antivanov.typo.detector.TypoDetector
val misspelledWord = "gementeradverkiezingen"
val isMisspelled = TypoDetector.isTypoOf(misspelledWord, "gemeenteraadsverkiezingen", maxMistypedSymbols = 5)
editDistanceFrom
computes the Levenshtein distance between the strings
Enhancing the String
class with editDistanceFrom
method
import io.github.antivanov.typo.detector.syntax._
val acknowlegmentText = "acknowlege"
val distance = acknowlegmentText.editDistanceFrom("acknowledge")
Using API object TypoDetector
if using implicits is not desirable
import io.github.antivanov.typo.detector.TypoDetector
val acknowlegmentText = "acknowlege"
val distance = TypoDetector.editDistanceFrom(acknowlegmentText, "acknowledge")
Under the hood the library computes the Levenshtein distance between strings using the Wagner-Fischer algorithm. If the distance is lower than a certain number, the two strings are considered to be a typo.