Last active
August 25, 2017 05:38
-
-
Save rgchris/ae72ec221d0c87d4181ac2a87d86514b to your computer and use it in GitHub Desktop.
Calculate the similarity of two strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: "Similarity Of" | |
Author: "Christopher Ross-Gill" | |
Date: 25-Aug-2017 | |
File: %similarity-of.red | |
Purpose: "Calculate the similarity (%) of two strings." | |
Rights: http://opensource.org/licenses/Apache-2.0 | |
] | |
do %simplediff.red | |
; from https://github.com/rgchris/Scripts/blob/master/red/simplediff.red | |
similarity-of: func [ | |
before [string!] | |
after [string!] | |
][ | |
round 200% * ( | |
length? rejoin collect [ | |
foreach [disposition part] diff before after [ | |
if disposition = '= [keep part] | |
] | |
] | |
) / ( | |
add length? before length? after | |
) | |
] | |
probe similarity-of "Pencilvaneya" "Pennsylvania" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by Pattern Matching: The Gestalt Approach.