lexf 0.1.0

Zero-unsafe multilingual morphological expander and query normalizer for search indexing
Documentation
//! Expand search tokens into normalized and stemmed forms

use lexf::{LangHint, LexConfig, Mode, Scratch, detect_lang, expand, expand_each};
use mcut::{Cut, CutMode, MCUT};

fn main() {
  // Index side: every token yields its surface form plus roots/variants
  let cfg = LexConfig::default();
  assert_eq!(expand("Cuting", cfg), ["cuting", "cut", "cute"]);
  assert_eq!(expand("數據庫", cfg), ["數據庫", "数据库"]);
  assert_eq!(expand("1,000.50", cfg), ["1,000.50", "1000.50", "1000.5"]);

  // Query side: prefix queries and exact phrases skip stemming
  let norm = LexConfig {
    mode: Mode::Norm,
    ..cfg
  };
  assert_eq!(expand("Cuting", norm), ["cuting"]);

  // Pair with mcut: detect the language once, reuse scratch buffers across tokens
  let doc = "Die Häuser und der Wald";
  let cfg = LexConfig {
    lang: detect_lang(doc),
    ..cfg
  };
  assert_eq!(cfg.lang, LangHint::De);
  let mut scratch = Scratch::new();
  for tok in MCUT.cut(doc, CutMode::Search) {
    let mut form_li = Vec::new();
    expand_each(tok.text, cfg, &mut scratch, |form| {
      form_li.push(form.to_owned())
    });
    println!("{} -> {form_li:?}", tok.text);
  }
}