views:

603

answers:

3

I would like to compare two strings and get some score how much these look alike. For example "The sentence is almost similar" and "The sentence is similar".

I'm not familiar with existing methods in Java ME, but for php I know the levenshtein function.

Are there better methods in Java?

+5  A: 

yeah thats a good metric, you could use StringUtil.getLevenshteinDistance() from apache commons

jspcal
It is not available in Java Mobile Edition, is it? But thanks for your response!
hsmit
you can use it with ME, just add the jar.
jspcal
hmmm, no, I'm not really so sure it's completely usable with J2ME, it has been compiled with a J2SE
Valentin Rocher
it doesn't use anything ME doesn't support. you can make and copy in the jar
jspcal
+6  A: 

Well, the Levensthein distance is a measure for how similar strings are. Or, more precisely, how many alterations have to be made that they are the same. The algorithm is available in pseudo-code on Wikipedia. Converting that to Java shouldn't be much of a problem, but it's not built-in into the base class library.

Wikipedia has some more algorithms that measure similarity of strings.

Joey
+2  A: 

I found a Levenshtein algorithm on this page.

hsmit
Good find, it seems simple enough to work in MIDP, and memory efficient, two critical factors for such platform.You should accept your own answer...Or instead accept Johannes's one, since he pointed to Wikipedia article where you (apparently) found the link you mention.
PhiLho
no, i found it before via google, but I will accept the answer!
hsmit