Skip to content

Commit

Permalink
Merge branch 'master' into Update_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
HLasse authored Apr 5, 2022
2 parents 06fb4f7 + de0ba76 commit 3ad0267
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 120 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Configuration: https://dependabot.com/docs/config-file/
# Docs: https://docs.github.com/en/github/administering-a-repository/keeping-your-dependencies-updated-automatically

version: 2

updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
commit-message:
prefix: ":arrow_up:"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
commit-message:
prefix: ":arrow_up:"
42 changes: 33 additions & 9 deletions .github/workflows/pytest-cov-comment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: CI Pytest
on:
push:
Expand All @@ -8,9 +7,34 @@ on:

jobs:
pytest:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
python-version: ['3.9', '3.8', '3.7']
exclude:
- os: ubuntu-latest
python-version: '3.9'

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
pip install -r requirements.txt
- name: Run and write pytest
run: |
echo "[run]\nomit =\n\ttextdescriptives/tests/*" > .coveragerc
python -m pytest --cov=textdescriptives --cov-config=.coveragerc --cov-report term-missing | tee pytest-coverage.txt
pytest-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
Expand All @@ -20,26 +44,26 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -r requirements.txt
- name: Run and write pytest
run: |
python ./dev/pytest-coverage/run_coverage.py
echo "[run]\nomit =\n\ttextdescriptives/tests/*" > .coveragerc
python -m pytest --cov=textdescriptives --cov-config=.coveragerc --cov-report term-missing | tee pytest-coverage.txt
- name: Pytest coverage comment
id: coverage-comment
uses: MishaKav/pytest-coverage-comment@v1.0
uses: MishaKav/pytest-coverage-comment@v1.1.17
with:
pytest-coverage-path: ./dev/pytest-coverage/pytest-coverage.txt
pytest-coverage-path: ./pytest-coverage.txt

