similarity_check package

Submodules

similarity_check.Similarity module

class similarity_check.Similarity.Similarity[source]

Bases: object

The class provides various similarity and dissimilarity methods including jaccard_coefficient,overlap_coefficient and hamming_distance Attributes: ———-

str1 :str

The first attribute for comparison. This can be any string that will be converted into a set.

str2 :str

The second attribute for comparison. This can be any string that will be converted into a set.

Methods

overlap_coefficient(str1, str2)

Calculates the Overlap coefficient between two sets.

hamming_distance(str1, str2)

Calculates the Hamming distance between two strings.

hamming_distance(str1, str2)[source]

Computes the Hamming distance between two strings.

The Hamming distance is defined as the number of positions at which the corresponding symbols in two strings of equal length are different.

Parameters:
  • str1 (str) – The first string for comparison.

  • str2 (str) – The second string for comparison.

Returns:

The Hamming distance between the two strings.Returns -1 if the strings have different lengths.

Return type:

int

jaccard_coefficient(str1, str2)[source]

Computes the Jaccard similarity coefficient between two sets.

The Jaccard coefficient is defined as the size of the intersection divided by the size of the union of the sets.

Parameters:
  • str1 (str) – The first string, which will be converted to a set.

  • str2 (str) – The second string, which will be converted to a set.

Returns:

The Jaccard similarity coefficient. Returns 0 if both sets are empty

Return type:

float

overlap_coefficient(str1, str2)[source]

Computes the Overlap coefficient between two sets.

The Overlap coefficient is defined as the size of the intersection divided by the size of the smaller set.

Parameters:
  • str1 (str) – The first string, which will be converted to a set.

  • str2 (str) – The second string, which will be converted to a set.

Returns:

The Overlap coefficient. Returns 0 if either set is empty.

Return type:

float

Module contents