2017-03-12 15:07:28 +03:00
|
|
|
|
# coding: utf8
|
2016-12-08 21:46:43 +03:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2017-01-08 22:37:39 +03:00
|
|
|
|
import re
|
2016-12-08 21:46:43 +03:00
|
|
|
|
|
2017-01-08 22:37:39 +03:00
|
|
|
|
|
|
|
|
|
_ALPHA_LOWER = """
|
|
|
|
|
a ä à á â ǎ æ ã å ā ă ą b c ç ć č ĉ ċ c̄ d ð ď e é è ê ë ė ȅ ȩ ẽ ę f g ĝ ğ h i ı
|
|
|
|
|
î ï í ī ì ȉ ǐ į ĩ j k ķ l ł ļ m n ñ ń ň ņ o ö ó ò ő ô õ œ ø ō ő ǒ ơ p q r ř ŗ s
|
|
|
|
|
ß ś š ş ŝ t ť u ú û ù ú ū ű ǔ ů ų ư v w ŵ x y ÿ ý ỳ ŷ ỹ z ź ž ż þ
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ALPHA_UPPER = """
|
|
|
|
|
A Ä À Á Â Ǎ Æ Ã Å Ā Ă Ą B C Ç Ć Č Ĉ Ċ C̄ D Ð Ď E É È Ê Ë Ė Ȅ Ȩ Ẽ Ę F G Ĝ Ğ H I İ
|
|
|
|
|
Î Ï Í Ī Ì Ȉ Ǐ Į Ĩ J K Ķ L Ł Ļ M N Ñ Ń Ň Ņ O Ö Ó Ò Ő Ô Õ Œ Ø Ō Ő Ǒ Ơ P Q R Ř Ŗ S
|
|
|
|
|
Ś Š Ş Ŝ T Ť U Ú Û Ù Ú Ū Ű Ǔ Ů Ų Ư V W Ŵ X Y Ÿ Ý Ỳ Ŷ Ỹ Z Ź Ž Ż Þ
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_UNITS = """
|
|
|
|
|
km km² km³ m m² m³ dm dm² dm³ cm cm² cm³ mm mm² mm³ ha µm nm yd in ft kg g mg
|
|
|
|
|
µg t lb oz m/s km/h kmh mph hPa Pa mbar mb MB kb KB gb GB tb
|
|
|
|
|
TB T G M K
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CURRENCY = r"""
|
|
|
|
|
\$ £ € ¥ ฿ US\$ C\$ A\$
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_QUOTES = r"""
|
|
|
|
|
' '' " ” “ `` ` ‘ ´ ‚ , „ » «
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_PUNCT = r"""
|
|
|
|
|
… , : ; \! \? ¿ ¡ \( \) \[ \] \{ \} < > _ # \* &
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_HYPHENS = r"""
|
|
|
|
|
- – — -- ---
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LIST_ELLIPSES = [
|
|
|
|
|
r'\.\.+',
|
|
|
|
|
"…"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LIST_CURRENCY = list(_CURRENCY.strip().split())
|
|
|
|
|
LIST_QUOTES = list(_QUOTES.strip().split())
|
|
|
|
|
LIST_PUNCT = list(_PUNCT.strip().split())
|
|
|
|
|
LIST_HYPHENS = list(_HYPHENS.strip().split())
|
|
|
|
|
|
|
|
|
|
|
2017-01-14 17:51:59 +03:00
|
|
|
|
ALPHA_LOWER = _ALPHA_LOWER.strip().replace(' ', '').replace('\n', '')
|
2017-01-14 18:30:11 +03:00
|
|
|
|
ALPHA_UPPER = _ALPHA_UPPER.strip().replace(' ', '').replace('\n', '')
|
2017-01-08 22:37:39 +03:00
|
|
|
|
ALPHA = ALPHA_LOWER + ALPHA_UPPER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QUOTES = _QUOTES.strip().replace(' ', '|')
|
|
|
|
|
CURRENCY = _CURRENCY.strip().replace(' ', '|')
|
2017-01-14 17:51:59 +03:00
|
|
|
|
UNITS = _UNITS.strip().replace(' ', '|').replace('\n', '|')
|
2017-01-08 22:37:39 +03:00
|
|
|
|
HYPHENS = _HYPHENS.strip().replace(' ', '|')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Prefixes
|
|
|
|
|
|
|
|
|
|
TOKENIZER_PREFIXES = (
|
2017-02-02 18:21:11 +03:00
|
|
|
|
['§', '%', '=', r'\+'] +
|
2017-01-08 22:37:39 +03:00
|
|
|
|
LIST_PUNCT +
|
|
|
|
|
LIST_ELLIPSES +
|
|
|
|
|
LIST_QUOTES +
|
|
|
|
|
LIST_CURRENCY
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Suffixes
|
|
|
|
|
|
|
|
|
|
TOKENIZER_SUFFIXES = (
|
|
|
|
|
LIST_PUNCT +
|
|
|
|
|
LIST_ELLIPSES +
|
|
|
|
|
LIST_QUOTES +
|
|
|
|
|
[
|
|
|
|
|
r'(?<=[0-9])\+',
|
|
|
|
|
r'(?<=°[FfCcKk])\.',
|
|
|
|
|
r'(?<=[0-9])(?:{c})'.format(c=CURRENCY),
|
|
|
|
|
r'(?<=[0-9])(?:{u})'.format(u=UNITS),
|
|
|
|
|
r'(?<=[0-9{al}{p}(?:{q})])\.'.format(al=ALPHA_LOWER, p=r'%²\-\)\]\+', q=QUOTES),
|
2017-01-09 00:28:25 +03:00
|
|
|
|
r'(?<=[{au}][{au}])\.'.format(au=ALPHA_UPPER),
|
2017-01-08 22:37:39 +03:00
|
|
|
|
"'s", "'S", "’s", "’S"
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Infixes
|
|
|
|
|
|
|
|
|
|
TOKENIZER_INFIXES = (
|
|
|
|
|
LIST_ELLIPSES +
|
|
|
|
|
[
|
2017-01-13 00:58:26 +03:00
|
|
|
|
r'(?<=[0-9])[+\-\*^](?=[0-9-])',
|
2017-01-08 22:37:39 +03:00
|
|
|
|
r'(?<=[{al}])\.(?=[{au}])'.format(al=ALPHA_LOWER, au=ALPHA_UPPER),
|
|
|
|
|
r'(?<=[{a}]),(?=[{a}])'.format(a=ALPHA),
|
2017-02-02 18:22:40 +03:00
|
|
|
|
r'(?<=[{a}])[?";:=,.]*(?:{h})(?=[{a}])'.format(a=ALPHA, h=HYPHENS),
|
2017-04-07 18:30:44 +03:00
|
|
|
|
r'(?<=[{a}"])[:<>=/](?=[{a}])'.format(a=ALPHA)
|
2017-01-08 22:37:39 +03:00
|
|
|
|
]
|
|
|
|
|
)
|
2016-12-08 21:46:43 +03:00
|
|
|
|
|
|
|
|
|
|
2016-12-18 17:35:56 +03:00
|
|
|
|
__all__ = ["TOKENIZER_PREFIXES", "TOKENIZER_SUFFIXES", "TOKENIZER_INFIXES"]
|