5
$\begingroup$

I'm trying to program Jaro distance as requested by this page I've done the following code that works well for the next two pairs ("MARTHA", "MARHTA") and ("DIXON", "DICKSONX") but when I try with ("JELLYFISH", "SMELLYFISH") I get an error because the code counts the double S of "SMELLYFISH", due to this error I have not been able to finish successfully, here is what I have programmed up to this moment

uno = "DIXON"; dos ="DICKSONX" ;
rep = Characters[uno] \[Intersection] Characters[dos]
scope = Max[StringLength[uno], StringLength[dos]]/2 - 1
inter = Transpose[{Flatten[Position[Characters[uno], #] & /@ rep], 
   Flatten[Position[Characters[dos], #] & /@ rep]}]

m = Select[inter, Abs[#[[1]] - #[[2]]] < scope &]

prb = Select[m, #[[1]] != #[[2]] &]

trans = Length[DeleteCases[Position[prb, Reverse[#]] & /@ prb, {}]]/2

1/3 (Length[m]/StringLength[uno] + Length[m]/StringLength[dos] + (
   Length[m] - trans)/Length[m])

% // N

Someone who can help me solve this problem? Maybe the approach I'm using is wrong, I hope someone is interested in this problem too. Thanks in advance

$\endgroup$
1
  • $\begingroup$ JaroSimilarity is available at the WFR. $\endgroup$
    – Syed
    Commented Nov 28 at 3:52

1 Answer 1

6
$\begingroup$

As an alternative you can use Experimental`JaroDistance:

jD = Experimental`JaroDistance;
jD[uno, dos]

0.766667

jD["JELLYFISH", "SMELLYFISH"]

0.896296

$\endgroup$
2
  • $\begingroup$ thank you very much for the information has been very useful, since actually get the expected results, I did not know about that package, but I would like to performance my own version of that function, and check it with the option you proposed, I hope please You can help improve my programming attempt since you have more experience than me. Hoping to have your help, I say goodbye, wishing you an excellent day $\endgroup$ Commented Aug 20, 2018 at 5:22
  • $\begingroup$ Please, take a look at the solution proposed in the wolfram community, here is the link community.wolfram.com/groups/-/m/t/1416937 , I think it is very accurate, but I do not understand what the author of the answer is asking for, since he has already tried his function and fails, now I am trying to find the solution to the problem with the code he shared. Thanks for your help here on stack exchange, and vote for your answer $\endgroup$ Commented Aug 21, 2018 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.