From 7b3f4e917517c9f2cd5e26e3e53d3a429892c50f Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 24 Jul 2016 03:37:11 -0400 Subject: [PATCH] [text] Adding utils.py for is_numeric/is_numeric_strict --- scripts/geodata/text/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 scripts/geodata/text/utils.py diff --git a/scripts/geodata/text/utils.py b/scripts/geodata/text/utils.py new file mode 100644 index 00000000..8f73b4ad --- /dev/null +++ b/scripts/geodata/text/utils.py @@ -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)