Add basic query searching

This commit is contained in:
FrankAlbella 2023-09-13 22:58:12 -04:00
parent ffe5dfdc28
commit d1644a29a6
3 changed files with 165 additions and 2 deletions

114
Cargo.lock generated
View File

@ -2,6 +2,120 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "cdict"
version = "0.1.0"
dependencies = [
"chinese_dictionary",
]
[[package]]
name = "character_converter"
version = "2.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14eb54f15451a7095181d32b3ac148ba3684ab8dc261a74208b2063c9293bb1c"
dependencies = [
"bincode",
"fst",
"once_cell",
]
[[package]]
name = "chinese_detection"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "364a0f5b5da896edd6b3507a8ed7821aedb624feb29948cde9d4d30d07b95209"
dependencies = [
"bincode",
"once_cell",
]
[[package]]
name = "chinese_dictionary"
version = "2.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a0bd724e1e6217757c912df24fe3926566ca25545685a6f1e283b6b19f52af"
dependencies = [
"bincode",
"character_converter",
"chinese_detection",
"once_cell",
"serde",
"serde_derive",
]
[[package]]
name = "fst"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab85b9b05e3978cc9a9cf8fea7f01b494e1a09ed3037e16ba39edc7a29eb61a"
[[package]]
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "proc-macro2"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "2.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

View File

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chinese_dictionary = "2.1.4"

View File

@ -1,3 +1,51 @@
fn main() {
println!("Hello, world!");
use chinese_dictionary as dictionary;
fn print_wordentry(word_entry: &dictionary::WordEntry) {
println!("{} ({})", word_entry.simplified, word_entry.traditional);
println!("{}", word_entry.pinyin_marks);
let mut it = word_entry.english.iter().peekable();
while let Some(def) = it.next() {
print!("{}", def);
if it.peek().is_none() {
println!();
} else {
print!(" / ")
}
}
let mut it = word_entry.measure_words.iter().peekable();
while let Some(mw) = it.next() {
print!("{}", mw.simplified);
if it.peek().is_none() {
println!();
} else {
print!(" / ")
}
}
}
fn print_usage(bin: &String) {
println!("Usage: {} <query>", bin);
}
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() == 1 {
print_usage(&args[0]);
std::process::exit(1);
}
let results = dictionary::query(&args[1]).unwrap();
if results.len() > 0 {
print_wordentry(&results[0]);
} else {
println!("No results found!")
}
}