Download src/utils/identifier.py from Partha11/ml-server: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/Partha11/ml-server/resolve/main/src/utils/identifier.py
- Command line
-
hf download hf://spaces/Partha11/ml-server/src/utils/identifier.py
-
curl -L -o identifier.py https://huggingface.co/spaces/Partha11/ml-server/resolve/main/src/utils/identifier.py
1 kB
| import regex | |
| """ | |
| This class is used to identify if a string contains any bangla word or not | |
| |-------------------------------------------------------------------------------------------------| | |
| | * This class is written for basic usage, it can be improved dramatically | | |
| | * Changing the for loop with a binary search would result in finding specific bangla word index | | |
| | * Sorting the word chunks based on lexicographic order would also produce better results | | |
| |-------------------------------------------------------------------------------------------------| | |
| """ | |
| class Identifier: | |
| pattern = r"\P{L}*\p{Bengali}+(?:\P{L}+\p{Bengali}+)*\P{L}*" | |
| is_bangla = False | |
| def __init__(self, query): | |
| self.parts = query.split(' ') | |
| for part in self.parts: | |
| if bool(regex.match(self.pattern, part)): | |
| self.is_bangla = True | |
| break | |
| def is_bangla(self) -> bool: | |
| return self.is_bangla |