-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable Language.pipe() execution * Refactor tests * Bump version
- Loading branch information
1 parent
ed5288a
commit 3610350
Showing
6 changed files
with
120 additions
and
70 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
import tempfile | ||
|
||
import pytest | ||
import spacy | ||
|
||
from spacy_udpipe import UDPipeModel, download, load | ||
|
||
EN = "en" | ||
RO = "ro" | ||
SPACY_VERSION = "2.2.4" | ||
|
||
|
||
@pytest.fixture | ||
def lang() -> str: | ||
return EN | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def download_lang(lang: str) -> None: | ||
download(lang=lang) | ||
|
||
|
||
def test_serialization(lang: str) -> None: | ||
with tempfile.TemporaryDirectory() as tdir: | ||
nlp = load(lang=lang) | ||
nlp.to_disk(tdir) | ||
|
||
udpipe_model = UDPipeModel(lang=lang) | ||
nlp = spacy.load(tdir, udpipe_model=udpipe_model) | ||
|
||
|
||
def test_pipe(lang: str) -> None: | ||
nlp = load(lang=lang) | ||
assert nlp._meta["lang"] == f"udpipe_{lang}" | ||
|
||
text = "spacy-udpipe package now support multiprocess execution." | ||
doc = nlp(text) | ||
|
||
texts = [text for _ in range(10)] | ||
docs = list(nlp.pipe(texts, n_process=-1)) | ||
|
||
assert len(docs) == len(texts) | ||
assert docs[0].to_json() == doc.to_json() | ||
|
||
|
||
def test_morph_exception() -> None: | ||
assert spacy.__version__ <= SPACY_VERSION | ||
|
||
lang = RO | ||
text = "Ce mai faci?" | ||
|
||
download(lang=lang) | ||
|
||
try: | ||
nlp = load(lang=lang) | ||
assert nlp._meta["lang"] == f"udpipe_{lang}" | ||
doc = nlp(text) | ||
except ValueError: | ||
nlp = load(lang=lang, ignore_tag_map=True) | ||
assert nlp._meta["lang"] == f"udpipe_{lang}" | ||
doc = nlp(text) | ||
|
||
assert doc |