fix: French album types, add map_album type test

This commit is contained in:
ThetaDev 2022-11-03 12:47:01 +01:00
parent 57abab112f
commit 6e2ba71f33
4 changed files with 38 additions and 7 deletions

View file

@ -64,8 +64,12 @@ pub fn write_samples_to_dict(project_root: &Path) {
let mut e_langs = dict_entry.equivalent.clone();
e_langs.push(lang);
collected.get(&lang).unwrap().iter().for_each(|(t, v)| {
dict_entry.album_types.insert(v.to_lowercase(), *t);
e_langs.iter().for_each(|lang| {
collected.get(&lang).unwrap().iter().for_each(|(t, v)| {
dict_entry
.album_types
.insert(v.to_lowercase().trim().to_owned(), *t);
});
});
}

View file

@ -630,7 +630,29 @@ pub(crate) fn map_artists(artists_p: Option<TextComponents>) -> (Vec<ArtistId>,
pub(crate) fn map_album_type(txt: &str, lang: Language) -> AlbumType {
dictionary::entry(lang)
.album_types
.get(&txt.to_lowercase())
.get(txt.to_lowercase().trim())
.copied()
.unwrap_or_default()
}
#[cfg(test)]
mod tests {
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
use super::*;
#[test]
fn map_album_type_samples() {
let json_path = Path::new("testfiles/dict/album_type_samples.json");
let json_file = File::open(json_path).unwrap();
let atype_samples: BTreeMap<Language, BTreeMap<AlbumType, String>> =
serde_json::from_reader(BufReader::new(json_file)).unwrap();
atype_samples.iter().for_each(|(lang, entry)| {
entry.iter().for_each(|(album_type, txt)| {
let res = map_album_type(txt, *lang);
assert_eq!(res, *album_type, "lang: {}, txt: {}", lang, txt);
});
});
}
}

View file

@ -1886,15 +1886,18 @@ pub(crate) fn entry(lang: Language) -> Entry {
],
},
album_types: ::phf::Map {
key: 2980949210194914378,
key: 12913932095322966823,
disps: &[
(2, 0),
(0, 0),
(5, 0),
],
entries: &[
("microalbum", AlbumType::Ep),
("album", AlbumType::Album),
("émission", AlbumType::Show),
("ep", AlbumType::Ep),
("livre audio", AlbumType::Audiobook),
("émission", AlbumType::Show),
("simple", AlbumType::Single),
("ep", AlbumType::Ep),
("single", AlbumType::Single),
],
},

View file

@ -1104,6 +1104,8 @@
"album": "Album",
"ep": "Ep",
"livre audio": "Audiobook",
"microalbum": "Ep",
"simple": "Single",
"single": "Single",
"émission": "Show"
}