diff --git a/Project.toml b/Project.toml index a63569f..af73dbf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StringDistances" uuid = "88034a9c-02f8-509d-84a9-84ec65e18404" -version = "0.8" +version = "0.9.0" [deps] Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" diff --git a/src/StringDistances.jl b/src/StringDistances.jl index 3a23044..f135480 100755 --- a/src/StringDistances.jl +++ b/src/StringDistances.jl @@ -2,31 +2,17 @@ module StringDistances using Distances -include("utils.jl") -include("edit.jl") -include("qgram.jl") +include("distances/utils.jl") +include("distances/edit.jl") +include("distances/qgram.jl") include("normalize.jl") const StringDistance = Union{Jaro, Levenshtein, DamerauLevenshtein, RatcliffObershelp, QGramDistance, Winkler, Partial, TokenSort, TokenSet, TokenMax, Normalize} # Distances API Distances.result_type(dist::StringDistance, s1, s2) = typeof(dist("", "")) - -""" - compare(s1, s2, dist) - -return a similarity score between 0 and 1 for the strings `s1` and -`s2` based on the distance `dist`. - -### Examples -```julia-repl -julia> compare("martha", "marhta", Levenshtein()) -0.6666666666666667 -``` -""" -compare(s1, s2, dist::StringDistance; min_score = 0.0) = 1 - normalize(dist)(s1, s2, 1 - min_score) - include("find.jl") + ############################################################################## ## ## Export diff --git a/src/edit.jl b/src/distances/edit.jl similarity index 100% rename from src/edit.jl rename to src/distances/edit.jl diff --git a/src/qgram.jl b/src/distances/qgram.jl similarity index 100% rename from src/qgram.jl rename to src/distances/qgram.jl diff --git a/src/utils.jl b/src/distances/utils.jl similarity index 100% rename from src/utils.jl rename to src/distances/utils.jl diff --git a/src/find.jl b/src/find.jl index 84f1cf2..0ab7d26 100755 --- a/src/find.jl +++ b/src/find.jl @@ -1,3 +1,18 @@ +""" + compare(s1, s2, dist) + +return a similarity score between 0 and 1 for the strings `s1` and +`s2` based on the distance `dist`. + +### Examples +```julia-repl +julia> compare("martha", "marhta", Levenshtein()) +0.6666666666666667 +``` +""" +compare(s1, s2, dist::StringDistance; min_score = 0.0) = 1 - normalize(dist)(s1, s2, 1 - min_score) + + """ findnearest(s, itr, dist::StringDistance; min_score = 0.0) -> (x, index) diff --git a/src/normalize.jl b/src/normalize.jl index 3789f1a..a2baade 100755 --- a/src/normalize.jl +++ b/src/normalize.jl @@ -259,4 +259,6 @@ function (dist::Winkler)(s1, s2, max_dist = 1.0) out -= min(l, dist.maxlength) * dist.p * out end out > max_dist ? 1.0 : out -end \ No newline at end of file +end + +