-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared_utils.py
38 lines (28 loc) · 1.02 KB
/
shared_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import re
def compare_norm_texts(text1, text2):
"""
Compare two normalized texts and return True if they are equal, False otherwise.
Parameters:
text1 (str): The first text to compare.
text2 (str): The second text to compare.
Returns:
bool: True if the normalized texts are equal, False otherwise.
"""
def normalize_string(input_string):
# Remove symbols using regular expression
normalized_string = re.sub(r"[^\w\s]", "", input_string)
# Convert to lowercase
normalized_string = normalized_string.lower()
# Remove spaces
normalized_string = normalized_string.replace(" ", "")
return normalized_string
if text1 is None and text2 is None:
raise ValueError("Both text1 and text2 are None")
elif text1 is None:
raise ValueError("text1 is None")
elif text2 is None:
raise ValueError("text2 is None")
if normalize_string(text1) == normalize_string(text2):
return True
else:
return False