Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and refactor text statistics functionality #350

Merged
merged 33 commits into from
Dec 1, 2021
Merged

Conversation

bdewilde
Copy link
Collaborator

@bdewilde bdewilde commented Nov 22, 2021

Description

  • implements a variety of text statistics measuring lexical diversity
    • ttr(): type-token-ratio, in three variations (standard, root, corrected)
    • log_ttr(): logarithmically-scaled TTR, in three variations (herdan, summer, dugast)
    • segmented_ttr(): segmented TTR, in two variations (mean, moving average)
    • mtld(): Measure of Textual Lexical Diversity, a modern and text length-agnostic measure
    • hdd(): Hypergeometric Distribution Diversity, a(nother) modern and text length-agnostic measure
  • implements functions for counting morphological, part-of-speech, and dependency annotations in a document
  • updates all text statistics functions to accept a Doc object as their first positional argument (i.e. Callable[[Doc, ...], int | float] , so they're more directly usable and accessible
    • adds caching to some functions and improves performance of .get_words() utils func to reduce overhead
  • consolidates all TextStats readability properties under a single TextStats.readability() method, where individual statistics are specified by name; similarly, adds TextStats.diversity() and .counts() methods for accessing those statistics
  • replaces TextStatsComponent custom spaCy language component with a suite of Doc property and method extensions, settable via textacy.text_stats.set_doc_extensions(); the outcome is roughly the same -- various text stats accessible via spaCy's Doc._ -- but the process is different

Motivation and Context

There are lots of use cases and methods for quantifying aspects of a document, and I wanted textacy to capture more of them. I even used something like annotation counts for a research project. Also, the text_stats functionality was clunky in many ways, and I wanted to make it easier for people to use.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation, and I have updated it accordingly.

partial factors should now be computed correctly
this lets us use these functions for Doc property/method extensions! to avoid re-computing potentially expensive operations, we cache a couple functions
I know, I overuse utils modules... but I think it's a bit nicer than importing private funcs from all over the place, or plopping them down in strange in places.
this allows us to use these functions as doc extensions, it makes them easier to call directly a la carte, it moves lang-checking into the functions that need it. only downside is a slight performance hit, but i'll take it.
@bdewilde bdewilde marked this pull request as ready for review November 30, 2021 04:01
@bdewilde bdewilde merged commit ceeb925 into develop Dec 1, 2021
@bdewilde bdewilde deleted the add-morph-stats branch December 1, 2021 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant