spaCy/spacy/lang/id/punctuation.py

54 lines
2.1 KiB
Python
Raw Normal View History

2017-07-24 02:17:18 +03:00
# coding: utf8
from __future__ import unicode_literals
from ..punctuation import TOKENIZER_PREFIXES, TOKENIZER_SUFFIXES, TOKENIZER_INFIXES
2017-07-24 09:57:21 +03:00
from ..char_classes import merge_chars, split_chars, _currency, _units
2017-07-24 02:17:18 +03:00
from ..char_classes import LIST_PUNCT, LIST_ELLIPSES, LIST_QUOTES
2017-07-24 09:57:21 +03:00
from ..char_classes import QUOTES, UNITS, ALPHA, ALPHA_LOWER, ALPHA_UPPER, HYPHENS
_units = (_units + 's bit Gbps Mbps mbps Kbps kbps ƒ ppi px '
'Hz kHz MHz GHz mAh '
'ratus rb ribu ribuan '
'juta jt jutaan mill?iar million bil[l]?iun bilyun billion '
)
2017-08-02 18:42:47 +03:00
_currency = (_currency + r' USD Rp IDR RMB SGD S\$')
2017-07-26 15:28:38 +03:00
_months = ('Januari Februari Maret April Mei Juni Juli Agustus September '
'Oktober November Desember January February March May June '
'July August October December Jan Feb Mar Jun Jul Aug Sept '
'Oct Okt Nov Des ')
2017-07-24 02:17:18 +03:00
UNITS = merge_chars(_units)
CURRENCY = merge_chars(_currency)
2017-07-26 15:13:36 +03:00
HTML_PREFIX = r'<(b|strong|i|em|p|span|div|br)\s?/>|<a([^>]+)>'
HTML_SUFFIX = r'</(b|strong|i|em|p|span|div|a)>'
2017-07-24 09:57:21 +03:00
MONTHS = merge_chars(_months)
LIST_CURRENCY = split_chars(_currency)
TOKENIZER_PREFIXES.remove('#') # hashtag
2017-07-26 15:13:36 +03:00
_prefixes = TOKENIZER_PREFIXES + LIST_CURRENCY + [HTML_PREFIX] + ['/', '']
2017-07-24 02:17:18 +03:00
2017-07-26 15:28:38 +03:00
_suffixes = TOKENIZER_SUFFIXES + [r'\-[Nn]ya', '-[KkMm]u', '[—-]'] + [
2017-08-02 18:42:47 +03:00
r'(?<={c})(?:[0-9]+)'.format(c=CURRENCY),
2017-07-24 09:57:21 +03:00
r'(?<=[0-9])(?:{u})'.format(u=UNITS),
2017-07-24 02:17:18 +03:00
r'(?<=[0-9])%',
r'(?<=[0-9{a}]{h})(?:[\.,:-])'.format(a=ALPHA, h=HTML_SUFFIX),
r'(?<=[0-9{a}])(?:{h})'.format(a=ALPHA, h=HTML_SUFFIX),
]
_infixes = TOKENIZER_INFIXES + [
2017-07-24 09:57:21 +03:00
r'(?<=[0-9])[\\/](?=[0-9%-])',
r'(?<=[0-9])%(?=[{a}0-9/])'.format(a=ALPHA),
r'(?<={u})[\/-](?=[0-9])'.format(u=UNITS),
r'(?<={m})[\/-](?=[0-9])'.format(m=MONTHS),
r'(?<=[0-9\)][\.,])"(?=[0-9])',
r'(?<=[{a}\)][\.,\'])["—](?=[{a}])'.format(a=ALPHA),
r'(?<=[{a}])-(?=[0-9])'.format(a=ALPHA),
r'(?<=[0-9])-(?=[{a}])'.format(a=ALPHA),
r'(?<=[{a}])[\/-](?={c}{a})'.format(a=ALPHA, c=CURRENCY),
2017-07-24 02:17:18 +03:00
]
TOKENIZER_PREFIXES = _prefixes
TOKENIZER_SUFFIXES = _suffixes
TOKENIZER_INFIXES = _infixes