Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Language Support Overview

Litsea supports word segmentation for four languages through a unified framework based on the Language enum.

Supported Languages

LanguageEnum VariantCLI ValuesFeature CountWord F1 (held-out)
JapaneseLanguage::Japanesejapanese, ja4296.70%
ChineseLanguage::Chinesechinese, zh4290.69%
KoreanLanguage::Koreankorean, ko3899.91%
EnglishLanguage::Englishenglish, en3898.31%

The Language Enum

#![allow(unused)]
fn main() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum Language {
    #[default]
    Japanese,
    Chinese,
    Korean,
    English,
}
}
  • Default is Japanese
  • Marked #[non_exhaustive] – new languages can be added without a breaking change, so external match expressions need a wildcard arm
  • Implements FromStr – parses from full name or ISO 639-1 code (case-insensitive)
  • Implements Display – outputs the lowercase full name

Parsing Examples

#![allow(unused)]
fn main() {
use litsea::language::Language;

let ja: Language = "japanese".parse().unwrap();
let zh: Language = "zh".parse().unwrap();
let ko: Language = "Korean".parse().unwrap();   // case-insensitive
let err = "french".parse::<Language>();          // Err(...)
}

How Languages Differ

Each language defines its own character type patterns that classify characters into type codes. These type codes are used as features for the AdaBoost classifier.

AspectJapaneseChineseKoreanEnglish
Character types8 (M, H, I, K, P, A, N, O)9 (F, C, X, R, P, B, A, N, O)10 (E, SN, SF, J, G, H, P, A, N, O)7 (U, W, Q, P, A, N, O)
WC featuresYes (4 extra)Yes (4 extra)NoNo
Total features42423838
Matching methodmatch on char rangesmatch on char rangesmatch on char ranges + codepoint testmatch on char ranges

Why Korean and English Have Fewer Features

Korean Hangul syllables are classified into only two types: SN (without 받침/final consonant) and SF (with 받침). This binary distinction means WC features (word + character-type combinations) would produce redundant information with little discriminative power. Excluding them reduces noise and keeps the model compact.

English shares the same conclusion for a related reason: the dominant boundary signal is whitespace, and a dev-split comparison measured the 38-template (no WC) tag-free model at 98.68% Word F1 versus 98.65% with all 42 templates — WC features measured worse, not just unhelpful. See English for the full comparison.