2023-06-14 18:48:41 +03:00
|
|
|
from typing import Callable, Dict, List, Optional, Tuple
|
2020-08-07 16:27:13 +03:00
|
|
|
|
|
|
|
from thinc.api import Model
|
2020-07-22 14:42:59 +03:00
|
|
|
|
2020-08-07 16:27:13 +03:00
|
|
|
from ...pipeline import Lemmatizer
|
2021-08-10 16:13:39 +03:00
|
|
|
from ...pipeline.lemmatizer import lemmatizer_score
|
2020-08-07 16:27:13 +03:00
|
|
|
from ...symbols import POS
|
|
|
|
from ...tokens import Token
|
|
|
|
from ...vocab import Vocab
|
2020-07-22 14:42:59 +03:00
|
|
|
|
|
|
|
PUNCT_RULES = {"«": '"', "»": '"'}
|
2017-11-21 11:44:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
class RussianLemmatizer(Lemmatizer):
|
2020-08-07 16:27:13 +03:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
vocab: Vocab,
|
|
|
|
model: Optional[Model],
|
|
|
|
name: str = "lemmatizer",
|
|
|
|
*,
|
2022-08-22 12:27:14 +03:00
|
|
|
mode: str = "pymorphy3",
|
2020-10-05 10:26:43 +03:00
|
|
|
overwrite: bool = False,
|
2021-08-10 16:13:39 +03:00
|
|
|
scorer: Optional[Callable] = lemmatizer_score,
|
2020-08-07 16:27:13 +03:00
|
|
|
) -> None:
|
2022-10-12 13:18:39 +03:00
|
|
|
if mode in {"pymorphy2", "pymorphy2_lookup"}:
|
2021-06-11 11:19:22 +03:00
|
|
|
try:
|
|
|
|
from pymorphy2 import MorphAnalyzer
|
|
|
|
except ImportError:
|
|
|
|
raise ImportError(
|
2022-11-25 13:12:46 +03:00
|
|
|
"The lemmatizer mode 'pymorphy2' requires the "
|
|
|
|
"pymorphy2 library and dictionaries. Install them with: "
|
|
|
|
"pip install pymorphy2"
|
|
|
|
"# for Ukrainian dictionaries:"
|
|
|
|
"pip install pymorphy2-dicts-uk"
|
2021-06-11 11:19:22 +03:00
|
|
|
) from None
|
2021-07-09 16:36:56 +03:00
|
|
|
if getattr(self, "_morph", None) is None:
|
2022-11-25 13:12:46 +03:00
|
|
|
self._morph = MorphAnalyzer(lang="ru")
|
|
|
|
elif mode in {"pymorphy3", "pymorphy3_lookup"}:
|
2022-08-22 12:27:14 +03:00
|
|
|
try:
|
|
|
|
from pymorphy3 import MorphAnalyzer
|
|
|
|
except ImportError:
|
|
|
|
raise ImportError(
|
2022-11-25 13:12:46 +03:00
|
|
|
"The lemmatizer mode 'pymorphy3' requires the "
|
|
|
|
"pymorphy3 library and dictionaries. Install them with: "
|
|
|
|
"pip install pymorphy3"
|
|
|
|
"# for Ukrainian dictionaries:"
|
|
|
|
"pip install pymorphy3-dicts-uk"
|
2022-08-22 12:27:14 +03:00
|
|
|
) from None
|
|
|
|
if getattr(self, "_morph", None) is None:
|
2022-11-25 13:12:46 +03:00
|
|
|
self._morph = MorphAnalyzer(lang="ru")
|
2021-11-05 11:56:26 +03:00
|
|
|
super().__init__(
|
|
|
|
vocab, model, name, mode=mode, overwrite=overwrite, scorer=scorer
|
|
|
|
)
|
2017-11-21 11:44:46 +03:00
|
|
|
|
2022-11-25 13:12:46 +03:00
|
|
|
def _pymorphy_lemmatize(self, token: Token) -> List[str]:
|
2020-08-07 16:27:13 +03:00
|
|
|
string = token.text
|
|
|
|
univ_pos = token.pos_
|
|
|
|
morphology = token.morph.to_dict()
|
💫 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
|
|
|
if univ_pos == "PUNCT":
|
2017-11-26 20:54:48 +03:00
|
|
|
return [PUNCT_RULES.get(string, string)]
|
💫 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
|
|
|
if univ_pos not in ("ADJ", "DET", "NOUN", "NUM", "PRON", "PROPN", "VERB"):
|
2022-11-25 13:12:46 +03:00
|
|
|
return self._pymorphy_lookup_lemmatize(token)
|
2017-11-21 11:44:46 +03:00
|
|
|
analyses = self._morph.parse(string)
|
|
|
|
filtered_analyses = []
|
|
|
|
for analysis in analyses:
|
|
|
|
if not analysis.is_known:
|
|
|
|
# Skip suggested parse variant for unknown word for pymorphy
|
|
|
|
continue
|
|
|
|
analysis_pos, _ = oc2ud(str(analysis.tag))
|
2022-11-25 13:12:46 +03:00
|
|
|
if (
|
|
|
|
analysis_pos == univ_pos
|
|
|
|
or (analysis_pos in ("NOUN", "PROPN") and univ_pos in ("NOUN", "PROPN"))
|
|
|
|
or ((analysis_pos == "PRON") and (univ_pos == "DET"))
|
💫 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
|
|
|
):
|
2017-11-21 11:44:46 +03:00
|
|
|
filtered_analyses.append(analysis)
|
|
|
|
if not len(filtered_analyses):
|
|
|
|
return [string.lower()]
|
2017-11-26 20:54:48 +03:00
|
|
|
if morphology is None or (len(morphology) == 1 and POS in morphology):
|
2021-10-15 12:36:49 +03:00
|
|
|
return list(
|
|
|
|
dict.fromkeys([analysis.normal_form for analysis in filtered_analyses])
|
|
|
|
)
|
💫 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
|
|
|
if univ_pos in ("ADJ", "DET", "NOUN", "PROPN"):
|
|
|
|
features_to_compare = ["Case", "Number", "Gender"]
|
|
|
|
elif univ_pos == "NUM":
|
|
|
|
features_to_compare = ["Case", "Gender"]
|
|
|
|
elif univ_pos == "PRON":
|
|
|
|
features_to_compare = ["Case", "Number", "Gender", "Person"]
|
2017-11-21 11:44:46 +03:00
|
|
|
else: # VERB
|
💫 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
|
|
|
features_to_compare = [
|
|
|
|
"Aspect",
|
|
|
|
"Gender",
|
|
|
|
"Mood",
|
|
|
|
"Number",
|
|
|
|
"Tense",
|
|
|
|
"VerbForm",
|
|
|
|
"Voice",
|
|
|
|
]
|
2017-11-21 11:44:46 +03:00
|
|
|
analyses, filtered_analyses = filtered_analyses, []
|
|
|
|
for analysis in analyses:
|
|
|
|
_, analysis_morph = oc2ud(str(analysis.tag))
|
|
|
|
for feature in features_to_compare:
|
💫 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
|
|
|
if (
|
|
|
|
feature in morphology
|
|
|
|
and feature in analysis_morph
|
2019-09-27 18:56:12 +03:00
|
|
|
and morphology[feature].lower() != analysis_morph[feature].lower()
|
💫 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
|
|
|
):
|
2017-11-21 11:44:46 +03:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
filtered_analyses.append(analysis)
|
|
|
|
if not len(filtered_analyses):
|
|
|
|
return [string.lower()]
|
2021-10-15 12:36:49 +03:00
|
|
|
return list(
|
|
|
|
dict.fromkeys([analysis.normal_form for analysis in filtered_analyses])
|
|
|
|
)
|
2017-11-21 11:44:46 +03:00
|
|
|
|
2022-11-25 13:12:46 +03:00
|
|
|
def _pymorphy_lookup_lemmatize(self, token: Token) -> List[str]:
|
2020-08-07 16:27:13 +03:00
|
|
|
string = token.text
|
2017-11-21 11:44:46 +03:00
|
|
|
analyses = self._morph.parse(string)
|
2022-11-25 13:12:46 +03:00
|
|
|
# often multiple forms would derive from the same normal form
|
|
|
|
# thus check _unique_ normal forms
|
|
|
|
normal_forms = set([an.normal_form for an in analyses])
|
|
|
|
if len(normal_forms) == 1:
|
|
|
|
return [next(iter(normal_forms))]
|
2021-03-15 13:11:06 +03:00
|
|
|
return [string]
|
2017-11-21 11:44:46 +03:00
|
|
|
|
2022-11-25 13:12:46 +03:00
|
|
|
def pymorphy2_lemmatize(self, token: Token) -> List[str]:
|
|
|
|
return self._pymorphy_lemmatize(token)
|
|
|
|
|
|
|
|
def pymorphy2_lookup_lemmatize(self, token: Token) -> List[str]:
|
|
|
|
return self._pymorphy_lookup_lemmatize(token)
|
|
|
|
|
2022-08-22 12:27:14 +03:00
|
|
|
def pymorphy3_lemmatize(self, token: Token) -> List[str]:
|
2022-11-25 13:12:46 +03:00
|
|
|
return self._pymorphy_lemmatize(token)
|
|
|
|
|
|
|
|
def pymorphy3_lookup_lemmatize(self, token: Token) -> List[str]:
|
|
|
|
return self._pymorphy_lookup_lemmatize(token)
|
2022-08-22 12:27:14 +03:00
|
|
|
|
2017-11-21 11:44:46 +03:00
|
|
|
|
2020-07-22 14:42:59 +03:00
|
|
|
def oc2ud(oc_tag: str) -> Tuple[str, Dict[str, str]]:
|
2017-11-21 11:44:46 +03:00
|
|
|
gram_map = {
|
💫 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
|
|
|
"_POS": {
|
|
|
|
"ADJF": "ADJ",
|
|
|
|
"ADJS": "ADJ",
|
|
|
|
"ADVB": "ADV",
|
|
|
|
"Apro": "DET",
|
|
|
|
"COMP": "ADJ", # Can also be an ADV - unchangeable
|
|
|
|
"CONJ": "CCONJ", # Can also be a SCONJ - both unchangeable ones
|
|
|
|
"GRND": "VERB",
|
|
|
|
"INFN": "VERB",
|
|
|
|
"INTJ": "INTJ",
|
|
|
|
"NOUN": "NOUN",
|
|
|
|
"NPRO": "PRON",
|
|
|
|
"NUMR": "NUM",
|
|
|
|
"NUMB": "NUM",
|
|
|
|
"PNCT": "PUNCT",
|
|
|
|
"PRCL": "PART",
|
|
|
|
"PREP": "ADP",
|
|
|
|
"PRTF": "VERB",
|
|
|
|
"PRTS": "VERB",
|
|
|
|
"VERB": "VERB",
|
2017-11-21 11:44:46 +03:00
|
|
|
},
|
💫 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
|
|
|
"Animacy": {"anim": "Anim", "inan": "Inan"},
|
|
|
|
"Aspect": {"impf": "Imp", "perf": "Perf"},
|
|
|
|
"Case": {
|
|
|
|
"ablt": "Ins",
|
|
|
|
"accs": "Acc",
|
|
|
|
"datv": "Dat",
|
|
|
|
"gen1": "Gen",
|
|
|
|
"gen2": "Gen",
|
|
|
|
"gent": "Gen",
|
|
|
|
"loc2": "Loc",
|
|
|
|
"loct": "Loc",
|
|
|
|
"nomn": "Nom",
|
|
|
|
"voct": "Voc",
|
2017-11-21 11:44:46 +03:00
|
|
|
},
|
💫 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
|
|
|
"Degree": {"COMP": "Cmp", "Supr": "Sup"},
|
|
|
|
"Gender": {"femn": "Fem", "masc": "Masc", "neut": "Neut"},
|
|
|
|
"Mood": {"impr": "Imp", "indc": "Ind"},
|
|
|
|
"Number": {"plur": "Plur", "sing": "Sing"},
|
|
|
|
"NumForm": {"NUMB": "Digit"},
|
|
|
|
"Person": {"1per": "1", "2per": "2", "3per": "3", "excl": "2", "incl": "1"},
|
|
|
|
"Tense": {"futr": "Fut", "past": "Past", "pres": "Pres"},
|
|
|
|
"Variant": {"ADJS": "Brev", "PRTS": "Brev"},
|
|
|
|
"VerbForm": {
|
|
|
|
"GRND": "Conv",
|
|
|
|
"INFN": "Inf",
|
|
|
|
"PRTF": "Part",
|
|
|
|
"PRTS": "Part",
|
|
|
|
"VERB": "Fin",
|
2017-11-21 11:44:46 +03:00
|
|
|
},
|
💫 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
|
|
|
"Voice": {"actv": "Act", "pssv": "Pass"},
|
|
|
|
"Abbr": {"Abbr": "Yes"},
|
2017-11-21 11:44:46 +03:00
|
|
|
}
|
💫 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
|
|
|
pos = "X"
|
2017-11-21 11:44:46 +03:00
|
|
|
morphology = dict()
|
|
|
|
unmatched = set()
|
💫 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
|
|
|
grams = oc_tag.replace(" ", ",").split(",")
|
2017-11-21 11:44:46 +03:00
|
|
|
for gram in grams:
|
|
|
|
match = False
|
|
|
|
for categ, gmap in sorted(gram_map.items()):
|
|
|
|
if gram in gmap:
|
|
|
|
match = True
|
💫 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
|
|
|
if categ == "_POS":
|
2017-11-21 11:44:46 +03:00
|
|
|
pos = gmap[gram]
|
|
|
|
else:
|
|
|
|
morphology[categ] = gmap[gram]
|
|
|
|
if not match:
|
|
|
|
unmatched.add(gram)
|
|
|
|
while len(unmatched) > 0:
|
|
|
|
gram = unmatched.pop()
|
💫 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
|
|
|
if gram in ("Name", "Patr", "Surn", "Geox", "Orgn"):
|
|
|
|
pos = "PROPN"
|
|
|
|
elif gram == "Auxt":
|
|
|
|
pos = "AUX"
|
|
|
|
elif gram == "Pltm":
|
|
|
|
morphology["Number"] = "Ptan"
|
2017-11-21 11:44:46 +03:00
|
|
|
return pos, morphology
|