use std::path::{Path, PathBuf};
use super::options::{runtime_paths, EngineOptions};
use crate::assets;
use crate::error::Result;
use crate::local::catalog::{self, EmojiCatalogItem, EmojiCatalogSlice, EmojiSymbolGroup};
use crate::shuangpin::hints::ShuangpinKeyHint;
use crate::types::ShuangpinProfileKind;
use crate::wubi::lookup::WubiCodeLookup;
pub fn hanzi_to_pinyin(options: &EngineOptions, text: &str) -> String {
crate::dictionary::hanzi::hanzi_to_pinyin(
&runtime_paths(options).dictionary(assets::MAIN_DICTIONARY),
text,
)
}
pub fn hanzi_to_pinyin_batch(options: &EngineOptions, texts: &[&str]) -> Vec<String> {
crate::dictionary::hanzi::hanzi_to_pinyin_batch(&main_dictionary_path(options), texts)
}
pub fn main_dictionary_path(options: &EngineOptions) -> PathBuf {
runtime_paths(options).dictionary(assets::MAIN_DICTIONARY)
}
pub fn wubi_code_lookup(options: &EngineOptions, text: &str) -> WubiCodeLookup {
let database = crate::ime::registry::wubi_database(&runtime_paths(options));
let database = if !options.wubi_dictionary.is_empty()
&& !crate::user_dictionary::generation::has_split_wubi_tables(&database).unwrap_or(false)
{
std::path::PathBuf::from(&options.wubi_dictionary)
} else {
database
};
crate::wubi::lookup::lookup_codes(&database, text)
}
pub fn normalize_full_pinyin(input: &str, expected_syllables: usize) -> String {
crate::pinyin::normalize::normalize_full_pinyin(input, expected_syllables)
}
pub fn shuangpin_key_hints(profile: &str) -> Vec<ShuangpinKeyHint> {
crate::shuangpin::hints::shuangpin_key_hints(profile)
}
pub fn shuangpin_zero_initials(profile: &str) -> Vec<(&'static str, &'static str)> {
crate::shuangpin::hints::shuangpin_zero_initials(profile)
}
pub fn is_shuangpin_syllable(syllable: &str) -> bool {
crate::shuangpin::profile::accepted_syllables().contains(syllable)
}
pub fn encode_shuangpin(pinyin: &str, profile: &str) -> Option<String> {
let profile =
ShuangpinProfileKind::from_name(profile).and_then(crate::shuangpin::profile::profile)?;
crate::shuangpin::utils::encode_pinyin(pinyin, profile)
}
pub fn shuangpin_uses_semicolon(profile: &str) -> Option<bool> {
ShuangpinProfileKind::from_name(profile)
.and_then(crate::shuangpin::profile::profile)
.map(|profile| profile.uses_semicolon_key())
}
pub fn emoji_catalog_filtered_page(
resources: &str,
search: &str,
category: &str,
group: &str,
offset: usize,
limit: u16,
parent: &str,
) -> Result<Vec<EmojiCatalogItem>> {
let slice = catalog::read_emoji_catalog_slice(
Path::new(resources),
search,
category,
group,
offset,
usize::from(limit),
parent,
true,
)?;
Ok(slice.items)
}
pub fn emoji_catalog_slice(
resources: &str,
search: &str,
category: &str,
group: &str,
offset: usize,
limit: u16,
parent: &str,
) -> Result<EmojiCatalogSlice> {
catalog::read_emoji_catalog_slice(
Path::new(resources),
search,
category,
group,
offset,
usize::from(limit),
parent,
false,
)
}
pub fn emoji_symbol_groups(resources: &str) -> Result<Vec<EmojiSymbolGroup>> {
catalog::emoji_symbol_groups(Path::new(resources))
}
pub fn emoji_catalog_groups(resources: &str, category: &str) -> Result<Vec<String>> {
catalog::emoji_catalog_groups(Path::new(resources), category)
}