spaCy/spacy/lang/en/tokenizer_exceptions.py

449 lines
14 KiB
Python
Raw Normal View History

2017-03-12 15:07:28 +03:00
# coding: utf8
from __future__ import unicode_literals
2017-05-08 23:29:04 +03:00
from ...symbols import ORTH, LEMMA, TAG, NORM
from ...deprecated import PRON_LEMMA
2017-05-08 16:47:25 +03:00
_exc = {}
_exclude = ["Ill", "ill", "Its", "its", "Hell", "hell", "Shell", "shell",
2017-03-12 15:37:58 +03:00
"Shed", "shed", "were", "Were", "Well", "well", "Whore", "whore"]
# Pronouns
for pron in ["i"]:
for orth in [pron, pron.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'m"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'m", LEMMA: "be", TAG: "VBP", "tenspect": 1, "number": 1}]
2017-05-08 16:47:25 +03:00
_exc[orth + "m"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "m", LEMMA: "be", TAG: "VBP", "tenspect": 1, "number": 1 }]
2017-05-08 16:47:25 +03:00
_exc[orth + "'ma"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "'m", LEMMA: "be", NORM: "am"},
2017-05-08 16:47:25 +03:00
{ORTH: "a", LEMMA: "going to", NORM: "gonna"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "ma"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "m", LEMMA: "be", NORM: "am"},
2017-05-08 16:47:25 +03:00
{ORTH: "a", LEMMA: "going to", NORM: "gonna"}]
for pron in ["i", "you", "he", "she", "it", "we", "they"]:
for orth in [pron, pron.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'ll"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ll", LEMMA: "will", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "ll"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "ll", LEMMA: "will", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'ll've"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "'ll", LEMMA: "will", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "llve"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "ll", LEMMA: "will", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'d"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'d", LEMMA: "would", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "d"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "d", LEMMA: "would", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'d've"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "'d", LEMMA: "would", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "dve"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
{ORTH: "d", LEMMA: "would", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
for pron in ["i", "you", "we", "they"]:
for orth in [pron, pron.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'ve"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "ve"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
for pron in ["you", "we", "they"]:
for orth in [pron, pron.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'re"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'re", LEMMA: "be", NORM: "are"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "re"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "re", LEMMA: "be", NORM: "are", TAG: "VBZ"}]
for pron in ["he", "she", "it"]:
for orth in [pron, pron.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'s"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "'s"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "s"] = [
{ORTH: orth, LEMMA: PRON_LEMMA, TAG: "PRP"},
2017-05-08 16:47:25 +03:00
{ORTH: "s"}]
# W-words, relative pronouns, prepositions etc.
for word in ["who", "what", "when", "where", "why", "how", "there", "that"]:
for orth in [word, word.title()]:
2017-05-08 16:47:25 +03:00
_exc[orth + "'s"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "'s"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "s"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "s"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'ll"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "'ll", LEMMA: "will", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "ll"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "ll", LEMMA: "will", TAG: "MD"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'ll've"] = [
{ORTH: orth, LEMMA: word},
{ORTH: "'ll", LEMMA: "will", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "llve"] = [
{ORTH: orth, LEMMA: word},
{ORTH: "ll", LEMMA: "will", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'re"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "'re", LEMMA: "be", NORM: "are"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "re"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "re", LEMMA: "be", NORM: "are"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'ve"] = [
{ORTH: orth},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "ve"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'d"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "'d"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "d"] = [
{ORTH: orth, LEMMA: word},
2017-05-08 16:47:25 +03:00
{ORTH: "d"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "'d've"] = [
{ORTH: orth, LEMMA: word},
{ORTH: "'d", LEMMA: "would", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[orth + "dve"] = [
{ORTH: orth, LEMMA: word},
{ORTH: "d", LEMMA: "would", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
# Verbs
for verb_data in [
{ORTH: "ca", LEMMA: "can", TAG: "MD"},
{ORTH: "could", TAG: "MD"},
{ORTH: "do", LEMMA: "do"},
{ORTH: "does", LEMMA: "do"},
{ORTH: "did", LEMMA: "do", TAG: "VBD"},
{ORTH: "had", LEMMA: "have", TAG: "VBD"},
{ORTH: "may", TAG: "MD"},
{ORTH: "might", TAG: "MD"},
{ORTH: "must", TAG: "MD"},
{ORTH: "need"},
{ORTH: "ought"},
{ORTH: "sha", LEMMA: "shall", TAG: "MD"},
{ORTH: "should", TAG: "MD"},
{ORTH: "wo", LEMMA: "will", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "would", TAG: "MD"}]:
verb_data_tc = dict(verb_data)
verb_data_tc[ORTH] = verb_data_tc[ORTH].title()
for data in [verb_data, verb_data_tc]:
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "n't"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "n't", LEMMA: "not", TAG: "RB"}]
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "nt"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "nt", LEMMA: "not", TAG: "RB"}]
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "n't've"] = [
dict(data),
{ORTH: "n't", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "ntve"] = [
dict(data),
{ORTH: "nt", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
for verb_data in [
{ORTH: "could", TAG: "MD"},
{ORTH: "might"},
{ORTH: "must"},
2017-05-08 16:47:25 +03:00
{ORTH: "should"}]:
verb_data_tc = dict(verb_data)
verb_data_tc[ORTH] = verb_data_tc[ORTH].title()
for data in [verb_data, verb_data_tc]:
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "'ve"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}]
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "ve"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}]
for verb_data in [
{ORTH: "ai", TAG: "VBP", "number": 2, LEMMA: "be"},
{ORTH: "are", LEMMA: "be", TAG: "VBP", "number": 2},
{ORTH: "is", LEMMA: "be", TAG: "VBZ"},
{ORTH: "was", LEMMA: "be"},
2017-05-08 16:47:25 +03:00
{ORTH: "were", LEMMA: "be"}]:
verb_data_tc = dict(verb_data)
verb_data_tc[ORTH] = verb_data_tc[ORTH].title()
for data in [verb_data, verb_data_tc]:
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "n't"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "n't", LEMMA: "not", TAG: "RB"}]
2017-05-08 16:47:25 +03:00
_exc[data[ORTH] + "nt"] = [
dict(data),
2017-05-08 16:47:25 +03:00
{ORTH: "nt", LEMMA: "not", TAG: "RB"}]
# Other contractions with trailing apostrophe
for exc_data in [
{ORTH: "doin", LEMMA: "do", NORM: "doing"},
{ORTH: "goin", LEMMA: "go", NORM: "going"},
{ORTH: "nothin", LEMMA: "nothing"},
{ORTH: "nuthin", LEMMA: "nothing"},
{ORTH: "ol", LEMMA: "old"},
2017-05-08 16:47:25 +03:00
{ORTH: "somethin", LEMMA: "something"}]:
exc_data_tc = dict(exc_data)
exc_data_tc[ORTH] = exc_data_tc[ORTH].title()
for data in [exc_data, exc_data_tc]:
data_apos = dict(data)
data_apos[ORTH] = data_apos[ORTH] + "'"
2017-05-08 16:47:25 +03:00
_exc[data[ORTH]] = [dict(data)]
_exc[data_apos[ORTH]] = [dict(data_apos)]
# Other contractions with leading apostrophe
for exc_data in [
{ORTH: "cause", LEMMA: "because"},
{ORTH: "em", LEMMA: PRON_LEMMA, NORM: "them"},
{ORTH: "ll", LEMMA: "will"},
2017-05-08 16:47:25 +03:00
{ORTH: "nuff", LEMMA: "enough"}]:
exc_data_apos = dict(exc_data)
exc_data_apos[ORTH] = "'" + exc_data_apos[ORTH]
for data in [exc_data, exc_data_apos]:
2017-05-08 16:47:25 +03:00
_exc[data[ORTH]] = [dict(data)]
# Times
for h in range(1, 12 + 1):
for period in ["a.m.", "am"]:
2017-05-08 17:38:16 +03:00
_exc["%d%s" % (h, period)] = [
{ORTH: "%d" % h},
2017-05-08 16:47:25 +03:00
{ORTH: period, LEMMA: "a.m."}]
for period in ["p.m.", "pm"]:
2017-05-08 17:38:16 +03:00
_exc["%d%s" % (h, period)] = [
{ORTH: "%d" % h},
2017-05-08 16:47:25 +03:00
{ORTH: period, LEMMA: "p.m."}]
# Rest
2017-05-08 16:47:25 +03:00
_other_exc = {
"y'all": [
{ORTH: "y'", LEMMA: PRON_LEMMA, NORM: "you"},
2017-05-08 16:47:25 +03:00
{ORTH: "all"}],
"yall": [
{ORTH: "y", LEMMA: PRON_LEMMA, NORM: "you"},
2017-05-08 16:47:25 +03:00
{ORTH: "all"}],
"how'd'y": [
{ORTH: "how", LEMMA: "how"},
{ORTH: "'d", LEMMA: "do"},
2017-05-08 16:47:25 +03:00
{ORTH: "'y", LEMMA: PRON_LEMMA, NORM: "you"}],
"How'd'y": [
{ORTH: "How", LEMMA: "how"},
{ORTH: "'d", LEMMA: "do"},
2017-05-08 16:47:25 +03:00
{ORTH: "'y", LEMMA: PRON_LEMMA, NORM: "you"}],
"not've": [
{ORTH: "not", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}],
"notve": [
{ORTH: "not", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}],
"Not've": [
{ORTH: "Not", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "'ve", LEMMA: "have", TAG: "VB"}],
"Notve": [
{ORTH: "Not", LEMMA: "not", TAG: "RB"},
2017-05-08 16:47:25 +03:00
{ORTH: "ve", LEMMA: "have", TAG: "VB"}],
"cannot": [
{ORTH: "can", LEMMA: "can", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "not", LEMMA: "not", TAG: "RB"}],
"Cannot": [
{ORTH: "Can", LEMMA: "can", TAG: "MD"},
2017-05-08 16:47:25 +03:00
{ORTH: "not", LEMMA: "not", TAG: "RB"}],
"gonna": [
{ORTH: "gon", LEMMA: "go", NORM: "going"},
2017-05-08 16:47:25 +03:00
{ORTH: "na", LEMMA: "to"}],
"Gonna": [
{ORTH: "Gon", LEMMA: "go", NORM: "going"},
2017-05-08 16:47:25 +03:00
{ORTH: "na", LEMMA: "to"}],
"gotta": [
{ORTH: "got"},
2017-05-08 16:47:25 +03:00
{ORTH: "ta", LEMMA: "to"}],
"Gotta": [
{ORTH: "Got"},
2017-05-08 16:47:25 +03:00
{ORTH: "ta", LEMMA: "to"}],
"let's": [
{ORTH: "let"},
2017-05-08 16:47:25 +03:00
{ORTH: "'s", LEMMA: PRON_LEMMA, NORM: "us"}],
"Let's": [
{ORTH: "Let", LEMMA: "let"},
2017-05-08 16:47:25 +03:00
{ORTH: "'s", LEMMA: PRON_LEMMA, NORM: "us"}]
}
2017-05-08 16:47:25 +03:00
_exc.update(_other_exc)
2017-05-08 16:47:25 +03:00
for exc_data in [
{ORTH: "'S", LEMMA: "'s"},
{ORTH: "'s", LEMMA: "'s"},
{ORTH: "\u2018S", LEMMA: "'s"},
{ORTH: "\u2018s", LEMMA: "'s"},
{ORTH: "and/or", LEMMA: "and/or", TAG: "CC"},
{ORTH: "'re", LEMMA: "be", NORM: "are"},
{ORTH: "'Cause", LEMMA: "because"},
{ORTH: "'cause", LEMMA: "because"},
{ORTH: "ma'am", LEMMA: "madam"},
{ORTH: "Ma'am", LEMMA: "madam"},
{ORTH: "o'clock", LEMMA: "o'clock"},
{ORTH: "O'clock", LEMMA: "o'clock"},
{ORTH: "Mt.", LEMMA: "Mount"},
{ORTH: "Ak.", LEMMA: "Alaska"},
{ORTH: "Ala.", LEMMA: "Alabama"},
{ORTH: "Apr.", LEMMA: "April"},
{ORTH: "Ariz.", LEMMA: "Arizona"},
{ORTH: "Ark.", LEMMA: "Arkansas"},
{ORTH: "Aug.", LEMMA: "August"},
{ORTH: "Calif.", LEMMA: "California"},
{ORTH: "Colo.", LEMMA: "Colorado"},
{ORTH: "Conn.", LEMMA: "Connecticut"},
{ORTH: "Dec.", LEMMA: "December"},
{ORTH: "Del.", LEMMA: "Delaware"},
{ORTH: "Feb.", LEMMA: "February"},
{ORTH: "Fla.", LEMMA: "Florida"},
{ORTH: "Ga.", LEMMA: "Georgia"},
{ORTH: "Ia.", LEMMA: "Iowa"},
{ORTH: "Id.", LEMMA: "Idaho"},
{ORTH: "Ill.", LEMMA: "Illinois"},
{ORTH: "Ind.", LEMMA: "Indiana"},
{ORTH: "Jan.", LEMMA: "January"},
{ORTH: "Jul.", LEMMA: "July"},
{ORTH: "Jun.", LEMMA: "June"},
{ORTH: "Kan.", LEMMA: "Kansas"},
{ORTH: "Kans.", LEMMA: "Kansas"},
{ORTH: "Ky.", LEMMA: "Kentucky"},
{ORTH: "La.", LEMMA: "Louisiana"},
{ORTH: "Mar.", LEMMA: "March"},
{ORTH: "Mass.", LEMMA: "Massachusetts"},
{ORTH: "May.", LEMMA: "May"},
{ORTH: "Mich.", LEMMA: "Michigan"},
{ORTH: "Minn.", LEMMA: "Minnesota"},
{ORTH: "Miss.", LEMMA: "Mississippi"},
{ORTH: "N.C.", LEMMA: "North Carolina"},
{ORTH: "N.D.", LEMMA: "North Dakota"},
{ORTH: "N.H.", LEMMA: "New Hampshire"},
{ORTH: "N.J.", LEMMA: "New Jersey"},
{ORTH: "N.M.", LEMMA: "New Mexico"},
{ORTH: "N.Y.", LEMMA: "New York"},
{ORTH: "Neb.", LEMMA: "Nebraska"},
{ORTH: "Nebr.", LEMMA: "Nebraska"},
{ORTH: "Nev.", LEMMA: "Nevada"},
{ORTH: "Nov.", LEMMA: "November"},
{ORTH: "Oct.", LEMMA: "October"},
{ORTH: "Okla.", LEMMA: "Oklahoma"},
{ORTH: "Ore.", LEMMA: "Oregon"},
{ORTH: "Pa.", LEMMA: "Pennsylvania"},
{ORTH: "S.C.", LEMMA: "South Carolina"},
{ORTH: "Sep.", LEMMA: "September"},
{ORTH: "Sept.", LEMMA: "September"},
{ORTH: "Tenn.", LEMMA: "Tennessee"},
{ORTH: "Va.", LEMMA: "Virginia"},
{ORTH: "Wash.", LEMMA: "Washington"},
{ORTH: "Wis.", LEMMA: "Wisconsin"}]:
_exc[exc_data[ORTH]] = [dict(exc_data)]
for orth in [
"'d", "a.m.", "Adm.", "Bros.", "co.", "Co.", "Corp.", "D.C.", "Dr.", "e.g.",
"E.g.", "E.G.", "Gen.", "Gov.", "i.e.", "I.e.", "I.E.", "Inc.", "Jr.",
"Ltd.", "Md.", "Messrs.", "Mo.", "Mont.", "Mr.", "Mrs.", "Ms.", "p.m.",
"Ph.D.", "Rep.", "Rev.", "Sen.", "St.", "vs."]:
_exc[orth] = [{ORTH: orth}]
for string in _exclude:
if string in _exc:
_exc.pop(string)
TOKENIZER_EXCEPTIONS = dict(_exc)