This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add remove_special_characters tool
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
hyko_toolkit/functions/NLP/nlp_data_cleaning/remove_special_characters/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM hyko-sdk:latest | ||
|
||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN poetry run pip install regex | ||
|
||
CMD ["poetry", "run", "uvicorn", "--host", "0.0.0.0", "--port", "3000","main:func"] |
23 changes: 23 additions & 0 deletions
23
hyko_toolkit/functions/NLP/nlp_data_cleaning/remove_special_characters/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import re | ||
|
||
from metadata import Inputs, Outputs, Params, func | ||
|
||
|
||
@func.on_execute | ||
async def main(inputs: Inputs, params: Params) -> Outputs: | ||
""" | ||
Remove special characters and punctuation from the text, keeping only alphanumeric characters and spaces. | ||
Args: | ||
- text (str): The input text from which special characters and punctuation will be removed. | ||
Returns: | ||
- str: The text with special characters and punctuation removed. | ||
""" | ||
# Define the regular expression pattern to match non-alphanumeric characters (excluding spaces) | ||
pattern = r"[^a-zA-Z0-9\s]" | ||
|
||
# Replace non-alphanumeric characters with an empty string | ||
cleaned_text = re.sub(pattern, "", inputs.text) | ||
|
||
return Outputs(result=" ".join(cleaned_text.strip().split())) |
28 changes: 28 additions & 0 deletions
28
hyko_toolkit/functions/NLP/nlp_data_cleaning/remove_special_characters/metadata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pydantic import Field | ||
|
||
from hyko_sdk.function import SDKFunction | ||
from hyko_sdk.metadata import CoreModel | ||
|
||
func = SDKFunction( | ||
description="A function to remove special characters and punctuation from text." | ||
) | ||
|
||
|
||
@func.set_input | ||
class Inputs(CoreModel): | ||
text: str = Field( | ||
..., | ||
description="The input text from which special characters and punctuation will be removed.", | ||
) | ||
|
||
|
||
@func.set_param | ||
class Params(CoreModel): | ||
pass | ||
|
||
|
||
@func.set_output | ||
class Outputs(CoreModel): | ||
result: str = Field( | ||
..., description="The text with special characters and punctuation removed." | ||
) |