[text] Adding utils.py for is_numeric/is_numeric_strict
This commit is contained in:
12
scripts/geodata/text/utils.py
Normal file
12
scripts/geodata/text/utils.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from geodata.text.tokenize import tokenize
|
||||
from geodata.text.token_types import token_types
|
||||
|
||||
|
||||
def is_numeric(s):
|
||||
tokens = tokenize(s)
|
||||
return sum((1 for t, c in tokens if c in token_types.NUMERIC_TOKEN_TYPES)) == len(tokens)
|
||||
|
||||
|
||||
def is_numeric_strict(s):
|
||||
tokens = tokenize(s)
|
||||
return sum((1 for t, c in tokens if c == token_types.NUMERIC)) == len(tokens)
|
||||
Reference in New Issue
Block a user