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