Make word lookup more verbose

master
Elnu 2 years ago
parent 3b0e75b7a1
commit 376fba6795

@ -64,6 +64,25 @@ fn broadcast_player_count(clients: &mut HashMap<u64, Responder>) {
}
}
fn lookup(input: &str) -> Option<&jisho::Entry> {
let input = input.trim();
for word in jisho::lookup(input) {
if
// If input has no kanji,
// we can just compare the input to the reading verbatim
// ensuring both are hiragana
(input.is_kana() && input.to_hiragana() == word.reading.to_hiragana()) ||
// Otherwise, we have to ensure that the input
// is verbosely the same.
// However, this will cause problems for some words.
// For example, 照り焼き will be accepted but 照焼 won't.
(input == word.kanji) {
return Some(word);
}
}
return None;
}
fn main() {
let event_hub = simple_websockets::launch(8080)
.expect("failed to listen on port 8080");
@ -102,7 +121,7 @@ fn main() {
message: String::from("It's not your turn!"),
}
} else {
match jisho::lookup(&message.trim()).iter().next() {
match lookup(&message) {
Some(entry) => {
if entry.reading.chars().last().unwrap().to_string().to_hiragana() == "ん" {
MessageResponseData::Error {

Loading…
Cancel
Save