hsg.classes
KnownSet
hsg.classes.knownset
KnownSet
ABC for 'which characters does the learner know'.
Backends: Heisig (frame range), HSK (level cap), file (user list), anki-export (Anki deck export).
get_char_info(char)
Return backend-specific metadata for a character.
Heisig returns {frame, keyword, pinyin, frequency}. HSK returns {level}. File returns {char}. Override in subclasses.
Source code in hsg/classes/knownset.py
28 29 30 31 32 33 34 35 | |
get_known_characters()
abstractmethod
Return the full list of known characters (excluding ADDITIONAL).
Source code in hsg/classes/knownset.py
19 20 21 22 | |
get_statistics(chars)
Compute coverage statistics for a list of characters.
This is a concrete method — it only calls is_known(), so it works for any KnownSet backend.
Source code in hsg/classes/knownset.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
is_additional_character(char)
Return True if char is a non-Hanzi allowlist character.
Source code in hsg/classes/knownset.py
24 25 26 | |
is_known(char)
abstractmethod
Return True if the learner knows this character.
Source code in hsg/classes/knownset.py
14 15 16 17 | |
Heisig
hsg.classes.heisig
Heisig(frequencies_corpus, maxframe=-1)
Bases: KnownSet
KnownSet backed by Heisig Remembering the Hanzi (RSH) frame data.
Loads frame data from assets/heisig.tsv. A character is 'known' if its
frame number <= maxframe. Also provides frequency-enriched frame metadata
(keyword, pinyin, frequency rank) via the configured Frequency corpus.
Initialise with a frequency corpus name and optional frame cap (-1 = all).
Source code in hsg/classes/heisig.py
22 23 24 25 26 27 28 | |
get_char_info(char)
Return the full frame metadata dict for a character.
Source code in hsg/classes/heisig.py
69 70 71 | |
get_frame_info(char)
Alias for get_char_info (kept for backward compatibility).
Source code in hsg/classes/heisig.py
73 74 75 | |
get_known_characters()
Return known frames plus ADDITIONAL_CHARACTERS.
Source code in hsg/classes/heisig.py
61 62 63 | |
get_known_frames()
Return hanzi whose frame number <= maxframe.
Source code in hsg/classes/heisig.py
57 58 59 | |
is_known(char)
Return True if char is in the known set (frame <= maxframe or additional).
Source code in hsg/classes/heisig.py
65 66 67 | |
load_heisig()
Parse heisig.tsv into self.heisig, enriching each entry with frequency data.
Source code in hsg/classes/heisig.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
output(words, format)
Print frame data in the specified format (csv, json, tabulate).
Source code in hsg/classes/heisig.py
77 78 79 80 81 82 83 84 85 86 87 88 89 | |
set_max_frame(maxframe)
Update the frame cap after construction.
Source code in hsg/classes/heisig.py
30 31 32 | |
HSK
hsg.classes.hsk
HSK()
HSK vocabulary data reader (both HSK 2.0 old and HSK 3.0 new lists).
Loads word and character data from hsk_old.csv and hsk_new.csv. Provides level lookups for words and individual characters.
Load both HSK old and new lists.
Source code in hsg/classes/hsk.py
15 16 17 18 19 20 21 22 | |
get_hsk_new_char_level(char)
Return the HSK 3.0 level for a single character, or None.
Source code in hsg/classes/hsk.py
98 99 100 | |
get_hsk_new_chars(level=None)
Return HSK 3.0 characters at the given level (None = all).
Source code in hsg/classes/hsk.py
108 109 110 111 112 | |
get_hsk_new_word(char)
Look up a word in the HSK 3.0 list. Returns None if not found.
Source code in hsg/classes/hsk.py
64 65 66 | |
get_hsk_new_word_level(word)
Return the HSK 3.0 level for a word, or None.
Source code in hsg/classes/hsk.py
87 88 89 90 91 92 | |
get_hsk_new_words(level)
Return HSK 3.0 words at the given level (None = all levels).
Source code in hsg/classes/hsk.py
74 75 76 77 78 | |
get_hsk_old_char_level(char)
Return the HSK 2.0 level for a single character, or None.
Source code in hsg/classes/hsk.py
94 95 96 | |
get_hsk_old_chars(level=None)
Return HSK 2.0 characters at the given level (None = all).
Source code in hsg/classes/hsk.py
102 103 104 105 106 | |
get_hsk_old_word(char)
Look up a word in the HSK 2.0 list. Returns None if not found.
Source code in hsg/classes/hsk.py
60 61 62 | |
get_hsk_old_word_level(word)
Return the HSK 2.0 level for a word, or None.
Source code in hsg/classes/hsk.py
80 81 82 83 84 85 | |
get_hsk_old_words(level)
Return HSK 2.0 words at the given level (None = all levels).
Source code in hsg/classes/hsk.py
68 69 70 71 72 | |
load_new_hsk(newhskcsv)
Parse the HSK 3.0 word list into self.hsk_new.
Source code in hsg/classes/hsk.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
load_old_hsk(oldhskcsv)
Parse the HSK 2.0 word list into self.hsk_old.
Source code in hsg/classes/hsk.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
HSKKnownSet
hsg.classes.hsk_knownset
HSKKnownSet(max_level=6, use_old=False)
Bases: KnownSet
KnownSet backed by HSK levels.
A character is 'known' if its HSK new-list level <= max_level, or if it's in ADDITIONAL_CHARACTERS.
Source code in hsg/classes/hsk_knownset.py
29 30 31 32 33 | |
FileKnownSet
hsg.classes.file_knownset
FileKnownSet(filepath)
Bases: KnownSet
KnownSet backed by a user-supplied file (one character per line).
Source code in hsg/classes/file_knownset.py
10 11 12 13 14 15 16 17 | |
Frequency
hsg.classes.frequency
Frequency
ABC for character/word frequency corpora.
Backends: SubtlexCh (subtitle-based), RenMinWang (newspaper-based).
find_char(char)
abstractmethod
Look up frequency data for a single character. Returns None if not found.
Source code in hsg/classes/frequency.py
15 16 17 18 | |
find_word(word)
abstractmethod
Look up frequency data for a multi-character word. Returns None if not found.
Source code in hsg/classes/frequency.py
20 21 22 23 | |
get_most_frequent_lemmas(type='chars', num=-1, skip_known=None, only_known=None, min_length=1, sort='rank', reverse=False)
Return ranked lemmas, optionally filtered by known-set membership.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
'chars' or 'words'. |
'chars'
|
num
|
int
|
Max results (-1 = all). |
-1
|
skip_known
|
set[str] | None
|
Exclude these characters. |
None
|
only_known
|
set[str] | None
|
Include only these characters. |
None
|
min_length
|
int
|
Minimum lemma length. |
1
|
sort
|
str
|
Sort key ('rank' or 'frequency'). |
'rank'
|
reverse
|
bool
|
Descending order if True. |
False
|
Source code in hsg/classes/frequency.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
RenMinWang
hsg.classes.renminwang
RenMinWang()
Bases: Frequency
Frequency corpus based on Renminwang (People's Daily) newspaper data.
Provides character and word frequency data from the renminwang/ assets.
Load character and word frequency CSVs.
Source code in hsg/classes/renminwang.py
14 15 16 17 18 19 | |
create_dict(lemmas)
Build a lemma-to-record lookup dict from a list.
Source code in hsg/classes/renminwang.py
42 43 44 45 46 47 | |
find_char(char)
Look up frequency data for a character. Returns None if not found.
Source code in hsg/classes/renminwang.py
49 50 51 | |
find_word(word)
Look up frequency data for a word. Returns None if not found.
Source code in hsg/classes/renminwang.py
53 54 55 | |
get_most_frequent_lemmas(type='chars', num=-1, skip_known=None, only_known=None, min_length=1, sort='rank', reverse=False)
Return ranked lemmas, optionally filtered by known-set membership.
Source code in hsg/classes/renminwang.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
load_csv(csvfile)
Parse a Renminwang frequency TSV, skipping header lines.
Source code in hsg/classes/renminwang.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
SubtlexCh
hsg.classes.subtlexch
SubtlexCh()
Bases: Frequency
Frequency corpus based on SUBTLEX-CH (Chinese film subtitle) data.
Provides character and word frequency, including part-of-speech data, from the subtlex-ch/ assets. Source: https://www.ugent.be/pp/experimentele-psychologie/en/research/documents/subtlexch/
Load character, word, and word+POS frequency CSVs.
Source code in hsg/classes/subtlexch.py
90 91 92 93 94 95 96 97 | |
create_dict(lemmas)
Build a lemma-to-record lookup dict from a list.
Source code in hsg/classes/subtlexch.py
109 110 111 112 113 114 | |
find_char(char)
Look up frequency data for a character. Returns None if not found.
Source code in hsg/classes/subtlexch.py
116 117 118 | |
find_pos(word)
Return the dominant part of speech and POS frequency counts for a word.
Source code in hsg/classes/subtlexch.py
124 125 126 127 128 129 130 131 132 | |
find_word(word)
Look up frequency data for a word. Returns None if not found.
Source code in hsg/classes/subtlexch.py
120 121 122 | |
get_most_frequent_lemmas(type='chars', num=-1, skip_known=None, only_known=None, min_length=1, sort='rank', reverse=False)
Return ranked lemmas, optionally filtered by known-set membership.
Source code in hsg/classes/subtlexch.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
get_words_by_pos(pos, strict=True)
Return words matching a part-of-speech code.
Source code in hsg/classes/subtlexch.py
134 135 136 137 138 | |
load_csv(csvfile, fields)
Parse a SUBTLEX-CH CSV with the given field names.
Source code in hsg/classes/subtlexch.py
99 100 101 102 103 104 105 106 107 | |
Ccedict
hsg.classes.ccedict
Ccedict(cedictfile, frequencies_corpus)
CC-CEDICT dictionary reader with HSK and frequency enrichment.
Loads the dictionary from a cedict_ts.u8 file (or a pickled cache). Supports search by simplified characters, pinyin, or English gloss, with optional HSK-level and frequency-rank filtering/sorting.
Load the CC-CEDICT dictionary and initialise HSK + frequency backends.
Source code in hsg/classes/ccedict.py
38 39 40 41 42 43 44 45 | |
get_query_type(query)
Classify a query string as 'simplified', 'pinyin', or 'english'.
Source code in hsg/classes/ccedict.py
98 99 100 101 102 103 104 105 106 107 108 109 | |
load_dict()
Load the dictionary from pickle cache or parse the raw .u8 file.
Source code in hsg/classes/ccedict.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
output(words, format)
Print search results in the specified format (csv, json, tabulate).
Source code in hsg/classes/ccedict.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
parse_line(line)
Parse a single CC-CEDICT line and append to self.dictionary.
Source code in hsg/classes/ccedict.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
remove_surnames()
Filter out surname entries from the dictionary.
Source code in hsg/classes/ccedict.py
91 92 93 94 95 96 | |
search(query, exact, show_traditional, format, sort, reverse, max_hsk, max_results, all_results)
Search the dictionary and print results in the chosen format.
Source code in hsg/classes/ccedict.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
sort_key(value)
Return a numeric sort key for HSK level or frequency rank.
Source code in hsg/classes/ccedict.py
151 152 153 154 155 | |
QueryType
Bases: Enum
Query classification for CC-CEDICT search: simplified, pinyin, or english.
SentenceCorpus
hsg.classes.sentencecorpus
SentenceCorpus
ABC for sentence corpora (Tatoeba, CC-CEDICT examples, etc.).
find_random_sentences(number, min_length=10, known_chars=None, reverse=False)
Find random sentences of minimum length, optionally filtered.
Source code in hsg/classes/sentencecorpus.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
find_sentences(keyword, known_chars=None, max_sentences=10000, reverse=False)
Find sentences containing keyword, optionally filtered by known set.
Source code in hsg/classes/sentencecorpus.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
load()
abstractmethod
Load sentences into a {hanzi: [translations]} dict.
Source code in hsg/classes/sentencecorpus.py
9 10 11 12 | |
TatoebaCorpus
hsg.classes.tatoeba_corpus
TatoebaCorpus(filepath)
Bases: SentenceCorpus
SentenceCorpus backed by Tatoeba TSV.
Source code in hsg/classes/tatoeba_corpus.py
9 10 11 | |
StoryStore
hsg.classes.stories
StoryStore(filepath)
Disk-based story store. Reads stories from a JSON file.
JSON format: {"
Load stories from the JSON file at filepath.
Source code in hsg/classes/stories.py
31 32 33 34 35 | |
get_story(hanzi)
Return the story entry for hanzi, with HTML tags stripped. None if not found.
Source code in hsg/classes/stories.py
42 43 44 45 46 47 48 49 50 | |
Factories
create_known_set
hsg.classes.knownset_factory
create_known_set(backend, *, max=-1, frequencies_corpus='subtlexch', filepath=None, **kwargs)
Create a KnownSet instance by backend name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
'heisig', 'hsk', or 'file'. |
required |
max
|
int
|
Frame limit (heisig) or HSK level cap (hsk). -1 = all. |
-1
|
frequencies_corpus
|
str
|
Frequency corpus for heisig backend. |
'subtlexch'
|
filepath
|
str | None
|
Path to known-characters file (required for 'file'). |
None
|
Source code in hsg/classes/knownset_factory.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
create_frequency
hsg.classes.frequency_factory
create_frequency(corpus)
Create a Frequency instance by corpus name.
Source code in hsg/classes/frequency_factory.py
4 5 6 7 8 9 10 11 12 13 14 | |