/String-Similarity

Calculate the similarity between two strings.

Primary LanguagePythonMIT LicenseMIT

String-Similarity

Calculate the similarity between two strings by rewarding both common sub-strings and common letter orderings.

Where:
`s1` = The character pairs of string 1
`s2` = The character pairs of string 2
In words:
The similarity of string1 to string2 is equal to two times the number of incommon character pairs divided by the sum of the total number of character pairs in each string.

Example:

Strings:
`string1` = "Financial"
`string2` = "Finance"

Character Pairs:
`s1` = "fi", "in", "na", "an", "nc", "ci", "ia", "al"
`s2` = "fi", "in", "na", "an", "nc", "ce"

similarity(s1, s2) = `(2 * 5) / (8 + 6)` = 0.7142

In Python:
Include wordSim.py and charPair.py in your directory.

  from wordSim import similarity
  
  string1 = "Financial"
  string2 = "Finance"
  sim = similarity(string1, string2).get_sim()
  
  print sim
  >> 0.7142

In PHP:
Include wordSim.php in your directory.

  include('/wordSim.php');
  
  $string1 = "Financial";
  $string2 = "Finance";
  $sim = Similarity::calculate($string1, $string2);
  
  echo $sim;
  >> 0.7142

In Ruby:
Coming soon...