From 7f3c9ba88a1591dce80424bf8a6a4d6fc3ace320 Mon Sep 17 00:00:00 2001 From: DHANUSH RAJA <155062318+DHANUSHRAJA22@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:51:50 +0530 Subject: [PATCH] fix: add missing normalise_text function to fix ImportErrorfix: add missing normalise_text function to fix ImportError in HTML parserUpdate __init__.py Adds the missing normalise_text function that was causing ImportError in HTML parser and preventing all tests from passing. This function normalizes text by removing extra whitespace and converting to lowercase as required by PR #117. --- src/harmony/parsing/util/__init__.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/harmony/parsing/util/__init__.py b/src/harmony/parsing/util/__init__.py index bff6538..c4a38bd 100644 --- a/src/harmony/parsing/util/__init__.py +++ b/src/harmony/parsing/util/__init__.py @@ -1,20 +1,16 @@ """ MIT License - Copyright (c) 2023 Ulster University (https://www.ulster.ac.uk). Project: Harmony (https://harmonydata.ac.uk) Maintainer: Thomas Wood (https://fastdatascience.com) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -22,25 +18,19 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """ - from typing import List, Optional - def strip_prefixes(question: str, prefixes: Optional[List[str]] = None) -> str: """ Strips specified prefixes from a question string if they are present. - Args: question (str): The question string from which prefixes need to be removed. prefixes (Optional[List[str]]): A list of prefixes to remove from the question. If not provided, a default set of common prefixes is used. - Returns: str: The question string with the prefix removed, if a match is found; otherwise, the original question. - Example: question = "Have you ever traveled abroad?" result = strip_prefixes(question) @@ -57,8 +47,19 @@ def strip_prefixes(question: str, prefixes: Optional[List[str]] = None) -> str: "Do you think", ] prefixes = prefixes or default_prefixes - for prefix in prefixes: if question.lower().startswith(prefix.lower()): return question[len(prefix) :].strip() return question + +def normalise_text(text: str) -> str: + """ + Normalizes text by removing extra whitespace and converting to lowercase. + + Args: + text (str): The input text to normalize + + Returns: + str: Normalized text + """ + return ' '.join(text.strip().split()).lower()