Add rule lower lemmatization#1
Open
jademlc wants to merge 1 commit into
Open
Conversation
YaYaB
reviewed
Sep 7, 2022
| self.cache[cache_key] = forms | ||
| return forms | ||
|
|
||
| def special_lemmatize(self, token: Token) -> List[str]: |
There was a problem hiding this comment.
should be better renaming it rule_lower_lemmatize to have something explicit
| if not forms: | ||
| forms.append(orig) | ||
| self.cache[cache_key] = forms | ||
| return forms |
There was a problem hiding this comment.
a lot of duplicate code for only the removing of
if univ_pos == "propn":
return [string]
else:
I would copy paste the rule_lemmatizer to __rule_lemmatizer_ private class with a lower argument.
# __ as prefix to define it as private
def __rule_lemmatizer__(self, token: Token, tolower: boolean = False):
...
...
if not tolower and univ_pos == "propn":
return [string]
else:
return [string.lower()]
...
...
and then create
def rule_lemmatize(self, token: Token) -> List[str]:
"""Lemmatize using a rule-based approach.
token (Token): The token to lemmatize.
RETURNS (list): The available lemmas for the string.
DOCS: https://spacy.io/api/lemmatizer#rule_lemmatize
"""
self.__rule_lemmatize__(token)
def rule_lower_lemmatize(self, token: Token) -> List[str]:
"""Lemmatize using a special approach that lowercases the whole text
token (Token): The token to lemmatize.
RETURNS (list): The available lemmas for the string.
DOCS: https://spacy.io/api/lemmatizer#rule_lower_lemmatize
"""
self.__rule_lemmatize__(token, tolower=True)
| elif self.mode == "rule": | ||
| self.lemmatize = self.rule_lemmatize | ||
| elif self.mode == "special": | ||
| self.lemmatize = self.special_lemmatize |
There was a problem hiding this comment.
elif self.mode == "rule_lower":
self.lemmatize = self.rule_lower_lemmatize
9cd5373 to
7cbb15d
Compare
The special lemmatization will lowercase the whole text, even proper nouns
7cbb15d to
5ed72c5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The special lemmatization will lowercase the whole text, even proper nouns
Description
Added a function to define a special_lemmatization that returns
text.lower()even when the token is detected as a proper nouns. This change is useful when using spaCy Matchers with noisy texts containing a lot of uppercases. This was discussed in this issue: explosion#11051Using the
speciallemmatizer, the lemma of 'CAT' will be 'cat' instead of 'CAT'.Types of change
This change is a enhancement of the lemmatizer.
Checklist