-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve coverage and clean entry points
- Loading branch information
Showing
6 changed files
with
197 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
47 changes: 47 additions & 0 deletions
47
edsnlp/pipelines/core/normalizer/remove_lowercase/factory.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from spacy.language import Language | ||
from spacy.tokens import Doc | ||
|
||
from edsnlp.utils.deprecation import deprecated_factory | ||
|
||
|
||
def remove_lowercase(doc: Doc): | ||
""" | ||
Add case on the `NORM` custom attribute. Should always be applied first. | ||
Parameters | ||
---------- | ||
doc : Doc | ||
The spaCy `Doc` object. | ||
Returns | ||
------- | ||
Doc | ||
The document, with case put back in `NORM`. | ||
""" | ||
|
||
for token in doc: | ||
token.norm_ = token.text | ||
|
||
return doc | ||
|
||
|
||
@deprecated_factory("remove-lowercase", "eds.remove_lowercase", assigns=["token.norm"]) | ||
@deprecated_factory( | ||
"eds.remove-lowercase", "eds.remove_lowercase", assigns=["token.norm"] | ||
) | ||
@Language.factory("eds.remove_lowercase", assigns=["token.norm"]) | ||
def create_component( | ||
nlp: Language, | ||
name: str, | ||
): | ||
""" | ||
Add case on the `NORM` custom attribute. Should always be applied first. | ||
Parameters | ||
---------- | ||
nlp : Language | ||
The pipeline object. | ||
name : str | ||
The name of the component. | ||
""" | ||
return remove_lowercase # pragma: no cover |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pydantic import validate_arguments | ||
|
||
from edsnlp.pipelines.base import ( | ||
SpanGetterArg, | ||
SpanSetterArg, | ||
validate_span_getter, | ||
validate_span_setter, | ||
) | ||
|
||
|
||
def test_span_getter(): | ||
assert validate_span_getter("ents") == {"ents": True} | ||
assert validate_span_getter(["ents"]) == {"ents": True} | ||
assert validate_span_getter(["ents", "group"]) == {"ents": True, "group": True} | ||
assert validate_span_getter({"grp": True}) == {"grp": True} | ||
assert validate_span_getter({"grp": ["a", "b", "c"]}) == {"grp": ["a", "b", "c"]} | ||
|
||
|
||
def test_span_setter(): | ||
assert validate_span_setter("ents") == {"ents": True} | ||
assert validate_span_setter(["ents"]) == {"ents": True} | ||
assert validate_span_setter(["ents", "group"]) == {"ents": True, "group": True} | ||
assert validate_span_setter({"grp": True}) == {"grp": True} | ||
assert validate_span_setter({"grp": ["a", "b", "c"]}) == {"grp": ["a", "b", "c"]} | ||
|
||
|
||
def test_validate_args(): | ||
@validate_arguments | ||
def my_func(span_getter: SpanGetterArg, span_setter: SpanSetterArg): | ||
return span_getter, span_setter | ||
|
||
assert my_func("ents", "ents") == ({"ents": True}, {"ents": True}) |