Spaces:
Sleeping
Sleeping
Update functions.py
Browse files- functions.py +21 -4
functions.py
CHANGED
@@ -121,7 +121,6 @@ def preprocess_text(text):
|
|
121 |
return text
|
122 |
|
123 |
|
124 |
-
|
125 |
def generate_variants(keyword):
|
126 |
# Split the keyword into individual words
|
127 |
words = keyword.split()
|
@@ -145,7 +144,6 @@ def generate_variants(keyword):
|
|
145 |
return [original, all_upper, all_lower, no_space_title, no_space_upper, no_space_lower, initials]
|
146 |
|
147 |
|
148 |
-
|
149 |
# Function to check if a cell contains any excluded keywords
|
150 |
def contains_excluded_keywords(cell, excluded_keywords):
|
151 |
if isinstance(cell, np.ndarray):
|
@@ -157,7 +155,6 @@ def contains_excluded_keywords(cell, excluded_keywords):
|
|
157 |
return
|
158 |
|
159 |
|
160 |
-
|
161 |
# Function to extract terms from a cell
|
162 |
def extract_terms(cell):
|
163 |
if isinstance(cell, np.ndarray):
|
@@ -167,4 +164,24 @@ def extract_terms(cell):
|
|
167 |
# Split the string by commas and strip whitespace from each term
|
168 |
return [term.strip() for term in cell.split(',') if term.strip()]
|
169 |
else:
|
170 |
-
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
return text
|
122 |
|
123 |
|
|
|
124 |
def generate_variants(keyword):
|
125 |
# Split the keyword into individual words
|
126 |
words = keyword.split()
|
|
|
144 |
return [original, all_upper, all_lower, no_space_title, no_space_upper, no_space_lower, initials]
|
145 |
|
146 |
|
|
|
147 |
# Function to check if a cell contains any excluded keywords
|
148 |
def contains_excluded_keywords(cell, excluded_keywords):
|
149 |
if isinstance(cell, np.ndarray):
|
|
|
155 |
return
|
156 |
|
157 |
|
|
|
158 |
# Function to extract terms from a cell
|
159 |
def extract_terms(cell):
|
160 |
if isinstance(cell, np.ndarray):
|
|
|
164 |
# Split the string by commas and strip whitespace from each term
|
165 |
return [term.strip() for term in cell.split(',') if term.strip()]
|
166 |
else:
|
167 |
+
return []
|
168 |
+
|
169 |
+
|
170 |
+
def remove_excluded_from_list(keywords_list, excluded_keywords):
|
171 |
+
"""
|
172 |
+
Remove items from the keywords_list if they contain any of the excluded keywords.
|
173 |
+
This function checks for partial matches in a case-insensitive manner.
|
174 |
+
"""
|
175 |
+
if not isinstance(keywords_list, list):
|
176 |
+
return keywords_list # If it's not a list, return as is
|
177 |
+
|
178 |
+
filtered_list = []
|
179 |
+
for item in keywords_list:
|
180 |
+
# Check if item contains any excluded keyword (case-insensitive)
|
181 |
+
if any(kw.lower() in item.lower() for kw in excluded_keywords):
|
182 |
+
# Skip this item if it matches an excluded keyword
|
183 |
+
continue
|
184 |
+
else:
|
185 |
+
filtered_list.append(item)
|
186 |
+
|
187 |
+
return filtered_list
|