2017-05-08 16:55:52 +03:00
|
|
|
|
# coding: utf8
|
2017-01-03 20:17:57 +03:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2017-04-07 16:54:25 +03:00
|
|
|
|
# The use of this module turns out to be important, to avoid pathological
|
|
|
|
|
# back-tracking. See Issue #957
|
2017-05-09 01:34:31 +03:00
|
|
|
|
import regex as re
|
2017-01-03 20:17:57 +03:00
|
|
|
|
|
2017-05-08 16:55:52 +03:00
|
|
|
|
from ..symbols import ORTH, POS, LEMMA, SPACE, PUNCT
|
|
|
|
|
|
|
|
|
|
|
2017-03-05 01:13:11 +03:00
|
|
|
|
# URL validation regex courtesy of: https://mathiasbynens.be/demo/url-regex
|
|
|
|
|
# A few minor mods to this regex to account for use cases represented in test_urls
|
2017-05-09 01:00:00 +03:00
|
|
|
|
URL_PATTERN = (
|
2017-03-05 01:13:11 +03:00
|
|
|
|
r"^"
|
|
|
|
|
# in order to support the prefix tokenization (see prefix test cases in test_urls).
|
|
|
|
|
r"(?=[\w])"
|
|
|
|
|
# protocol identifier
|
|
|
|
|
r"(?:(?:https?|ftp|mailto)://)?"
|
|
|
|
|
# user:pass authentication
|
|
|
|
|
r"(?:\S+(?::\S*)?@)?"
|
|
|
|
|
r"(?:"
|
|
|
|
|
# IP address exclusion
|
|
|
|
|
# private & local networks
|
|
|
|
|
r"(?!(?:10|127)(?:\.\d{1,3}){3})"
|
|
|
|
|
r"(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})"
|
|
|
|
|
r"(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})"
|
|
|
|
|
# IP address dotted notation octets
|
|
|
|
|
# excludes loopback network 0.0.0.0
|
|
|
|
|
# excludes reserved space >= 224.0.0.0
|
|
|
|
|
# excludes network & broadcast addresses
|
|
|
|
|
# (first & last IP address of each class)
|
2017-04-07 16:54:25 +03:00
|
|
|
|
# MH: Do we really need this? Seems excessive, and seems to have caused
|
|
|
|
|
# Issue #957
|
2017-03-05 01:13:11 +03:00
|
|
|
|
r"(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])"
|
|
|
|
|
r"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}"
|
|
|
|
|
r"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
|
|
|
|
|
r"|"
|
|
|
|
|
# host name
|
2017-10-14 13:58:07 +03:00
|
|
|
|
r"(?:(?:[a-z0-9\-]*)?[a-z0-9]+)"
|
2017-03-05 01:13:11 +03:00
|
|
|
|
# domain name
|
2017-10-14 13:58:07 +03:00
|
|
|
|
r"(?:\.(?:[a-z0-9\-])*[a-z0-9]+)*"
|
2017-03-05 01:13:11 +03:00
|
|
|
|
# TLD identifier
|
2017-10-14 13:58:07 +03:00
|
|
|
|
r"(?:\.(?:[a-z]{2,}))"
|
2017-03-05 01:13:11 +03:00
|
|
|
|
r")"
|
|
|
|
|
# port number
|
|
|
|
|
r"(?::\d{2,5})?"
|
|
|
|
|
# resource path
|
|
|
|
|
r"(?:/\S*)?"
|
|
|
|
|
# query parameters
|
|
|
|
|
r"\??(:?\S*)?"
|
|
|
|
|
# in order to support the suffix tokenization (see suffix test cases in test_urls),
|
|
|
|
|
r"(?<=[\w/])"
|
|
|
|
|
r"$"
|
|
|
|
|
).strip()
|
2017-01-03 20:17:57 +03:00
|
|
|
|
|
2017-05-09 01:34:31 +03:00
|
|
|
|
TOKEN_MATCH = re.compile(URL_PATTERN, re.UNICODE).match
|
2017-01-03 20:17:57 +03:00
|
|
|
|
|
2017-05-08 16:55:52 +03:00
|
|
|
|
|
|
|
|
|
BASE_EXCEPTIONS = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for exc_data in [
|
|
|
|
|
{ORTH: " ", POS: SPACE},
|
|
|
|
|
{ORTH: "\t", POS: SPACE},
|
|
|
|
|
{ORTH: "\\t", POS: SPACE},
|
|
|
|
|
{ORTH: "\n", POS: SPACE},
|
|
|
|
|
{ORTH: "\\n", POS: SPACE},
|
|
|
|
|
{ORTH: "\u2014", POS: PUNCT, LEMMA: "--"},
|
💫 Tidy up and auto-format .py files (#2983)
<!--- Provide a general summary of your changes in the title. -->
## Description
- [x] Use [`black`](https://github.com/ambv/black) to auto-format all `.py` files.
- [x] Update flake8 config to exclude very large files (lemmatization tables etc.)
- [x] Update code to be compatible with flake8 rules
- [x] Fix various small bugs, inconsistencies and messy stuff in the language data
- [x] Update docs to explain new code style (`black`, `flake8`, when to use `# fmt: off` and `# fmt: on` and what `# noqa` means)
Once #2932 is merged, which auto-formats and tidies up the CLI, we'll be able to run `flake8 spacy` actually get meaningful results.
At the moment, the code style and linting isn't applied automatically, but I'm hoping that the new [GitHub Actions](https://github.com/features/actions) will let us auto-format pull requests and post comments with relevant linting information.
### Types of change
enhancement, code style
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-11-30 19:03:03 +03:00
|
|
|
|
{ORTH: "\u00a0", POS: SPACE, LEMMA: " "},
|
|
|
|
|
]:
|
2017-11-02 01:02:45 +03:00
|
|
|
|
BASE_EXCEPTIONS[exc_data[ORTH]] = [exc_data]
|
2017-05-08 16:55:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for orth in [
|
💫 Tidy up and auto-format .py files (#2983)
<!--- Provide a general summary of your changes in the title. -->
## Description
- [x] Use [`black`](https://github.com/ambv/black) to auto-format all `.py` files.
- [x] Update flake8 config to exclude very large files (lemmatization tables etc.)
- [x] Update code to be compatible with flake8 rules
- [x] Fix various small bugs, inconsistencies and messy stuff in the language data
- [x] Update docs to explain new code style (`black`, `flake8`, when to use `# fmt: off` and `# fmt: on` and what `# noqa` means)
Once #2932 is merged, which auto-formats and tidies up the CLI, we'll be able to run `flake8 spacy` actually get meaningful results.
At the moment, the code style and linting isn't applied automatically, but I'm hoping that the new [GitHub Actions](https://github.com/features/actions) will let us auto-format pull requests and post comments with relevant linting information.
### Types of change
enhancement, code style
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-11-30 19:03:03 +03:00
|
|
|
|
"'",
|
|
|
|
|
'\\")',
|
|
|
|
|
"<space>",
|
|
|
|
|
"''",
|
|
|
|
|
"C++",
|
|
|
|
|
"a.",
|
|
|
|
|
"b.",
|
|
|
|
|
"c.",
|
|
|
|
|
"d.",
|
|
|
|
|
"e.",
|
|
|
|
|
"f.",
|
|
|
|
|
"g.",
|
|
|
|
|
"h.",
|
|
|
|
|
"i.",
|
|
|
|
|
"j.",
|
|
|
|
|
"k.",
|
|
|
|
|
"l.",
|
|
|
|
|
"m.",
|
|
|
|
|
"n.",
|
|
|
|
|
"o.",
|
|
|
|
|
"p.",
|
|
|
|
|
"q.",
|
|
|
|
|
"r.",
|
|
|
|
|
"s.",
|
|
|
|
|
"t.",
|
|
|
|
|
"u.",
|
|
|
|
|
"v.",
|
|
|
|
|
"w.",
|
|
|
|
|
"x.",
|
|
|
|
|
"y.",
|
|
|
|
|
"z.",
|
|
|
|
|
"ä.",
|
|
|
|
|
"ö.",
|
|
|
|
|
"ü.",
|
|
|
|
|
]:
|
2017-05-08 16:55:52 +03:00
|
|
|
|
BASE_EXCEPTIONS[orth] = [{ORTH: orth}]
|
|
|
|
|
|
|
|
|
|
|
💫 Tidy up and auto-format .py files (#2983)
<!--- Provide a general summary of your changes in the title. -->
## Description
- [x] Use [`black`](https://github.com/ambv/black) to auto-format all `.py` files.
- [x] Update flake8 config to exclude very large files (lemmatization tables etc.)
- [x] Update code to be compatible with flake8 rules
- [x] Fix various small bugs, inconsistencies and messy stuff in the language data
- [x] Update docs to explain new code style (`black`, `flake8`, when to use `# fmt: off` and `# fmt: on` and what `# noqa` means)
Once #2932 is merged, which auto-formats and tidies up the CLI, we'll be able to run `flake8 spacy` actually get meaningful results.
At the moment, the code style and linting isn't applied automatically, but I'm hoping that the new [GitHub Actions](https://github.com/features/actions) will let us auto-format pull requests and post comments with relevant linting information.
### Types of change
enhancement, code style
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-11-30 19:03:03 +03:00
|
|
|
|
emoticons = set(
|
|
|
|
|
"""
|
2017-05-08 16:55:52 +03:00
|
|
|
|
:)
|
|
|
|
|
:-)
|
|
|
|
|
:))
|
|
|
|
|
:-))
|
|
|
|
|
:)))
|
|
|
|
|
:-)))
|
|
|
|
|
(:
|
|
|
|
|
(-:
|
|
|
|
|
=)
|
|
|
|
|
(=
|
|
|
|
|
")
|
|
|
|
|
:]
|
|
|
|
|
:-]
|
|
|
|
|
[:
|
|
|
|
|
[-:
|
|
|
|
|
:o)
|
|
|
|
|
(o:
|
|
|
|
|
:}
|
|
|
|
|
:-}
|
|
|
|
|
8)
|
|
|
|
|
8-)
|
|
|
|
|
(-8
|
|
|
|
|
;)
|
|
|
|
|
;-)
|
|
|
|
|
(;
|
|
|
|
|
(-;
|
|
|
|
|
:(
|
|
|
|
|
:-(
|
|
|
|
|
:((
|
|
|
|
|
:-((
|
|
|
|
|
:(((
|
|
|
|
|
:-(((
|
|
|
|
|
):
|
|
|
|
|
)-:
|
|
|
|
|
=(
|
|
|
|
|
>:(
|
|
|
|
|
:')
|
|
|
|
|
:'-)
|
|
|
|
|
:'(
|
|
|
|
|
:'-(
|
|
|
|
|
:/
|
|
|
|
|
:-/
|
|
|
|
|
=/
|
|
|
|
|
=|
|
|
|
|
|
:|
|
|
|
|
|
:-|
|
|
|
|
|
:1
|
|
|
|
|
:P
|
|
|
|
|
:-P
|
|
|
|
|
:p
|
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|
|
|
(ಠ_ಠ)
|
|
|
|
|
¯\(ツ)/¯
|
|
|
|
|
(╯°□°)╯︵┻━┻
|
|
|
|
|
><(((*>
|
💫 Tidy up and auto-format .py files (#2983)
<!--- Provide a general summary of your changes in the title. -->
## Description
- [x] Use [`black`](https://github.com/ambv/black) to auto-format all `.py` files.
- [x] Update flake8 config to exclude very large files (lemmatization tables etc.)
- [x] Update code to be compatible with flake8 rules
- [x] Fix various small bugs, inconsistencies and messy stuff in the language data
- [x] Update docs to explain new code style (`black`, `flake8`, when to use `# fmt: off` and `# fmt: on` and what `# noqa` means)
Once #2932 is merged, which auto-formats and tidies up the CLI, we'll be able to run `flake8 spacy` actually get meaningful results.
At the moment, the code style and linting isn't applied automatically, but I'm hoping that the new [GitHub Actions](https://github.com/features/actions) will let us auto-format pull requests and post comments with relevant linting information.
### Types of change
enhancement, code style
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-11-30 19:03:03 +03:00
|
|
|
|
""".split()
|
|
|
|
|
)
|
2017-05-08 16:55:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for orth in emoticons:
|
|
|
|
|
BASE_EXCEPTIONS[orth] = [{ORTH: orth}]
|