2017-09-26 17:39:15 +03:00
|
|
|
# coding: utf8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from ...attrs import LIKE_NUM
|
|
|
|
|
|
|
|
|
|
|
|
_num_words = set("""
|
|
|
|
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
|
|
|
|
""".split())
|
|
|
|
|
|
|
|
_ordinal_words = set("""
|
|
|
|
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
|
|
|
|
""".split())
|
|
|
|
|
|
|
|
|
|
|
|
def like_num(text):
|
2017-09-26 17:43:28 +03: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
|
2017-09-26 17:39:15 +03:00
|
|
|
text = text.replace(',', '').replace('.', '')
|
|
|
|
if text.isdigit():
|
|
|
|
return True
|
|
|
|
if text.count('/') == 1:
|
|
|
|
num, denom = text.split('/')
|
|
|
|
if num.isdigit() and denom.isdigit():
|
|
|
|
return True
|
2018-01-08 05:25:08 +03:00
|
|
|
if text.lower() in _num_words:
|
2017-09-26 17:39:15 +03:00
|
|
|
return True
|
2018-01-08 05:28:50 +03:00
|
|
|
if text.lower() in _ordinal_words:
|
|
|
|
return True
|
2017-09-26 17:39:15 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
LEX_ATTRS = {
|
|
|
|
LIKE_NUM: like_num
|
|
|
|
}
|