vickumar1981 / stringdistance

A fuzzy matching string distance library for Scala and Java that includes Levenshtein distance, Jaro distance, Jaro-Winkler distance, Dice coefficient, N-Gram similarity, Cosine similarity, Jaccard similarity, Longest common subsequence, Hamming distance, and more..

Home Page:https://vickumar1981.github.io/stringdistance/api/com/github/vickumar1981/stringdistance/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implicits not found while calling StringDistance

batakpout opened this issue · comments

commented

I'm creating a simple Test program to test ur Scala code, I am facing implicit issues, I tried various thing but is working, here is my sample code

import com.github.vickumar1981.stringdistance.StringDistance._

object test extends App {

val res = Cosine.score("aamir", "rimaa")
}
Its expecting implicit in scope, I simply copied from example from https://github.com/vickumar1981/stringdistance

this is the error message its giving:
Error:(8, 38) ambiguous reference to overloaded definition,
both method score in trait StringMetric of type (s1: String, s2: String)(implicit algo: com.github.vickumar1981.stringdistance.SoundScoringAlgorithm[com.github.vickumar1981.stringdistance.CosineAlgorithm])Boolean
and method score in trait StringMetric of type (s1: String, s2: String)(implicit algo: com.github.vickumar1981.stringdistance.ScoringAlgorithm[com.github.vickumar1981.stringdistance.CosineAlgorithm])Double
match argument types (String,String)
val cosSimilarity: Double = Cosine.score("hello", "chello")() // 0.935

there you haven't mentioned any implicit usage or importing any implicit.
Please look into this.

commented

I just found the fix, your imports are wrong, in ur scala example its mentioned as

import com.github.vickumar1981.stringdistance.StringDistance._
import com.github.vickumar1981.stringdistance.StringSound._

It should be

import com.github.vickumar1981.stringdistance.util.StringDistance._
import com.github.vickumar1981.stringdistance.util.StringSound._

👍 thanks for bringing this to my attention. I'll take a look at the scala examples later tonight.

The util package is specifically for Java, so if you have a java project, you should use that. If you are using scala, however, the other packages should work (I could have missed an import somewhere though).

For the 1st scala example, can you try importing:

import com.github.vickumar1981.stringdistance.implicits._

that's the package where all the implicit definitions live:

https://github.com/vickumar1981/stringdistance/blob/master/src/main/scala/com/github/vickumar1981/stringdistance/implicits/package.scala

Thanks again for bringing this up. I'm on EST, so around 6-7 tonight, I'll be looking at it if it's not resolved.

commented

Thanks for the quick response, I have tried all the options even
import com.github.vickumar1981.stringdistance.implicits._
is also not working, finally I settled with
import com.github.vickumar1981.stringdistance.StringDistance._
looks like you have missed something, please look into this.

Thanks

@aamir-f I pushed up a 1.1.0 build (and a 1.1.0-SNAPSHOT if you don't want to wait) which should be up on maven shortly that updates/fixes the bugs. Also, updated the README.md with working instructions.

Specifically, I found out what wasn't working were the scoring algorithms that required an extra parameter to them. Cosine.score(s1, s2, regEx) is the signature of the function, where regex is how you want to split up the strings - either treating them as a word, or as a sentence. These parameters are now required for the implementations that need them. (With 1.1.1 you can go back to treating them optionally, the examples in the README are only for pointing out explicitly that these parameters exist)

Other examples are Jaccard.score(s1, s2, nGrams) where nGrams is how you want to tokenize strings s1 and s2 for comparison.

If you want to bypass setting up some of the extra parameters, you can also use the 2nd usage:

import com.github.vickumar1981.stringdistance.StringConverter._
val cosSimilarity: Double = "hello" cosine "chello"

I tried to update the docs to reflect this, but I'm sure they still need work. Let me know if you're still having issues, and thank you again for opening the issue.

@aamir-f is it okay to close this issue?