In this article, I presented some requirements for a similarity ranking algorithm such that it would be applicable to many domains, in many languages. I described a metric and associated algorithm that meets those requirements by comparing the adjacent character pairs contained in two strings. I illustrated the algorithm with examples, and presented a Java implementation.
To close the article, I should like to return to some of the examples quoted at the start for which I argued the inadequacy of the existing algorithms. Contrary to the Soundex algorithm and the Edit Distance, my algorithm rates the strings ‘FRANCE’ and ‘REPUBLIC OF FRANCE’ to have a good similarity of 56%. On the other hand, the strings ‘FRANCE’ and ‘QUEBEC’ are seen to be reassuringly dissimilar, with a similarity of 0%. And ‘FRENCH REPUBLIC’ is more similar to ‘REPUBLIC OF FRANCE’ than it is to ‘REPUBLIC OF CUBA’ with similarities of 72% and 61%, respectively.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |