6
$\begingroup$

I would like to know if it's possible to use/install this java library on Mathematica. This library, named SimMetrics, has a lot of string similarity functions that I would like to test.

Here is the list of functions:

Levenstein, NeedlemanWunch, SmithWaterman, SmithWatermanGotoh, SmithWatermanGotohWindowedAffine, Jaro, JaroWinkler, ChapmanLengthDeviation, ChapmanMeanLength, QGramsDistance, BlockDistance, CosineSimilarity, DiceSimilarity, EuclideanDistance, JaccardSimilarity, MatchingCoefficient, MongeElkan, OverlapCoefficient.

I have no knowledge on Java and use a MAC. A thought in Leonid Java Reloader, but it's a complete .jar file, not a small class.

Update

I download the simmetrics_jar_v1_6_2_d07_02_07.jar from the link above, saved it on notebook directory and tryed:

Needs["JLink`"]
ReinstallJava[ClassPath->"/System/Library/Java/JavaVirtualMachines/:"<>NotebookDirectory[]<>"simmetrics_jar_v1_6_2_d07_02_07.jar"]    

Now I have to use LoadJavaClass? How can a list the available classes?

If I unzip the .jar file, the classes are inside this folder: uk/ac/shef/wit/simmetrics/similaritymetrics/

for example: Levenshtein.class

$\endgroup$
3
  • 1
    $\begingroup$ Many of these distance functions are built in to Mathematica as well, mostly with the same names. $\endgroup$
    – bill s
    Commented Aug 12, 2013 at 2:25
  • 1
    $\begingroup$ Given that you could do it with .NET dlls, I'd say its also possible with Java libraries. Have you tried following this? reference.wolfram.com/mathematica/JLink/tutorial/… $\endgroup$
    – Jonie
    Commented Aug 12, 2013 at 3:26
  • $\begingroup$ tks @Jonie, it was a begin. $\endgroup$
    – Murta
    Commented Aug 12, 2013 at 10:42

1 Answer 1

4
$\begingroup$

Looking at this it is easy to figure out what to do:

c = LoadJavaClass[ "uk.ac.shef.wit.simmetrics.similaritymetrics.Levenshtein"]

Then

Constructors@c

and

Methods@c

will get you going. I tried things on Windows, but it should work on Mac alike:

Mathematica graphics

$\endgroup$
1
  • 4
    $\begingroup$ I just want to add a couple remarks to Rolf's excellent answer. I want to discourage the use of an idiom like ReinstallJava[ClassPath->NotebookDirectory[]] for modifying the Java classpath. ReinstallJava is a destructive operation that might impact other J/Link-using packages currently in use on your system. Instead, use AddToClassPath["some dir containing jar files"]. The Simmetrics library also has a full set of JavaDocs that you can download separately from the site. That type of documentation is indispensable when tinkering with a library via J/Link. $\endgroup$ Commented Aug 13, 2013 at 15:28

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.