Skip to content

Commit 5ff8309

Browse files
authored
Merge pull request #118 from DHANUSHRAJA22/patch-1
fix: add missing normalise_text function to resolve ImportError and CI failurefix: add missing normalise_text function to fix ImportErrorfix: add m…
2 parents 7f9324a + 7f3c9ba commit 5ff8309

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
11
"""
22
MIT License
3-
43
Copyright (c) 2023 Ulster University (https://www.ulster.ac.uk).
54
Project: Harmony (https://harmonydata.ac.uk)
65
Maintainer: Thomas Wood (https://fastdatascience.com)
7-
86
Permission is hereby granted, free of charge, to any person obtaining a copy
97
of this software and associated documentation files (the "Software"), to deal
108
in the Software without restriction, including without limitation the rights
119
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1210
copies of the Software, and to permit persons to whom the Software is
1311
furnished to do so, subject to the following conditions:
14-
1512
The above copyright notice and this permission notice shall be included in all
1613
copies or substantial portions of the Software.
17-
1814
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1915
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2016
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2117
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2218
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2319
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2420
SOFTWARE.
25-
2621
"""
27-
2822
from typing import List, Optional
2923

30-
3124
def strip_prefixes(question: str, prefixes: Optional[List[str]] = None) -> str:
3225
"""
3326
Strips specified prefixes from a question string if they are present.
34-
3527
Args:
3628
question (str): The question string from which prefixes need to be removed.
3729
prefixes (Optional[List[str]]): A list of prefixes to remove from the question.
3830
If not provided, a default set of common prefixes is used.
39-
4031
Returns:
4132
str: The question string with the prefix removed, if a match is found;
4233
otherwise, the original question.
43-
4434
Example:
4535
question = "Have you ever traveled abroad?"
4636
result = strip_prefixes(question)
@@ -57,8 +47,19 @@ def strip_prefixes(question: str, prefixes: Optional[List[str]] = None) -> str:
5747
"Do you think",
5848
]
5949
prefixes = prefixes or default_prefixes
60-
6150
for prefix in prefixes:
6251
if question.lower().startswith(prefix.lower()):
6352
return question[len(prefix) :].strip()
6453
return question
54+
55+
def normalise_text(text: str) -> str:
56+
"""
57+
Normalizes text by removing extra whitespace and converting to lowercase.
58+
59+
Args:
60+
text (str): The input text to normalize
61+
62+
Returns:
63+
str: Normalized text
64+
"""
65+
return ' '.join(text.strip().split()).lower()

0 commit comments

Comments
 (0)