Skip to content

Catalog.from_dict_of_freqs

Catalog.from_dict_of_freqs classmethod

from_dict_of_freqs(freqs: DictOfFreqs) -> Catalog

Creates a Catalog of corpora from named token-to-frequency mappings.

Example
import wordlevel as wl

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

Parameters:

Name Type Description Default

freqs

DictOfFreqs

A mapping of corpus names to token-to-frequency mappings, one per corpus. Each mapping is {corpus: {token: frequency}}, with one mapping per corpus

required

Returns:

Type Description
Catalog

A Catalog of corpora representing the provided tokens and frequencies

Raises:

Type Description
ValueError

If fewer than two corpora are provided in freqs.

ValueError

If any corpus in freqs has no token frequencies.

Source