aspose file tools
The moose likes Beginning Java and the fly likes Compare similar String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Compare similar String" Watch "Compare similar String" New topic
Author

Compare similar String

kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 27

Hi All,

I want to write a function which will should return the measure of similarity between two string passed to it.

Say String A and String B is passed to the function, then it should return the value, from 0 to 100. 0 being totally different string and 100 being exactly same string.

The similarity should take into consideration the order of the words.

Is there any library already for this?

Please help


OCPJP 6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32717
    
    4
You will have to work out what the algorithm you wish to use is. Also what does "similarity" mean? If you mean the same letter in the same place, then what about Ritchie and CRitchie? They would come out as 0 even though the latter String contains the former String as a substring.
kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 27

Hi,

I don't want to compare the exact order, but the order should have some weightage on calculating how similar the two strings are.


Similar String: Most of the words of the string are same and order of words are same except for few (say max 40% of words)
Jacek Garlinski
Greenhorn

Joined: Aug 08, 2011
Posts: 8
You should search for something like 'text processing algorithms'


Please correct my English.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
One approach would be the Double Metaphone algorithm (as implemented in the Apache Commons Codec library, for example). Another is the Levenshtein distance or Damerau-Levenshtein distance.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Compare similar String
 
Similar Threads
Begginer question, assigning a java string the value of a passed parameter
EL doubt
Passed with 93%
PASSED(74%)
Passed!!!