mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-27 18:36:36 +03:00
db55577c45
* Remove unicode declarations * Remove Python 3.5 and 2.7 from CI * Don't require pathlib * Replace compat helpers * Remove OrderedDict * Use f-strings * Set Cython compiler language level * Fix typo * Re-add OrderedDict for Table * Update setup.cfg * Revert CONTRIBUTING.md * Revert lookups.md * Revert top-level.md * Small adjustments and docs [ci skip]
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
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):
|
|
# 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
|
|
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
|
|
if text.lower() in _num_words:
|
|
return True
|
|
if text.lower() in _ordinal_words:
|
|
return True
|
|
return False
|
|
|
|
|
|
LEX_ATTRS = {LIKE_NUM: like_num}
|