Skip to content

Language profiles

AutoMiner’s pipeline is mostly language agnostic: sources, downloads, subtitle pools, sync, clip cutting, scoring, the Queue and Anki delivery do not care what language a sentence is in. A small set of layers do. This document names those layers, the contract they implement, and the order in which they move behind it.

core/autominer/lang/ holds one LanguageProfile per target language. The pipeline asks the profile for the media it is working on:

from autominer import lang
profile = lang.get(media["lang"]) # never None
profile.has_native_script(text) # "is this text in the language?"
profile.fold_reading(reading) # comparison form of a reading
profile.matches_tag("ja-JP") # container/feed language tags
  • lang.studied() is the languages the install studies, first = primary: the AUTOMINER_LANG environment setting (ja, es), else the mine.lang settings row (Settings › 言語 › 学習中の言語: a checklist of the languages core offers, GET /v1/languages / lang.offered, ordered with ↑↓, those with no mining layer under 取得のみの言語), else the built-in lang.DEFAULT_CODE (ja). lang.default_code() is the primary one. A part must name a language the install knows (a registered profile or lang.KNOWN; english → en): the Settings PUT refuses any other with 400, and the parser drops one an environment value carries (#1278).

  • lang.detect(tags, texts) decides a media’s language at fetch time and the fetch writes it to media.lang: the first studied language a source tag names, else (no tag at all) one whose script a studied profile sees in the titles, else the primary. It also returns the non-studied language a source names, so the source can skip it. What each source asks:

    Source Tags Off-list
    YouTube (fetch_yt) yt-dlp’s audio language (asked only when the skip is on or 2+ languages are studied); title script skipped with 学習中の言語の動画だけマイニング ON, else the primary
    Podcasts / Spotify (fetch_rss) the feed’s <language>, else Spotify’s episode languages (media.source_langs); show and episode titles’ script always skipped (NonJapanesePodcast): the transcript is paid for; a pressed show is decided by its titles (else heard)
    Stremio (fetch_stremio) the downloaded file’s audio stream tags (assets.audio_languages) a language the install names and does not mine (media_actions.fetch_only: an HK film’s yue is Cantonese) is stored and fetched only; another, the primary and the subtitle gate decides

    When two or more languages are studied and neither tags nor titles name one (lang.told), YouTube (after the video download), podcasts (after the episode download; a show already transcribed keeps its language) and Stremio (an untagged file) hear it: probe_asr.heard_language sends one 30 s window from the middle to the cloud recognizer told no language (Scribe’s language_code, OpenAI’s language), metered like every read. A one-language install never asks. A heard language that is not studied but that the install names and does not mine (Cantonese) is stored as heard, so the source is fetched only, never mined as the primary.

    A Chinese (zh) source whose speech is Cantonese is refiled yue (media_actions.refile_cantonese, never over a person’s language): its lines are written Cantonese (zh.written_cantonese: a tenth of them carry 嘅 咗 喺 唔 冇 佢 哋 啲 嚟 乜), checked by every mine and 再計算, or — on a Stremio fetch whose audio tags say no more than Chinese (chi, zho, zh-HK, untagged: most Hong Kong releases) and whose lines are Traditional (zh.traditional), or that has no subtitles (before its transcript is paid for) — the heard probe answers yue (Scribe’s code for Cantonese; every other read is told the media’s language, so none answers this for free). A file is heard once: the answer is kept per media and file (probe_asr.HEARD_KEY, name and size) until another file comes or a person sets the language. Its untouched mined cards go to the trash as on a person’s change (retire_mined): a yue mine is skipped, nothing would replace them.

    Capture records a first guess the fetch replaces: the adapters and ReVanced the primary, Spotify’s phone adapter the studied language its episode languages name (else the primary); the extension sends none (media.lang NULL reads as the primary).

  • A person corrects a source’s language (Sources’ header, every source’s, the sync screen beside 字幕を再取得, or Today’s 取得のみ row): PUT /v1/media/{id}/lang, refused with 400 for a language the install cannot name. It answers at once and queues the change as a job (media.lang, media_actions.change_lang), which the pages follow: the cards move, the language is stored with media.lang_source = 'person' (after the cards that go, so each trash record keeps the language its card was mined in), and the source is fetched again — unless it brings back cards whose lines it still has, or had kept (media_actions.keep_lines / lines_back, a subtitle-cache snapshot per language): then nothing is fetched or bought again, and a change and its way back leave the source as it was. Queued fetches, transcriptions and mines of the language it leaves are called off; a busy database or a restart runs the change again whole. Cards back with another language’s dictionary entry are enriched again. Every fetch keeps a person’s language (media_actions.set_detected_lang) and asks nothing to detect it (no feed refusal, no heard probe).

  • A source in a language with no mining layer is fetched only (取得のみ): its mine job settles skipped naming the language (「スペイン語はマイニング 対象外 (取得のみ)」) and queues no enrichment, and no transcript is paid for it (asr.handle_asr, YouTube’s auto captions) and no podcast episode is downloaded (fetch_rss.resolve_and_fetch ends skipped with the same message). A mined source a person switches to such a language sends the mined cards a 再計算 would replace and nobody touched to the trash (media_actions.retire_mined, through clipmanager.delete_clips, so Audit › クリップ can restore them); cards made by hand, edited, decided or sent stay. The page asks first with the count (PUT …/lang?dry_run=true), and the answer’s retired says how many go (#1311). Their trash records say so (by: "lang"); switching back to a mined language restores exactly those, before any re-fetch (media_actions.lang_retired_ids, restored in the dry run and the answer), never a card the person deleted by hand. One whose trash was emptied comes back owed a cut.

  • lang.get(code) returns the registered profile, or a generic, script-less profile for a language with no layer, named from lang.KNOWN (“Spanish”, spa) when the code is listed there. An unregistered language runs the agnostic pipeline; it is never processed with Japanese rules.

  • A profile is data first (codes, aliases, script ranges) with a few overridable methods. A language without a special script needs no subclass.

How a language’s text is put together. The base values fit a spaced, .-punctuated language, so a new one (Korean, Spanish) needs none of them — Korean sets none; a load, a transcript or a read with no language follows Japanese’s (segments.text_profile).

Field Base (ko) ja zh Read by
word_separator " " "" "" Scribe’s words into a cue (asr.cues_from_scribe_words), a Whisper probe’s text, joined subtitle lines and stored rows read back (ParseRules.sep, segments.derive_cues/separator), a wrapped cue’s line break under the default filter row (mine.LINE_BREAK_FILTER: Hello⏎world is Hello world, a Japanese cue’s break still goes), the editor’s 前の文を追加 (the preview’s word_separator)
sentence_terminals 。!?!?. 。!?!? 。!?!? a Scribe cue closes on one (a . of ... never); segments.terminal_re adds the closers every language shares (… 」 ) ── ~ ...) for carries_on, joins_on, stacked — anchored at the line’s end, so 3.5 ends nothing
join_commas () 、 , 、 segments.joins_on, sentence_parts
reading_bracket None (compared as written) kana in […] after kanji pinyin in […] after Han push.spells
reading_label None (ふりがな / 振り仮名, the UI’s default) ふりがな ピンイン duplicates.field_words, the editor’s reading boxes and 上書き confirm (the preview’s reading_label)
subtitle_query_tags None (its code) — zh-cn,zh-tw opensubtitles.search (API_LANGUAGES keeps pt, which has no profile)

Japanese-specific layers (inventory at ee9f1243)

Section titled “Japanese-specific layers (inventory at ee9f1243)”
Layer Where today Phase
Script detection: kana/kanji ranges, reading folds lang/ja.py; tokenize, yomitan, known, mining/aggregate delegate 1 (done)
Default language of new media lang.DEFAULT_CODE, read by every fetcher/adapter 1 (done)
Feed language tags profile.matches_tag (fetch_rss.is_japanese) 1 (done)
Track-language gate (“is this track in the language?”) profile.track_gate(cues) — extract_subs.is_japanese asks it; None = not gated 2 (done)
Title script hint (feed titles) profile.text_language_hint(*texts) 2 (done)
Tokenizer + target gate (fugashi/UniDic, POS, counters, katakana retarget, 1-char rules) profile.tagger() / profile.mining → tokenize.py; mine_media skips a media whose profile has no mining layer 3 (done)
Card reading, sentence/word furigana profile.display_reading / sentence_furigana / word_furigana → yomitan.py; push asks the profile 4 (done)
Known-word cache key folding known.normalize_reading via ja.katakana_to_hiragana 4 (done)
Subtitle providers that serve one language each provider’s SERVES; subpool.serves(kind, lang) skips a source for a language it has none of (not_served) 5 (done)
LLM prompts naming the language the media’s profile.english_name (gemini.translate_prompt, linejoin.state, judge.window_plan) 5 (done)
ASR language codes the media’s profile.iso639_3 (Scribe, mining and 判定’s reads); AM_PROBE_ASR_LANG blank = the media’s code 5 (done)
判定’s subtitle gate and readings profile.judge_usable(cues) (None = not gated) and profile.tagger() in evidence.candidate / evidence.reading 6 (done)
Known-word harvest known.studied: the install’s language and every media’s; a word is kept in any of them 6 (done)
Known words per language each note’s language (known.note_lang, below) on known_word, known_word_note and anki_note (lang, NULL = every language); a mine, a recount and the editor know only the media’s language’s words; Today’s 既知語 counts each studied language 7 (done)
Duplicates and the editor’s furigana duplicates reads a note’s word in every known.studied language, and offers a card only its media’s language’s notes (lookup/outside lang=, automine’s duplicate status); /v1/furigana and a DIFFERS check read the card’s media’s 6 (done)

Which language a note’s words are known in

Section titled “Which language a note’s words are known in”

known.note_lang reads the note’s own word, reading and sentence fields — never its deck or note type, which are named by the person and name no language:

  • a studied language can have the note when the fields carry its word script and none it never writes (profile.rules_out: kana is no Chinese or Korean note’s, Hangul no Japanese or Chinese one’s; kanji alone stay Japanese);
  • of those, the one whose own script the fields carry (profile.text_language_hint is True): kana → Japanese; a Han character Japanese never writes (这, 们: not in cp932) → Chinese; else the only one;
  • else every studied language (NULL): Han both write (学生 alone, 時間). An ambiguous note stays known in each language it could be, so nothing becomes unknown by mistake. A word held by notes of two languages is known in those two (known._own_keys); the hand-kept CSV is its own language’s;
  • none can (a Japanese collection read by a Chinese learner, Latin alone for ja·zh·ko): the note is no language’s (“”) — its words are not known, and Audit lists no finding of it (QA 2026-11-02).

A Japanese note 学生 with its reading がくせい is Japanese, so the Chinese 学生 stays a word to mine. The columns were back-filled to the primary studied language when added; adding a language makes the next read a whole one (duplicates.last_synced), which reads every note’s language again — as does a read from before READING_RULE 2 in an install keeping two languages’ words or Chinese. | Dual-audio stream heard | assets.audio_map(path, lang), handed the media’s lang by the track, the clip, 判定’s windows and their read identity | 6 (done) | | Dictionary enrichment (Yomitan) | yomitan.py is dictionary-server bound, not language bound: Yomitan serves whatever dictionaries are installed | n/a | | UI copy (Japanese UI) | core/static | separate i18n track, not a language profile | | Content markup | a media’s sentence, word and source title carry lang (none for ja: the page’s own); a definition carries none — it is in its dictionary’s gloss language, which nothing records (Yomitan’s answer names no dictionary; a local zip’s lang is its headwords’) | done |

  • tokenize.py’s content rules (UniDic POS names, counters, katakana runs, okurigana) ARE the Japanese mining layer. A second language gets its own module and names it from its profile’s mining.
  • clipscore vocalisation (grunt_only) tests kana: a line in another script is never a grunt, so it needs no profile yet.
  • kiku’s inflected bold reads the Japanese tagger unless the card’s language’s mining layer says where its word is said (said_span: Korean); Chinese needs none (its words are not inflected).
  • The judge’s line-join question (linejoin) is asked only of a pair the language’s grammar proposes (profile.proposes_join: Japanese’s kana check + UniDic particles and auxiliaries). A profile without one (the base: None) is asked nothing, never every unfinished pair unpruned; its 、/,-style join_commas still join. The question and its state already name the media’s language, so a profile that adds a grammar needs nothing else.
  • jev/judge window prompts are tuned on Japanese subtitle layout; the language name is the profile’s, the tuning is not.
  • Phase 1 changes no behaviour. It moves duplicated helpers into lang/ja.py and routes callers through them. Where two modules historically disagreed (aggregate’s kana set adds the U+31F0 phonetic extensions; tokenize/known add half-width katakana) both sets are kept under distinct names. Unifying them is a behaviour change for its own PR. core/tests/test_language_profiles.py holds the moved helpers to the original implementations over every BMP code point.
  • Each later phase defines the profile hook first (e.g. profile.tokenizer(), profile.track_gate(cues)), implements it for Japanese by delegation to the existing module, proves byte-identical mining on fixtures, and only then lets the pipeline call the hook.
  • The media’s lang column selects the profile for every stage after the fetch: mining, the pool, 判定, the prompts, the ASR code and what a card shows (lang.get(media["lang"])). Changing the install’s language re-labels nothing already stored: existing media keep their lang; the constants built at import time (translate.SYSTEM_PROMPT, asr.SCRIBE_LANGUAGE, …) are only the fallback for a call with no media.
  • A new profile is a LanguageProfile subclass with a mining module and register(); mine_media mines through profile.mining, so nothing in the pipeline changes. Chinese (below) is the second one, Korean the third.
Question Answer
Codes zh; Scribe zho; aliases zho chi cmn chinese mandarin 中文 汉语 漢語 (zh-Hans, zh-TW by primary subtag)
Is this text/track Chinese? ≥ 25 % CJK and < 5 % kana (reads_chinese): track gate, 判定’s judge_usable; a title with a Han character Japanese cannot write (们, 这, 习) hints Chinese; Han that Japanese also writes (東京観光) tells nothing, so the audio decides
Words jieba (jieba.posseg) on the line’s Simplified copy (OpenCC t2s, one character per character), each word cut back out as written, so 圖書館 stays one Traditional word: nouns/time/place words, idioms and fixed expressions (名詞), verbs (動詞), adjectives (形容詞), adverbs (副詞); pronouns, particles, numerals, measure words, prepositions, conjunctions are no words. Proper nouns (nr ns nt nz) sort last as in Japanese. With a local Chinese dictionary imported (CC-CEDICT), a content word jieba keeps whole that has no entry and is made wholly of dictionary words (longest first, left to right) is those words: 坐地铁 is 坐 + 地铁 (_parts; jieba’s own dictionary holds such verb + object chunks, and neither HMM=False nor cut_for_search separates them). A name is never split; without a dictionary, or with a character no entry covers, jieba’s word stands
Targets a one-character verb, adjective or adverb (是 有 去 要 会 说 好 大 最 也 都) is no card, as in Japanese (target_reject_reason, one_char_non_noun) — still one of the line’s unknown words; a one-character noun (书 猫 饭 菜) is a card
Readings pypinyin: tone-marked pinyin is the card’s reading (target_reading, word[pīn yīn] furigana per word); 判定 compares lines by toneless pinyin, so 简体/繁體 spellings of one line read alike
Known words a token’s pinyin is pinyin, not reading: the known check matches surfaces only (是/事/市 are all shì). A word known in one spelling is known in the other: the cache holds each word under its Simplified spelling too (fold_word), and a token’s lemma is its Simplified spelling. A card’s status reads the same: its known word, its note in the duplicates range and a hand-made card’s note outside it match each other spelling of its word too (automine._folded, _spellings, cached until the notes or known words change)
Frequency a word with no rank as written is ranked by its Simplified spelling (dictionaries.frequency, yomitan.frequency_rank with lang): a Traditional 學習 takes a Simplified-only list’s 学习
Grouping deinflects=False: a mine groups words by surface and never asks Yomitan for a headword (a Japanese dictionary scans 学习 as 学). The key is the Simplified spelling (fold_word, OpenCC t2s): 學習 and 学习 are one word, keyed 学习, and each card keeps the word as its line writes it (its Expression too, defined through the Simplified key: push.default_fields)
Subtitles OpenSubtitles asked for zh-cn,zh-tw (subtitle_query_tags); Jimaku/AnimeTosho serve Japanese only (the sync screen’s list asks Jimaku nothing); a file that is not UTF-8 is GB18030 (a superset of GBK) or Big5 (legacy_encodings), whichever reads most as Han (extract_subs.decode_subtitle; Japanese: cp932 as always); a stream tagged zh-TW, cmn or chi is a candidate (lang.code_of). Cantonese (yue) is its own language, fetched only
Line joins a line ending in ,or 、 joins the next (join_commas); the judge’s line-join question is not asked: no grammar proposes pairs yet (proposes_join None)
Card furigana word[pīn yīn]; a reading fixed by hand is kept (push.spells reads pinyin brackets, reading_bracket)

jieba, pypinyin and opencc-python-reimplemented (Apache-2.0) are core dependencies, imported on first use.

Question Answer
Codes ko; Scribe kor; aliases kor korean 한국어 韓国語 (ko-KR by primary subtag)
Is this text/track Korean? Hangul is at least half the letters (reads_korean): track gate, 判定’s judge_usable; 判定’s read floor counts Hangul syllables (script_chars); a title with a Hangul syllable hints Korean, kana or Han without Hangul hints not Korean, Latin tells nothing
Words Kiwi (kiwipiepy, Sejong tags, -I/-R irregular marks dropped). A word is a content morpheme through the endings (E*) attached to it in the line: its surface is the word as said (먹었어요, 갔어요, 아름다운), its lemma/base the dictionary form. Nouns NNG (名詞) and NNP (名詞, proper, sorted last); verbs VV (動詞) and adjectives VA (形容詞) as stem + 다 (먹다, 춥다, 재미있다, 돕다); a noun or root + XSV/XSA is one verb/adjective (공부해요 → 공부하다, 깨끗해요 → 깨끗하다, 걱정돼요 → 걱정되다), as a dictionary scan of the line reads it; adverbs MAG (副詞) of two syllables or more (정말 너무 매일). Never a word, so neither a target nor an unknown word holding a line above i+1: particles (J*), endings (E*), the copula (VCP/VCN), pronouns (NP), numerals (NR), dependent nouns (NNB: 것 수 씨), auxiliary verbs (VX: 싶다 주다), determiners (MM), conjunctive adverbs (MAJ), interjections (IC), a bare root (XR), affixes (XPN, XSN: 선생님 is 선생), symbols, foreign letters and Hanja (S*), and one-syllable adverbs (안 못 잘 좀 더 또 꼭 다 왜)
Readings none: Hangul is phonetic. reading_bracket and reading_label stay None; a card’s reading, ExpressionReading and furigana are empty (ExpressionFurigana is the word), SentenceFurigana is the sentence as written
Card sentence bolded where the word is said (said_span: 먹다 bolds 먹었어요), through kiku.bold_target’s lang
Grouping and keys deinflects=False, as Chinese: a word is keyed by its Kiwi dictionary form and Yomitan is never asked for a headword. Yomitan’s Korean deinflection resolves to the same stem + 다 headword, so with a Korean dictionary installed the key is Yomitan’s own; a word it lacks would otherwise be keyed by the longest prefix it has (yomitan._entry_rank prefers, never requires, the whole text: 민수 → 민), and the script-sanity net that catches that for Japanese only reads kanji keys. Yomitan still answers the card’s content: its entry for exactly the key (enrich_headword), its frequency for exactly the word; a local Korean dictionary fills both when it does not. A Korean card never waits on Yomitan to be sent
Subtitles a file that is not UTF-8 is EUC-KR (legacy_encodings cp949); OpenSubtitles is asked for ko; Jimaku/AnimeTosho serve Japanese only
Line joins none: no joining commas; a transcript’s line with no sentence end carries on with a space (the base text rules); the judge’s grammar question is Japanese-only

kiwipiepy (Apache-2.0) is a core dependency, imported on first Korean use: an abi3 wheel per platform (manylinux2014 aarch64 for a Raspberry Pi, 5.2 MB) and kiwipiepy_model (pure data: an 88 MB sdist, 109 MB installed, no compiler needed). Loaded without its typo and multi-word dictionaries it holds about 0.23 GB resident, 0.3 GB once it has tokenized (0.33 / 0.52 GB with them).

Outside lang/: the dependency (pyproject.toml), registering the profile (lang/__init__.py), the stage guard (versions.COVERED + its record), the Settings and setup copy naming the languages that mine, and two hooks: the card’s bold asks the language where its word is said (kiku.bold_target lang=, passed by push and candidates.rekey), since Korean inflects and only the Japanese tagger could find an inflected word before; and 判定’s read floor counts the language’s script (profile.script_chars, read by evidence.read_rejection), which counted kana and Han only. Everything else — fetch, subtitles, segments, the mine, enrichment, the push, known words, Audit — ran on the profile as it was.

判定 reads a Korean source as any other: its floor for a read (three characters, evidence.read_rejection) counts the media’s own script (profile.script_chars: kana and Han, Hangul for Korean), so a Korean read is no longer “too short”; a hand-changed word re-bolds through its media’s language (candidates.rekey → push._rebold); clipscore’s spoken characters count Hangul. A mining layer’s language-neutral half (the gates, the known-cache clear, the target picker) is lang/common.py, shared by zh and ko.

Yomitan is the one source of truth for a word: it decides every word’s key (the headword its card, the known-word check and the duplicates range read). Two things keep a card useful while Yomitan is away:

  • Yomitan’s answers are kept (yomitan_answer): every answer is stored and read back only when Yomitan does not answer, so a word it has resolved keeps Yomitan’s own headword (a pick is keyed and can be sent — only with the entry Yomitan gave its card, never without one). A live answer always wins and replaces the kept one; one read while Yomitan was away gives way at its next successful probe. Read and written through one connection per process, memoized, written in batches; a heartbeat (the rail’s poll, a pick’s 3 s ask) never marks Yomitan away, only a full probe does.
  • Local dictionaries (dictionaries.py, Settings › 言語, each language’s tab): Yomitan-format zips (JMdict / Jitendex, CC-CEDICT, JPDB / BCCWJ frequency lists …) imported per language and asked top down. They fill CONTENT only — while Yomitan is away, or for a word it has no entry for (a Chinese word where it has Japanese dictionaries only) — a card’s definition (yomitan_json with provisional naming the dictionary, enriched_at left empty so the next enrichment with Yomitan answering replaces it) and the frequency a mine scores with when Yomitan gives no answer. They never key a word. An import goes in one bank at a time, a few thousand rows per transaction, under a temporary title: the revision it replaces answers, whole, until the new one is in.