Skip to content

Instantly share code, notes, and snippets.

@rgchris
Last active August 25, 2017 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgchris/ae72ec221d0c87d4181ac2a87d86514b to your computer and use it in GitHub Desktop.
Save rgchris/ae72ec221d0c87d4181ac2a87d86514b to your computer and use it in GitHub Desktop.
Calculate the similarity of two strings
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"
@rgchris
Copy link
Author

rgchris commented Aug 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment