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

implement cutoff from the API in Counts #207

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dhlab/text/conc_coll.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ def from_df(cls, df):
class Counts(DhlabObj):
"""Provide counts for a corpus - shouldn't be too large"""

def __init__(self, corpus=None, words=None):
def __init__(self, corpus=None, words=None, cutoff=0):
"""Get frequency list for Corpus

:param corpus: target Corpus, defaults to None
:param words: list of words to be counted, defaults to None
:param cutoff: frequency cutoff, will not include words with frequency <= cutoff
"""
if corpus is None and words is None:
self.freq = pd.DataFrame()
Expand All @@ -189,7 +190,7 @@ def __init__(self, corpus=None, words=None):
# count - if words is none result will be as if counting all words
# in the corpus
self.freq = get_document_frequencies(
urns=urnlist(corpus), cutoff=0, words=words
urns=urnlist(corpus), cutoff=cutoff, words=words
)

# Include dhlab and title link in object
Expand Down
8 changes: 4 additions & 4 deletions dhlab/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def coll(
ignore_caps=ignore_caps,
)

def count(self, words=None):
def count(self, words=None, cutoff=0):
"""Get word frequencies for corpus"""
return dh.Counts(self, words)
return dh.Counts(self, words, cutoff)

def freq(self, words=None):
def freq(self, words=None, cutoff=0):
"""Get word frequencies for corpus"""
return dh.Counts(self, words)
return dh.Counts(self, words, cutoff)

@staticmethod
def _is_Corpus(corpus: "Corpus") -> bool:
Expand Down
Loading