2017-09-26 14:39:15 +00:00
|
|
|
from ...attrs import LIKE_NUM
|
|
|
|
|
2019-08-20 15:36:34 +00:00
|
|
|
_num_words = set(
|
|
|
|
"""
|
2017-09-26 14:39:15 +00:00
|
|
|
nul een één twee drie vier vijf zes zeven acht negen tien elf twaalf dertien
|
|
|
|
veertien twintig dertig veertig vijftig zestig zeventig tachtig negentig honderd
|
|
|
|
duizend miljoen miljard biljoen biljard triljoen triljard
|
2019-08-20 15:36:34 +00:00
|
|
|
""".split()
|
|
|
|
)
|
2017-09-26 14:39:15 +00:00
|
|
|
|
2019-08-20 15:36:34 +00:00
|
|
|
_ordinal_words = set(
|
|
|
|
"""
|
2017-09-26 14:39:15 +00:00
|
|
|
eerste tweede derde vierde vijfde zesde zevende achtste negende tiende elfde
|
|
|
|
twaalfde dertiende veertiende twintigste dertigste veertigste vijftigste
|
|
|
|
zestigste zeventigste tachtigste negentigste honderdste duizendste miljoenste
|
|
|
|
miljardste biljoenste biljardste triljoenste triljardste
|
2019-08-20 15:36:34 +00:00
|
|
|
""".split()
|
|
|
|
)
|
2017-09-26 14:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def like_num(text):
|
2017-09-26 14:43:28 +00:00
|
|
|
# This only does the most basic check for whether a token is a digit
|
|
|
|
# or matches one of the number words. In order to handle numbers like
|
|
|
|
# "drieëntwintig", more work is required.
|
|
|
|
# See this discussion: https://github.com/explosion/spaCy/pull/1177
|
2019-08-20 15:36:34 +00:00
|
|
|
text = text.replace(",", "").replace(".", "")
|
2017-09-26 14:39:15 +00:00
|
|
|
if text.isdigit():
|
|
|
|
return True
|
2019-08-20 15:36:34 +00:00
|
|
|
if text.count("/") == 1:
|
|
|
|
num, denom = text.split("/")
|
2017-09-26 14:39:15 +00:00
|
|
|
if num.isdigit() and denom.isdigit():
|
|
|
|
return True
|
2018-01-08 02:25:08 +00:00
|
|
|
if text.lower() in _num_words:
|
2017-09-26 14:39:15 +00:00
|
|
|
return True
|
2018-01-08 02:28:50 +00:00
|
|
|
if text.lower() in _ordinal_words:
|
|
|
|
return True
|
2017-09-26 14:39:15 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2019-08-20 15:36:34 +00:00
|
|
|
LEX_ATTRS = {LIKE_NUM: like_num}
|