Ratio
Ratio class#
Contains functions for calculating the ratio of similarity between two strings.
Initialise the Ratio class with the correct parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scorer |
Type[BaseScorer]
|
The scoring algorithm to use, by default LevenshteinScorer Available scorers: LevenshteinScorer, JaroScorer, JaroWinklerScorer. |
LevenshteinScorer
|
latinise |
bool
|
If special unicode characters should be removed from the strings, by default False. |
False
|
ignore_case |
bool
|
If the strings should be compared ignoring case, by default True. |
True
|
remove_punctuation |
bool
|
If punctuation should be removed from the strings, by default False. |
False
|
alphanumeric |
bool
|
If the strings should only be compared by their latin letters, by default False. |
False
|
include_partial |
bool
|
If partial substring matches should be included, by default False. |
False
|
Returns:
Type | Description |
---|---|
Ratio
|
The Ratio class. |
Examples:
Source code in stringmatch/ratio.py
ratio(string1: str, string2: str) -> int
#
Returns the similarity score between two strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string1 |
str
|
The first string to compare. |
required |
string2 |
str
|
The second string to compare. |
required |
Returns:
Type | Description |
---|---|
int
|
The score between 0 and 100. |
Examples:
>>> ratio("stringmatch", "strmatch")
84
>>> ratio("stringmatch", "something completely different")
34
Source code in stringmatch/ratio.py
ratio_list(string: str, string_list: List[str]) -> List[int]
#
Returns the similarity score between a string and a list of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string |
str
|
The string to compare. |
required |
string_list |
List[str]
|
The list of strings to compare to. |
required |
Returns:
Type | Description |
---|---|
List[int]
|
The scores between 0 and 100. |
Examples:
Source code in stringmatch/ratio.py
partial_ratio(string1: str, string2: str) -> int
#
Returns the similarity score between subsections of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string1 |
str
|
The first string to compare. |
required |
string2 |
str
|
The second string to compare. |
required |
Returns:
Type | Description |
---|---|
int
|
The score between 0 and 100. |
Examples:
>>> partial_ratio("test", "This is a test!")
75
>>> partial_ratio("word", "The word is in a really, really long string that is pretty different.")
65
Source code in stringmatch/ratio.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
_prepare_strings(string1: str, string2: str) -> Tuple[str, str]
#
Modifies the strings to be ready for comparison, according to the settings. Only meant for internal usage, but feel free to use it for something else.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string1 |
str
|
The first string to modify. |
required |
string2 |
str
|
The second string to modify. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
The two modified strings. |
Examples: