Created
August 3, 2021 17:09
-
-
Save luizamboni/d16a3d2b56db266bdddae7121784daed to your computer and use it in GitHub Desktop.
detect ranges filter with nltk
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
import nltk | |
from typing import List,Union, Dict, TypedDict, Any | |
nltk.download('punkt') | |
nltk.download('averaged_perceptron_tagger') | |
def is_range_value(sentence: str) -> bool : | |
tokens: List[str] = nltk.word_tokenize(sentence) | |
taggeds = nltk.pos_tag(tokens) | |
cds = list(filter(lambda tagged_token: tagged_token[1] == 'CD', taggeds)) | |
if len(cds) > 1: | |
return True | |
else: | |
return False | |
examples: List[Dict[str, Any]] = [ | |
{ | |
"message": "5 a 10 kg", | |
"is_range": True, | |
} | |
] | |
for example in examples: | |
print(example) | |
print( | |
is_range_value( | |
example["message"] | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment