1#![warn(missing_docs)]
22#![deny(unsafe_code)]
23#![cfg_attr(feature = "simd", feature(portable_simd))]
24#![allow(
25 clippy::inline_always,
26 clippy::similar_names,
27 clippy::cast_precision_loss,
28 clippy::cast_possible_truncation,
29 clippy::option_if_let_else,
30 clippy::map_unwrap_or,
31 clippy::zero_sized_map_values,
32 clippy::missing_panics_doc,
33 clippy::unwrap_used
34)]
35
36pub mod dictionary;
37pub mod domain;
38pub mod entry_store;
39pub mod file_watcher;
40pub mod hot_reload;
41pub mod lazy_entries;
42pub mod loader;
43pub mod matrix;
44pub mod string_pool;
45pub mod trie;
46pub mod user_dict;
47
48#[cfg(feature = "hot-reload-v2")]
49pub mod hot_reload_v2;
50
51pub use dictionary::{DictEntry, DictionaryLoader, LoadOptions, SystemDictionary};
52pub use entry_store::{EagerStore, EntryStore, LazyStore};
53pub use error::{DictError, Result};
54pub use file_watcher::{FileEvent, FileWatcher, WatchConfig};
55pub use hot_reload::{
56 DeltaUpdate, DeltaUpdateBuilder, EntryChange, HotReloadDictionary, Version, VersionInfo,
57};
58pub use lazy_entries::LazyEntries;
59pub use loader::{LazyDictionary, LoaderConfig, MmapDictionary};
60pub use matrix::{ConnectionMatrix, DenseMatrix, Matrix, MatrixLoader, MmapMatrix, SparseMatrix};
61pub use string_pool::{ConcurrentStringPool, StringPool, StringPoolStats};
62pub use trie::{DictionarySearcher, EntryIndex, PrefixMatch, Trie, TrieBuilder};
63pub use user_dict::{UserDictionary, UserDictionaryBuilder, UserEntry};
64
65#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct Entry {
68 pub surface: String,
70 pub left_id: u16,
72 pub right_id: u16,
74 pub cost: i16,
76 pub feature: String,
78}
79
80pub trait Dictionary {
82 fn lookup(&self, surface: &str) -> Vec<Entry>;
84
85 fn get_connection_cost(&self, left_id: u16, right_id: u16) -> i16;
87}
88
89pub mod error {
91 use thiserror::Error;
92
93 #[derive(Error, Debug)]
95 pub enum DictError {
96 #[error("IO error: {0}")]
98 Io(#[from] std::io::Error),
99
100 #[error("Invalid dictionary format: {0}")]
102 Format(String),
103
104 #[error("Version mismatch: expected {expected}, found {found}")]
106 Version {
107 expected: u32,
109 found: u32,
111 },
112 }
113
114 pub type Result<T> = std::result::Result<T, DictError>;
116}
117
118pub mod format {
122
123 pub struct Header {
125 pub magic: [u8; 4],
127 pub version: u32,
129 pub entry_count: u32,
131 }
132}
133
134#[cfg(test)]
135mod tests {
136 use super::*;
137
138 #[test]
139 fn test_entry_creation() {
140 let entry = Entry {
141 surface: "안녕".to_string(),
142 left_id: 1,
143 right_id: 1,
144 cost: 100,
145 feature: "NNG,*,T,안녕,*,*,*,*".to_string(),
146 };
147
148 assert_eq!(entry.surface, "안녕");
149 }
150}