- name: Check the output coverage
run: |
echo "Coverage Report - ${{ steps.coverage-comment.outputs.coverage }}"
echo "Coverage Color - ${{ steps.coverage-comment.outputs.color }}"
- name: Create the Badge
uses: schneegans/dynamic-badges-action@v1.0.0
uses: schneegans/dynamic-badges-action@v1.1.0
with:
auth: ${{ secrets.PYTEST_COVERAGE }}
gistID: 24ee79064ca9d49616cbc410da65cee2
gistID: 4ee79064ca9d49616cbc410da65cee2
filename: badge-textdescriptives-pytest-coverage.json
label: Coverage
message: ${{ steps.coverage-comment.outputs.coverage }}
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/pytest_mac_catalina.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/pytest_windows.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![github actions pytest](https://github.com/hlasse/textdescriptives/actions/workflows/pytest-cov-comment.yml/badge.svg)](https://github.com/hlasse/textdescriptives/actions)
[![github actions docs](https://github.com/hlasse/textdescriptives/actions/workflows/documentation.yml/badge.svg)](https://hlasse.github.io/TextDescriptives/)
![github coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/hlasse/24ee79064ca9d49616cbc410da65cee2/raw/badge-textdescriptives-pytest-coverage.json)
[![DOI](https://zenodo.org/badge/236710916.svg)](https://zenodo.org/badge/latestdoi/236710916)



Expand Down
Empty file removed dev/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions dev/pytest-coverage/.coveragerc

This file was deleted.

33 changes: 0 additions & 33 deletions dev/pytest-coverage/run_coverage.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pandas>=1.0.0,<1.5.0
pyphen>=0.11.0,<0.12.0
ftfy>=6.0.3,<6.1.0
https://huggingface.co/spacy/en_core_web_sm/resolve/main/en_core_web_sm-any-py3-none-any.whl
en_core_web_sm==3.1.0
en_core_web_sm==3.2.0
13 changes: 6 additions & 7 deletions textdescriptives/tests/test_dependency_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_dependency_distance_edge(text, expected, nlp):
assert pytest.approx(expected, rel=1e-2) == v



@pytest.mark.parametrize(
"text,expected",
[
Expand All @@ -54,7 +53,7 @@ def test_mean_dep_distance(text, expected, nlp):
text = " ".join(text.split())
doc = nlp(text)
assert (
pytest.approx(expected, rel=1e-2)
pytest.approx(expected, rel=0.15)
== doc._.dependency_distance["dependency_distance_mean"]
)

Expand All @@ -72,7 +71,7 @@ def test_std_dep_distance(text, expected, nlp):
text = " ".join(text.split())
doc = nlp(text)
assert (
pytest.approx(expected, rel=1e-2)
pytest.approx(expected, rel=0.15)
== doc._.dependency_distance["dependency_distance_std"]
)

Expand All @@ -90,16 +89,16 @@ def test_mean_adj_dep(text, expected, nlp):
text = " ".join(text.split())
doc = nlp(text)
assert (
pytest.approx(expected, rel=1e-2)
pytest.approx(expected, rel=0.1)
== doc._.dependency_distance["prop_adjacent_dependency_relation_mean"]
)


@pytest.mark.parametrize(
"text,expected",
[
(oliver_twist, 0.094),
(secret_garden, 0.107),
(oliver_twist, 0.11),
(secret_garden, 0.09),
(flatland, 0.056),
],
)
Expand All @@ -108,6 +107,6 @@ def test_std_adj_dep(text, expected, nlp):
text = " ".join(text.split())
doc = nlp(text)
assert (
pytest.approx(expected, rel=1e-2)
pytest.approx(expected, rel=0.1)
== doc._.dependency_distance["prop_adjacent_dependency_relation_std"]
)
110 changes: 97 additions & 13 deletions textdescriptives/tests/test_pos_stats.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,115 @@
import spacy
from spacy.tokens import Doc
from spacy.lang.en import English
import pytest
from textdescriptives.components import POSStatistics


@pytest.fixture(scope="function")
def nlp():
nlp = spacy.load("en_core_web_sm", disable=('ner', 'textcat'))
nlp = spacy.load("en_core_web_sm", disable=("ner", "textcat"))
nlp.add_pipe("pos_stats")

return nlp

def test_pos_integrations(nlp):
assert "pos_stats" == nlp.pipe_names[-1]

def test_pos_proportions_doc(nlp):
doc = nlp(
"Here is the first sentence. It was pretty short. Let's make another one that's slightly longer and more complex."
@pytest.fixture(scope="function")
def doc(nlp):
words = [
"Here",
"is",
"the",
"first",
"sentence",
".",
"It",
"was",
"pretty",
"short",
".",
"Let",
"'s",
"make",
"another",
"one",
"that",
"'s",
"slightly",
"longer",
"and",
"more",
"complex",
".",
]
pos = [
"ADV",
"AUX",
"DET",
"ADJ",
"NOUN",
"PUNCT",
"PRON",
"AUX",
"ADV",
"ADJ",
"PUNCT",
"VERB",
"PRON",
"VERB",
"DET",
"NOUN",
"PRON",
"AUX",
"ADV",
"ADJ",
"CCONJ",
"ADV",
"ADJ",
"PUNCT",
]
doc = Doc(
nlp.vocab,
words=words,
pos=pos,
)
return doc


def test_pos_integrations(nlp):
assert "pos_stats" == nlp.pipe_names[-1]

assert doc._.pos_proportions == pytest.approx({'pos_prop_ADV': 0.1666, 'pos_prop_AUX': 0.0833, 'pos_prop_DET': 0.125, 'pos_prop_ADJ': 0.1666, 'pos_prop_NOUN': 0.0833, 'pos_prop_PUNCT': 0.125, 'pos_prop_PRON': 0.0833, 'pos_prop_VERB': 0.125, 'pos_prop_CCONJ': 0.0416}, rel=1e-2)

def test_pos_proportions_span(nlp):
doc = nlp(
"Here is the first sentence. It was pretty short. Let's make another one that's slightly longer and more complex."
def test_pos_proportions_doc(doc):
assert doc._.pos_proportions == pytest.approx(
{
"pos_prop_ADV": 0.1666,
"pos_prop_AUX": 0.125,
"pos_prop_DET": 0.083,
"pos_prop_ADJ": 0.1666,
"pos_prop_NOUN": 0.0833,
"pos_prop_PUNCT": 0.125,
"pos_prop_PRON": 0.125,
"pos_prop_VERB": 0.083,
"pos_prop_CCONJ": 0.0416,
},
rel=0.05,
)

span = doc[0:]

assert doc._.pos_proportions == pytest.approx({'pos_prop_ADV': 0.1666, 'pos_prop_AUX': 0.0833, 'pos_prop_DET': 0.125, 'pos_prop_ADJ': 0.1666, 'pos_prop_NOUN': 0.0833, 'pos_prop_PUNCT': 0.125, 'pos_prop_PRON': 0.0833, 'pos_prop_VERB': 0.125, 'pos_prop_CCONJ': 0.0416}, rel=1e-2)

def test_pos_proportions_span(doc):
span = doc[:]

assert span._.pos_proportions == pytest.approx(
{
"pos_prop_ADV": 0.1666,
"pos_prop_AUX": 0.125,
"pos_prop_DET": 0.083,
"pos_prop_ADJ": 0.1666,
"pos_prop_NOUN": 0.0833,
"pos_prop_PUNCT": 0.125,
"pos_prop_PRON": 0.125,
"pos_prop_VERB": 0.083,
"pos_prop_CCONJ": 0.0416,
},
rel=0.01,
)

0 comments on commit 3ad0267

Please sign in to comment.