diff options
| author | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
|---|---|---|
| committer | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
| commit | 4bc5fbef9d159e143fb7e2c3231932e6e76f667c (patch) | |
| tree | e2198f5c552e0667d838b8ec764ddb3a4d8f6dec /pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py | |
| parent | jq: fix build with structured-attrs on darwin (diff) | |
| parent | Merge pull request #123802 from superherointj/package-virtmanager-bugfix (diff) | |
| download | nixpkgs-origin/structured-attrs.tar.gz | |
Merge remote-tracking branch 'upstream/master' into structured-attrsorigin/structured-attrs
Diffstat (limited to 'pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py')
| -rw-r--r-- | pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py b/pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py new file mode 100644 index 000000000000..d0be2d1c335a --- /dev/null +++ b/pkgs/development/python-modules/spacy-transformers/annotation-test/annotate.py @@ -0,0 +1,68 @@ +import pytest +import spacy + +en_text = ( + "When Sebastian Thrun started working on self-driving cars at " + "Google in 2007, few people outside of the company took him " + "seriously. “I can tell you very senior CEOs of major American " + "car companies would shake my hand and turn away because I wasn’t " + "worth talking to,” said Thrun, in an interview with Recode earlier " + "this week.") + + +@pytest.fixture +def en_core_web_trf(): + return spacy.load("en_core_web_trf") + + +@pytest.fixture +def doc_en_core_web_trf(en_core_web_trf): + return en_core_web_trf(en_text) + + +def test_entities(doc_en_core_web_trf): + entities = list(map(lambda e: (e.text, e.label_), + doc_en_core_web_trf.ents)) + + assert entities == [ + ('Sebastian Thrun', 'PERSON'), + ('Google', 'ORG'), + ('2007', 'DATE'), + ('American', 'NORP'), + ('Thrun', 'PERSON'), + ('Recode', 'ORG'), + ('earlier this week', 'DATE'), + ] + + +def test_nouns(doc_en_core_web_trf): + assert [ + chunk.text for chunk in doc_en_core_web_trf.noun_chunks] == [ + 'Sebastian Thrun', + 'self-driving cars', + 'Google', + 'few people', + 'the company', + 'him', + 'I', + 'you', + 'very senior CEOs', + 'major American car companies', + 'my hand', + 'I', + 'Thrun', + 'an interview', + 'Recode'] + + +def test_verbs(doc_en_core_web_trf): + assert [ + token.lemma_ for token in doc_en_core_web_trf if token.pos_ == "VERB"] == [ + 'start', + 'take', + 'tell', + 'shake', + 'turn', + 'be', + 'talk', + 'say'] |
