|
|
@ -4,7 +4,7 @@ use std::str::FromStr;
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
use serde_yaml::Value;
|
|
|
|
use serde_yaml::Value;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::kyujitai::{Kyujitai, self};
|
|
|
|
use crate::kyujitai::Kyujitai;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct Challenge {
|
|
|
|
pub struct Challenge {
|
|
|
@ -46,22 +46,16 @@ impl<'de> Deserialize<'de> for ChallengeWord {
|
|
|
|
));
|
|
|
|
));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let text = map.get("text").map(|value| match value {
|
|
|
|
let text = map.get("text").map(|value| match value {
|
|
|
|
Value::String(string) => vec![Furigana::new(
|
|
|
|
Value::String(string) => vec![Furigana::new(string.clone(), None)],
|
|
|
|
string.clone(),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
)],
|
|
|
|
|
|
|
|
Value::Sequence(sequence) => sequence
|
|
|
|
Value::Sequence(sequence) => sequence
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|value| match value {
|
|
|
|
.map(|value| match value {
|
|
|
|
Value::String(kanji) => Furigana::new(
|
|
|
|
Value::String(kanji) => Furigana::new(kanji.to_owned(), None),
|
|
|
|
kanji.to_owned(),
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
Value::Mapping(mapping) => {
|
|
|
|
Value::Mapping(mapping) => {
|
|
|
|
let (kanji, furigana) = mapping.iter().next().unwrap();
|
|
|
|
let (kanji, furigana) = mapping.iter().next().unwrap();
|
|
|
|
Furigana::new(
|
|
|
|
Furigana::new(
|
|
|
|
kanji.as_str().unwrap().to_owned(),
|
|
|
|
kanji.as_str().unwrap().to_owned(),
|
|
|
|
Some(furigana.as_str().unwrap().to_owned())
|
|
|
|
Some(furigana.as_str().unwrap().to_owned()),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => panic!(),
|
|
|
|
_ => panic!(),
|
|
|
@ -79,7 +73,12 @@ impl<'de> Deserialize<'de> for ChallengeWord {
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
_ => panic!("dictionary must be string!"),
|
|
|
|
_ => panic!("dictionary must be string!"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
None => text.as_ref().map(|furigana| furigana.iter().map(|segment| segment.kanji.clone()).collect()),
|
|
|
|
None => text.as_ref().map(|furigana| {
|
|
|
|
|
|
|
|
furigana
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|segment| segment.kanji.clone())
|
|
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let pos: Option<PartOfSpeech> = map
|
|
|
|
let pos: Option<PartOfSpeech> = map
|
|
|
|
.get("pos")
|
|
|
|
.get("pos")
|
|
|
|