-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor make_sentence_span_getter -> make_span_context_getter
- Loading branch information
Showing
4 changed files
with
173 additions
and
17 deletions.
There are no files selected for viewing
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
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,64 @@ | ||
import edsnlp | ||
from edsnlp.utils.span_getters import make_span_context_getter | ||
|
||
|
||
def test_span_sentence_getter(lang): | ||
nlp = edsnlp.blank("eds") | ||
nlp.add_pipe("eds.normalizer") | ||
nlp.add_pipe("eds.sentences") | ||
nlp.add_pipe("eds.matcher", config={"terms": {"sentence": "sentence"}}) | ||
doc = nlp( | ||
"This is a sentence. " | ||
"This is another sentence. " | ||
"This is a third one. " | ||
"Last sentence." | ||
) | ||
|
||
span_getter = make_span_context_getter( | ||
span_getter=["ents"], | ||
context_words=2, | ||
overlap_policy="merge", | ||
) | ||
spans = span_getter(doc) | ||
assert [s.text for s in spans] == [ | ||
"This is a sentence. This is another sentence. This", | ||
". Last sentence.", | ||
] | ||
|
||
span_getter = make_span_context_getter( | ||
span_getter=["ents"], | ||
context_words=2, | ||
overlap_policy="filter", | ||
) | ||
spans = span_getter(doc) | ||
assert [s.text for s in spans] == [ | ||
"This is a sentence. This", | ||
". Last sentence.", | ||
] | ||
|
||
span_getter = make_span_context_getter( | ||
span_getter=["ents"], | ||
context_words=0, | ||
context_sents=1, | ||
overlap_policy="filter", | ||
) | ||
spans = span_getter(doc) | ||
assert [s.text for s in spans] == [ | ||
"This is a sentence.", | ||
"This is another sentence.", | ||
"Last sentence.", | ||
] | ||
|
||
span_getter = make_span_context_getter( | ||
span_getter=["ents"], | ||
context_words=0, | ||
context_sents=2, | ||
overlap_policy="merge", | ||
) | ||
spans = span_getter(doc) | ||
assert [s.text for s in spans] == [ | ||
( | ||
"This is a sentence. This is another sentence. " | ||
"This is a third one. Last sentence." | ||
) | ||
] |