Skip to content

Commit

Permalink
fix: add verbose flag to descriptive statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
HLasse committed Oct 12, 2023
1 parent 6d6130a commit 83980f3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/textdescriptives/components/descriptive_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class DescriptiveStatistics:
counts of tokens and sentences.
"""

def __init__(self, nlp: Language):
def __init__(self, nlp: Language, verbose: bool):
"""Initialise components."""
self.can_calculate_syllables = language_exists_in_pyphen(lang=nlp.lang)
if not self.can_calculate_syllables:
if not self.can_calculate_syllables and verbose:
msg.warn(
f"Could not load syllable counter for language {nlp.lang}. "
+ "The following extensions will be set to np.nan: "
Expand Down Expand Up @@ -188,10 +188,12 @@ def __call__(self, doc):
"span._.counts",
"span._.descriptive_stats",
],
default_config={"verbose": True},
)
def create_descriptive_stats_component(
nlp: Language,
name: str,
verbose: bool,
) -> Callable[[Doc], Doc]:
"""Allows DescriptiveStatistics to be added to a spaCy pipe using
nlp.add_pipe("textdescriptives/descriptive_stats").
Expand Down Expand Up @@ -233,5 +235,4 @@ def create_descriptive_stats_component(
sentencizers = {"sentencizer", "parser"}
if not sentencizers.intersection(set(nlp.pipe_names)):
nlp.add_pipe("sentencizer") # add a sentencizer if not one in pipe
return DescriptiveStatistics(nlp)
return DescriptiveStatistics(nlp)
return DescriptiveStatistics(nlp, verbose=verbose)

0 comments on commit 83980f3

Please sign in to comment.