mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 18:06:29 +03:00
1139247532
* Revert changes to priority of `token_match` so that it has priority over all other tokenizer patterns * Add lookahead and potentially slow lookbehind back to the default URL pattern * Expand character classes in URL pattern to improve matching around lookaheads and lookbehinds related to #4882 * Revert changes to Hungarian tokenizer * Revert (xfail) several URL tests to their status before #4374 * Update `tokenizer.explain()` and docs accordingly
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
# coding: utf8
|
|
from __future__ import unicode_literals
|
|
|
|
from ..char_classes import LIST_PUNCT, LIST_ELLIPSES, LIST_QUOTES, CONCAT_QUOTES
|
|
from ..char_classes import CONCAT_ICONS, UNITS, ALPHA, ALPHA_LOWER, ALPHA_UPPER
|
|
|
|
|
|
# removing ° from the special icons to keep e.g. 99° as one token
|
|
_concat_icons = CONCAT_ICONS.replace("\u00B0", "")
|
|
|
|
_currency = r"\$¢£€¥฿"
|
|
_quotes = CONCAT_QUOTES.replace("'", "")
|
|
|
|
_prefixes = (
|
|
LIST_PUNCT
|
|
+ LIST_ELLIPSES
|
|
+ LIST_QUOTES
|
|
+ [_concat_icons]
|
|
+ [r"[,.:](?=[{a}])".format(a=ALPHA)]
|
|
)
|
|
|
|
_suffixes = (
|
|
[r"\+"]
|
|
+ LIST_PUNCT
|
|
+ LIST_ELLIPSES
|
|
+ LIST_QUOTES
|
|
+ [_concat_icons]
|
|
+ [
|
|
r"(?<=[0-9])\+",
|
|
r"(?<=°[FfCcKk])\.",
|
|
r"(?<=[0-9])(?:[{c}])".format(c=_currency),
|
|
r"(?<=[0-9])(?:{u})".format(u=UNITS),
|
|
r"(?<=[{al}{e}{q}(?:{c})])\.".format(
|
|
al=ALPHA_LOWER, e=r"%²\-\+", q=CONCAT_QUOTES, c=_currency
|
|
),
|
|
r"(?<=[{al})])-e".format(al=ALPHA_LOWER),
|
|
]
|
|
)
|
|
|
|
_infixes = (
|
|
LIST_ELLIPSES
|
|
+ [_concat_icons]
|
|
+ [
|
|
r"(?<=[{al}])\.(?=[{au}])".format(al=ALPHA_LOWER, au=ALPHA_UPPER),
|
|
r"(?<=[{a}])[,!?](?=[{a}])".format(a=ALPHA),
|
|
r"(?<=[{a}])[:<>=](?=[{a}])".format(a=ALPHA),
|
|
r"(?<=[{a}])--(?=[{a}])".format(a=ALPHA),
|
|
r"(?<=[{a}]),(?=[{a}])".format(a=ALPHA),
|
|
r"(?<=[{a}])([{q}\)\]\(\[])(?=[\-{a}])".format(a=ALPHA, q=_quotes),
|
|
]
|
|
)
|
|
|
|
TOKENIZER_PREFIXES = _prefixes
|
|
TOKENIZER_SUFFIXES = _suffixes
|
|
TOKENIZER_INFIXES = _infixes
|