Skip to content

Commit

Permalink
fix: Fixed erros in test due by forcing the extension to be set.
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethEnevoldsen committed Sep 25, 2022
1 parent b70f850 commit b47d602
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions textdescriptives/components/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def top_ngram_chr_fraction(
count = count_span["count"]
if count >= min_count:
# calculate the fraction of the top n-gram
top_ngram_chr_frac[n] = len(ngram) / chr_len
top_ngram_chr_frac[n] = (len(ngram) * count) / chr_len
else:
top_ngram_chr_frac[n] = 0.0

Expand Down Expand Up @@ -465,9 +465,9 @@ def set_extensions(self):
doc_getter = span_getter_to_doc_getter(span_getter)

if not Span.has_extension(ext_name) or self.force is True:
Span.set_extension(ext_name, getter=span_getter)
Span.set_extension(ext_name, getter=span_getter, force=True)
if not Doc.has_extension(ext_name) or self.force is True:
Doc.set_extension(ext_name, getter=doc_getter)
Doc.set_extension(ext_name, getter=doc_getter, force=True)


@Language.factory(
Expand Down
11 changes: 8 additions & 3 deletions textdescriptives/tests/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_top_ngram_chr_fraction(

def test_quality_component(nlp: spacy.Language):
"""Test the quality component."""
nlp.add_pipe("quality")
nlp.add_pipe("quality", config={"force": True})
doc = nlp("This is a test. This is a test. This is a test.")
assert doc._.quality["n_stop_words"] == 9
assert doc._.quality["mean_word_length"] == 2.4
Expand Down Expand Up @@ -211,7 +211,12 @@ def test_quality_component_with_config(nlp: spacy.Language):
"contains_lorem ipsum": False,
}
d = nlp.add_pipe(
"quality", config={"symbols": ["."], "quality_thresholds": quality_thresholds}
"quality",
config={
"symbols": ["."],
"quality_thresholds": quality_thresholds,
"force": True,
},
)

doc = nlp("This is a test. This is a test. This is a test.")
Expand Down Expand Up @@ -246,6 +251,6 @@ def test_quality_component_with_config(nlp: spacy.Language):
)
def test_passed_quality_check(text: str, passed: bool, nlp: spacy.Language):
"""Test the passed_quality_check attribute."""
nlp.add_pipe("quality")
nlp.add_pipe("quality", config={"force": True})
doc = nlp(text)
assert doc._.passed_quality_check == passed

0 comments on commit b47d602

Please sign in to comment.