spaCy/spacy/lang/ti/lex_attrs.py

74 lines
1.5 KiB
Python
Raw Normal View History

from ...attrs import LIKE_NUM
_num_words = [
"ዜሮ",
"ሓደ",
"ክልተ",
"ሰለስተ",
"ኣርባዕተ",
"ሓሙሽተ",
"ሽድሽተ",
"ሸውዓተ",
"ሽሞንተ",
"ትሽዓተ",
"ዓሰርተ",
"ዕስራ",
"ሰላሳ",
"ኣርብዓ",
"ሓምሳ",
"ሱሳ",
"ሰብዓ",
"ሰማንያ",
"ቴስዓ",
"ሚእቲ",
"ሺሕ",
"ሚልዮን",
"ቢልዮን",
"ትሪልዮን",
"ኳድሪልዮን",
"ጋዚልዮን",
2021-11-05 11:56:26 +03:00
"ባዚልዮን",
]
# Tigrinya ordinals above 10 are the same as _num_words but start with "መበል "
_ordinal_words = [
2021-01-15 03:57:36 +03:00
"ቀዳማይ",
"ካልኣይ",
"ሳልሳይ",
"ራብዓይ",
2021-01-15 03:57:36 +03:00
"ሓምሻይ",
"ሻድሻይ",
"ሻውዓይ",
"ሻምናይ",
"ታሽዓይ",
2021-11-05 11:56:26 +03:00
"ዓስራይ",
]
2021-01-15 03:57:36 +03:00
def like_num(text):
if text.startswith(("+", "-", "±", "~")):
text = text[1:]
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
text_lower = text.lower()
if text_lower in _num_words:
return True
# Check ordinal number
if text_lower in _ordinal_words:
return True
if text_lower.endswith(""):
if text_lower[:-2].isdigit():
2021-01-15 03:57:36 +03:00
return True
return False
LEX_ATTRS = {LIKE_NUM: like_num}