Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversions for movie-related roles #274

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 70 additions & 13 deletions src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl From<&PermissiveType<i64>> for MaybeTyped<Numeric> {
}
}

fn ed_role(role: EditorType) -> Option<PersonRole> {
fn ed_role(role: EditorType, entry_type: &tex::EntryType) -> Option<PersonRole> {
match role {
EditorType::Editor => None,
EditorType::Compiler => Some(PersonRole::Compiler),
Expand All @@ -126,7 +126,25 @@ fn ed_role(role: EditorType) -> Option<PersonRole> {
EditorType::Collaborator => Some(PersonRole::Collaborator),
EditorType::Organizer => Some(PersonRole::Organizer),
EditorType::Director => Some(PersonRole::Director),
EditorType::Unknown(role) => Some(PersonRole::Unknown(role)),
EditorType::Unknown(role) => {
let other_entry_type = if let tex::EntryType::Unknown(t) = entry_type {
Some(t.to_ascii_lowercase())
} else {
None
};

match (role.to_ascii_lowercase().as_str(), other_entry_type.as_deref()) {
// See p. 26 of the biblatex-chicago manual and biblatex-apa
("producer", _) => Some(PersonRole::Producer),
// The pervasive Zotero plugin zotero-better-biblatex produces this.
("scriptwriter", _) => Some(PersonRole::Writer),
// The biblatex-apa style expects `writer` for videos.
("writer", Some("video")) => Some(PersonRole::Writer),
// See p. 26 of the biblatex-chicago manual
("none", Some("video") | Some("music")) => Some(PersonRole::CastMember),
_ => Some(PersonRole::Unknown(role)),
}
}
}
}

Expand Down Expand Up @@ -209,7 +227,7 @@ impl TryFrom<&tex::Entry> for Entry {
let mut eds: Vec<Person> = vec![];
let mut collaborators = vec![];
for (editors, role) in entry.editors()? {
let ptype = ed_role(role);
let ptype = ed_role(role, &entry.entry_type);
match ptype {
None => eds.extend(editors.iter().map(Into::into)),
Some(role) => collaborators.push(PersonsWithRoles::new(
Expand Down Expand Up @@ -586,24 +604,63 @@ fn comma_list(items: &[Vec<Spanned<Chunk>>]) -> FormatString {

#[cfg(test)]
mod tests {
use crate::types::PersonRole;

#[test]
fn test_pmid_from_biblatex() {
let entries = crate::io::from_biblatex_str(
r#"@article{test_article,
title = {Title},
volume = {3},
url = {https://example.org},
pages = {1--99},
journaltitle = {Testing Journal},
author = {Doe, Jane},
date = {2024-12},
eprint = {54678},
eprinttype = {pubmed},
}"#,
title = {Title},
volume = {3},
url = {https://example.org},
pages = {1--99},
journaltitle = {Testing Journal},
author = {Doe, Jane},
date = {2024-12},
eprint = {54678},
eprinttype = {pubmed},
}"#,
)
.unwrap();
let entry = entries.get("test_article").unwrap();
assert_eq!(Some("54678"), entry.keyed_serial_number("pmid"));
assert_eq!(Some("54678"), entry.pmid());
}

#[test]
/// See https://github.com/typst/hayagriva/issues/266
fn issue_266() {
let entries = crate::io::from_biblatex_str(
r#"@video{wachowskiMatrix1999,
type = {Action, Sci-Fi},
entrysubtype = {film},
title = {The {{Matrix}}},
editor = {Wachowski, Lana and Wachowski, Lilly},
editortype = {director},
editora = {Wachowski, Lilly and Wachowski, Lana},
editoratype = {scriptwriter},
namea = {Reeves, Keanu and Fishburne, Laurence and Moss, Carrie-Anne},
nameatype = {collaborator},
date = {1999-03-31},
publisher = {Warner Bros., Village Roadshow Pictures, Groucho Film Partnership},
abstract = {When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.},
keywords = {artificial reality,dystopia,post apocalypse,simulated reality,war with machines},
annotation = {IMDb ID: tt0133093\\
event-location: United States, Australia}
}"#,
).unwrap();

let entry = entries.get("wachowskiMatrix1999").unwrap();
assert_eq!(
Some("Lilly"),
entry
.affiliated_with_role(PersonRole::Writer)
.first()
.unwrap()
.given_name
.as_deref()
);

serde_json::to_value(entry).unwrap();
}
}