Skip to content

Commit ada1077

Browse files
authored
enable github ci actions pipeline (#11)
* enable github ci actions pipeline * install wordnet data
1 parent e1d0641 commit ada1077

File tree

3 files changed

+120
-17
lines changed

3 files changed

+120
-17
lines changed

.github/workflows/ci.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- 'master'
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- 'master'
13+
release:
14+
types: [published]
15+
16+
jobs:
17+
build:
18+
name: Build python package
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash -l {0}
23+
steps:
24+
- name: Checkout Code 🛎
25+
uses: actions/checkout@v2
26+
- name: Cache pip 👜
27+
uses: actions/cache@v2
28+
env:
29+
# Increase this value to reset cache if setup.cfg has not changed
30+
CACHE_NUMBER: 0
31+
with:
32+
path: ~/.cache/pip
33+
key: ${{ runner.os }}-pip-${{ env.CACHE_NUMBER }}-${{ hashFiles('setup.cfg') }}
34+
- name: Install package 🧊
35+
run: pip install .[testing]
36+
- name: Run tests 📈
37+
run: |
38+
python -m nltk.downloader wordnet
39+
python -m nltk.downloader omw
40+
pip install spacy~=2.0
41+
python -m spacy download en_core_web_sm
42+
python -m spacy download es_core_news_sm
43+
pytest tests
44+
pip install spacy~=3.0.0
45+
python -m spacy download en_core_web_sm
46+
python -m spacy download es_core_news_sm
47+
pytest tests
48+
- name: Build Package 🍟
49+
run: |
50+
pip install -U build
51+
python -m build
52+
- name: Upload package artifact
53+
uses: actions/upload-artifact@v2
54+
with:
55+
name: python-package
56+
path: dist
57+
58+
# This job will upload a Python Package using Twine when a release is created
59+
# For more information see:
60+
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
61+
deploy_release:
62+
name: Deploy Release
63+
runs-on: ubuntu-latest
64+
if: ${{ github.event_name == 'release' }}
65+
needs:
66+
- build
67+
defaults:
68+
run:
69+
shell: bash -l {0}
70+
steps:
71+
- name: Checkout Code 🛎
72+
uses: actions/checkout@v2
73+
74+
- name: Download python package
75+
uses: actions/download-artifact@v2
76+
with:
77+
name: python-package
78+
path: dist
79+
- name: Publish Package to TestPyPI 🥪
80+
uses: pypa/gh-action-pypi-publish@master
81+
with:
82+
user: __token__
83+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
84+
repository_url: https://test.pypi.org/legacy/
85+
- name: Test Installing 🍿
86+
run: pip install --index-url https://test.pypi.org/simple --no-deps spacy-wordnet==${GITHUB_REF#refs/*/v}
87+
- name: Publish Package to PyPI 🥩
88+
uses: pypa/gh-action-pypi-publish@master
89+
with:
90+
user: __token__
91+
password: ${{ secrets.PYPI_API_TOKEN }}

spacy_wordnet/wordnet_annotator.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
from spacy_wordnet.wordnet_domains import Wordnet, load_wordnet_domains
66

7-
@Language.factory("spacy_wordnet", default_config={"lang": "en"})
8-
def wordnet_annotator(nlp, name, lang: str):
9-
return WordnetAnnotator(lang=lang)
7+
try:
8+
9+
@Language.factory("spacy_wordnet", default_config={"lang": "en"})
10+
def wordnet_annotator(nlp, name, lang: str):
11+
return WordnetAnnotator(lang=lang)
12+
13+
14+
except AttributeError:
15+
pass # spacy 2.x
16+
1017

1118
class WordnetAnnotator(object):
12-
__FIELD = 'wordnet'
19+
__FIELD = "wordnet"
1320

14-
def __init__(self, lang: str = 'es'):
21+
def __init__(self, lang: str = "es"):
1522
Token.set_extension(WordnetAnnotator.__FIELD, default=None, force=True)
1623
load_wordnet_domains()
1724
self.__lang = lang

tests/test_wordnet_annotator.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@
1111

1212

1313
class WordnetAnnotatorTest(unittest.TestCase):
14-
1514
def __init__(self, *args, **kwargs):
1615

1716
super().__init__(*args, **kwargs)
1817

19-
self.nlp_en = spacy.load('en_core_web_sm')
20-
self.nlp_es = spacy.load('es_core_news_sm')
18+
self.nlp_en = spacy.load("en_core_web_sm")
19+
self.nlp_es = spacy.load("es_core_news_sm")
2120

22-
# Add wordnet component
23-
self.nlp_en.add_pipe("spacy_wordnet", config={'lang': self.nlp_en.lang})
24-
self.nlp_es.add_pipe("spacy_wordnet", config={'lang': self.nlp_es.lang})
21+
try:
22+
# Add wordnet component
23+
self.nlp_en.add_pipe("spacy_wordnet", config={"lang": self.nlp_en.lang})
24+
self.nlp_es.add_pipe("spacy_wordnet", config={"lang": self.nlp_es.lang})
25+
except TypeError: # spacy 2.x
26+
self.nlp_en.add_pipe(WordnetAnnotator(self.nlp_en.lang))
27+
self.nlp_es.add_pipe(WordnetAnnotator(self.nlp_es.lang))
2528

2629
def test_english_annotations(self):
2730

28-
token = self.nlp_en('contracts')[0]
31+
token = self.nlp_en("contracts")[0]
2932

3033
assert token._.wordnet.synsets()
3134
assert token._.wordnet.lemmas()
3235
assert token._.wordnet.wordnet_domains()
3336

3437
def test_generate_variants_from_domain_list(self):
3538

36-
economy_domains = ['finance', 'banking']
39+
economy_domains = ["finance", "banking"]
3740
enriched_sentence = []
3841

39-
sentence = self.nlp_en('I want to withdraw 5,000 euros')
42+
sentence = self.nlp_en("I want to withdraw 5,000 euros")
4043

4144
for token in sentence:
4245
synsets = token._.wordnet.wordnet_synsets_for_domain(economy_domains)
@@ -45,13 +48,15 @@ def test_generate_variants_from_domain_list(self):
4548
lemmas_for_synset = []
4649
for s in synsets:
4750
lemmas_for_synset.extend(s.lemma_names())
48-
enriched_sentence.append('({})'.format('|'.join(set(lemmas_for_synset))))
51+
enriched_sentence.append(
52+
"({})".format("|".join(set(lemmas_for_synset)))
53+
)
4954
else:
5055
enriched_sentence.append(token.text)
51-
print(' '.join(enriched_sentence))
56+
print(" ".join(enriched_sentence))
5257

5358
def test_spanish_annotations(self):
54-
token = self.nlp_es('contratos')[0]
59+
token = self.nlp_es("contratos")[0]
5560

5661
assert token._.wordnet.synsets()
5762
assert token._.wordnet.lemmas()

0 commit comments

Comments
 (0)