Skip to content

Catalog.from_list_of_freqs

Catalog.from_list_of_freqs classmethod

from_list_of_freqs(
    freqs: ListOfFreqs, corpora: Sequence[str] | None = None
) -> Catalog

Creates a Catalog of corpora from a sequence of token-to-frequency mappings, each representing the frequencies of tokens in a particular corpus.

Example
import wordlevel as wl

cl = wl.Catalog.from_list_of_freqs(
    [
        {"good": 12, "bad": 8, "happy": 6, "sad": 4},
        {"good": 5, "bad": 7, "happy": 3, "sad": 9},
    ],
    corpora=["before", "after"],
)

Parameters:

Name Type Description Default

freqs

ListOfFreqs

A sequence of token-to-frequency mappings, one per corpus. Each mapping is {token: frequency} for a single corpus

required

corpora

Sequence[str] | None

The names of the corpora, listed in the same order as freqs. If not provided, will default to corpus1, corpus2, etc.

None

Returns:

Type Description
Catalog

A Catalog of corpora representing the provided tokens and frequencies

Raises:

Type Description
ValueError

If freqs and corpora have different lengths.

ValueError

If fewer than two corpora are provided in freqs.

ValueError

If any corpus in freqs has no token frequencies.

Source