Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pairwise not working with StringDistances #45

Closed
simonschoelly opened this issue Dec 27, 2020 · 3 comments
Closed

pairwise not working with StringDistances #45

simonschoelly opened this issue Dec 27, 2020 · 3 comments

Comments

@simonschoelly
Copy link

In the following example, the pairwise function from Distances.jl does not work.

Versions:
* Julia: 1.5.1
* Distances: 0.9.2
* StringDistances: 0.8.0

julia> using Distances, StringDistances

julia> pairwise(Jaro(), ["hello" "world"])
ERROR: MethodError: result_type(::Jaro, ::Array{String,2}, ::Array{String,2}) is ambiguous. Candidates:
  result_type(dist::PreMetric, a::AbstractArray, b::AbstractArray) in Distances at /home/simon/.julia/packages/Distances/1CdE2/src/generic.jl:36
  result_type(dist::Union{DamerauLevenshtein, Jaro, Levenshtein, RatcliffObershelp, StringDistances.QGramDistance, StringDistances.Normalize, Partial, TokenMax, TokenSet, TokenSort, Winkler}, s1, s2) in StringDistances at /home/simon/.julia/packages/StringDistances/67cTd/src/StringDistances.jl:12
Possible fix, define
  result_type(::Union{DamerauLevenshtein, Jaro, Levenshtein, RatcliffObershelp, StringDistances.QGramDistance, StringDistances.Normalize, Partial, TokenMax, TokenSet, TokenSort, Winkler}, ::AbstractArray, ::AbstractArray)
Stacktrace:
 [1] pairwise(::Jaro, ::Array{String,2}; dims::Nothing) at /home/simon/.julia/packages/Distances/1CdE2/src/generic.jl:212
 [2] pairwise(::Jaro, ::Array{String,2}) at /home/simon/.julia/packages/Distances/1CdE2/src/generic.jl:209
 [3] top-level scope at REPL[7]:1

I suspect that the reason for this ambiguity is making StringDistance a union, see #19

@matthieugomez
Copy link
Owner

The latest version of StringDistances is 0.10, and the problem does not appear with this version (reopen if not).

@simonschoelly
Copy link
Author

Something weird going on here, I can manually add Version v0.10.0, but as soon as I do ]Pkg up, Julia downgrades this package to v0.8.0 again.

Anyway, I created a new Project to check this out and I can still reproduce the problem with versions v0.10.0 of StringDistances:

(Test) pkg> add Distances, StringDistances
   Updating registry at `~/.julia/registries/General`
   Updating git-repo `git://github.com/JuliaRegistries/General.git`
  Resolving package versions...
Updating `~/Desktop/Test/Project.toml`
  [b4f34e82] + Distances v0.10.0
  [88034a9c] + StringDistances v0.10.0
Updating `~/Desktop/Test/Manifest.toml`
  [b4f34e82] + Distances v0.10.0
  [88034a9c] + StringDistances v0.10.0
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [9a3f8284] + Random
  [9e88b42a] + Serialization
  [2f01184e] + SparseArrays
  [10745b16] + Statistics

julia> using Distances, StringDistances

julia> pairwise(Jaro(), ["hello" "world"])
ERROR: MethodError: result_type(::Jaro, ::Array{String,2}, ::Array{String,2}) is ambiguous. Candidates:
  result_type(dist::PreMetric, a::AbstractArray, b::AbstractArray) in Distances at /home/simon/.julia/packages/Distances/d9gO5/src/generic.jl:36
  result_type(dist::Union{Jaro, RatcliffObershelp, JaroWinkler, QGramDistance, DamerauLevenshtein, StringDistances.Hamming, Levenshtein, StringDistances.Normalized, Partial, TokenMax, TokenSet, TokenSort}, s1, s2) in StringDistances at /home/simon/.julia/packages/StringDistances/LqX4j/src/StringDistances.jl:14
Possible fix, define
  result_type(::Union{Jaro, RatcliffObershelp, JaroWinkler, QGramDistance, DamerauLevenshtein, StringDistances.Hamming, Levenshtein, StringDistances.Normalized, Partial, TokenMax, TokenSet, TokenSort}, ::AbstractArray, ::AbstractArray)
Stacktrace:
 [1] pairwise(::Jaro, ::Array{String,2}; dims::Nothing) at /home/simon/.julia/packages/Distances/d9gO5/src/generic.jl:212
 [2] pairwise(::Jaro, ::Array{String,2}) at /home/simon/.julia/packages/Distances/d9gO5/src/generic.jl:209
 [3] top-level scope at REPL[4]:1

@matthieugomez
Copy link
Owner

Ok, it does not happen with the dev version of Distances. In any case, I think what you want to do is pairwise(Jaro(), ["hello", "world"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants