1#![warn(missing_docs)]
22#![deny(unsafe_code)]
23#![cfg_attr(feature = "simd", feature(portable_simd))]
24
25pub mod dictionary;
26pub mod file_watcher;
27pub mod hot_reload;
28pub mod lazy_entries;
29pub mod loader;
30pub mod matrix;
31pub mod trie;
32pub mod user_dict;
33
34pub use dictionary::{DictEntry, DictionaryLoader, SystemDictionary};
35pub use error::{DictError, Result};
36pub use file_watcher::{FileEvent, FileWatcher, WatchConfig};
37pub use hot_reload::{
38 DeltaUpdate, DeltaUpdateBuilder, EntryChange, HotReloadDictionary, Version, VersionInfo,
39};
40pub use lazy_entries::LazyEntries;
41pub use loader::{LazyDictionary, LoaderConfig, MmapDictionary};
42pub use matrix::{ConnectionMatrix, DenseMatrix, Matrix, MatrixLoader, MmapMatrix, SparseMatrix};
43pub use trie::{DictionarySearcher, EntryIndex, PrefixMatch, Trie, TrieBuilder};
44pub use user_dict::{UserDictionary, UserDictionaryBuilder, UserEntry};
45
46#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct Entry {
49 pub surface: String,
51 pub left_id: u16,
53 pub right_id: u16,
55 pub cost: i16,
57 pub feature: String,
59}
60
61pub trait Dictionary {
63 fn lookup(&self, surface: &str) -> Vec<Entry>;
65
66 fn get_connection_cost(&self, left_id: u16, right_id: u16) -> i16;
68}
69
70pub mod error {
72 use thiserror::Error;
73
74 #[derive(Error, Debug)]
76 pub enum DictError {
77 #[error("IO error: {0}")]
79 Io(#[from] std::io::Error),
80
81 #[error("Invalid dictionary format: {0}")]
83 Format(String),
84
85 #[error("Version mismatch: expected {expected}, found {found}")]
87 Version {
88 expected: u32,
90 found: u32,
92 },
93 }
94
95 pub type Result<T> = std::result::Result<T, DictError>;
97}
98
99pub mod format {
103
104 pub struct Header {
106 pub magic: [u8; 4],
108 pub version: u32,
110 pub entry_count: u32,
112 }
113}
114
115#[cfg(test)]
116mod tests {
117 use super::*;
118
119 #[test]
120 fn test_entry_creation() {
121 let entry = Entry {
122 surface: "안녕".to_string(),
123 left_id: 1,
124 right_id: 1,
125 cost: 100,
126 feature: "NNG,*,T,안녕,*,*,*,*".to_string(),
127 };
128
129 assert_eq!(entry.surface, "안녕");
130 }
131}