lexf 0.1.0

Zero-unsafe multilingual morphological expander and query normalizer for search indexing
Documentation
//! Japanese and Korean trailing inflection/particle stripping.

use super::strip_keep;

/// Minimum chars a CJK stem must keep.
const MIN_STEM: usize = 2;

/// Japanese polite/inflectional endings, longest first among overlapping ones.
const JA_SUFFIX: &[&str] = &[
  "ませんでした",
  "ていました",
  "ています",
  "ました",
  "ません",
  "ている",
  "だった",
  "かった",
  "ます",
  "です",
  "した",
  "ない",
];

/// Korean particles (josa) and endings (eomi), longest first among overlapping ones.
const KO_SUFFIX: &[&str] = &[
  "에서부터",
  "으로부터",
  "입니다",
  "합니다",
  "하였다",
  "에서는",
  "에서도",
  "으로는",
  "에게는",
  "에게서",
  "에서",
  "으로",
  "까지",
  "부터",
  "보다",
  "처럼",
  "에게",
  "한테",
  "이나",
  "이고",
  "하며",
  "하다",
  "이다",
  "은",
  "는",
  "이",
  "가",
  "을",
  "를",
  "에",
  "의",
  "로",
  "도",
  "만",
  "과",
  "와",
];

/// Emits the Japanese stem with its polite/inflectional ending removed.
pub(crate) fn emit_ja(surface: &str, out: &mut impl FnMut(&str)) {
  if let Some(stem) = strip_keep(surface, JA_SUFFIX, MIN_STEM) {
    out(stem);
  }
}

/// Emits the Korean stem with its trailing particle/ending removed.
pub(crate) fn emit_ko(surface: &str, out: &mut impl FnMut(&str)) {
  if let Some(stem) = strip_keep(surface, KO_SUFFIX, MIN_STEM) {
    out(stem);
  }
}