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 author roles to JATS #10153

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Add author roles to JATS #10153

wants to merge 18 commits into from

Conversation

cthoyt
Copy link

@cthoyt cthoyt commented Sep 4, 2024

Closes #10152

This PR adds support for annotating author roles using the Contribution Role Taxonomy (CRediT).

I'm motivated to add this to Pandoc since I want the Journal of Open Source Software (JOSS), which is built on top of Pandoc, to be able to create compliant JATS. We're already adding support for encoding this information in article metadata in parallel in openjournals/inara#75.

Example input markdown / output JATS XML

Example input markdown file:

---
title: CRediT Test
author:
  - name: John Batman
    roles:
      - type: software
        degree: lead
      - type: methodology
        degree: lead
  - name: Jim Batman
    roles:
      - type: software
        degree: supporting
---

# Body

This file tests CRediT annotations.

Example output JATS file:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.2 20190208//EN"
        "JATS-publishing1.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2"
         article-type="other">
    <front>
        <article-meta>
            <title-group>
                <article-title>
                    CRediT Test
                </article-title>
            </title-group>
            <contrib-group>
                <contrib contrib-type="author">
                    <name>
                        <surname>Batman</surname>
                        <given-names>John</given-names>
                    </name>
                    <role vocab="credit"
                          vocab-identifier="https://credit.niso.org/"
                          vocab-term-identifier="https://credit.niso.org/contributor-roles/software/"
                          vocab-term="Software"
                          degree-contribution="Lead"
                    >
                        Software
                    </role>
                    <role vocab="credit"
                          vocab-identifier="https://credit.niso.org/"
                          vocab-term-identifier="https://credit.niso.org/contributor-roles/methodology/"
                          vocab-term="Methodology"
                          degree-contribution="Lead"
                    >
                        Methodology
                    </role>
                </contrib>
                <contrib contrib-type="author">
                    <name>
                        <surname>Batman</surname>
                        <given-names>Jim</given-names>
                    </name>
                    <role vocab="credit"
                          vocab-identifier="https://credit.niso.org/"
                          vocab-term-identifier="https://credit.niso.org/contributor-roles/software/"
                          vocab-term="Software"
                          degree-contribution="Supporting"
                    >
                        Software
                    </role>
                </contrib>
            </contrib-group>
        </article-meta>
    </front>
    <body>
        <sec id="body">
            <title>Body</title>
            <p>This file tests CRediT annotations.</p>
        </sec>
    </body>
</article>

@jgm
Copy link
Owner

jgm commented Sep 5, 2024

You should add a "command test" to test the proposed feature, and to illustrate how it works.

See test/command/*.md for examples.

@cthoyt
Copy link
Author

cthoyt commented Sep 24, 2024

Hi @jgm , I think I figured out making a test file. I have a few questions I bet you could answer very quickly but would take me a long time to figure out:

  1. Is there a specific naming convention I should use for my test command file?
  2. I created a Credit.hs that contains a dictionary that I want to inject into the JATS output process. Where should I look to do that? you can see in the diff what I am currently trying in the JATS writer

@jgm
Copy link
Owner

jgm commented Sep 24, 2024

Is there a specific naming convention I should use for my test command file?

Usually we try to name them after the associated issue. So, if there's an open issue that this fixes you could use that number; otherwise you could use the PR's number, 10153.md. That makes it easy to figure out later why the test was added.

I created a Credit.hs that contains a dictionary that I want to inject into the JATS output process. Where should I look to do that? you can see in the diff what I am currently trying in the JATS writer

Instead of creating a separate module, I'd prefer if you just included this map in the JATS writer module itself.

@cthoyt
Copy link
Author

cthoyt commented Sep 24, 2024

@jgm thanks for that feedback, I addressed both of your points. Now, the only thing left is how to make this dictionary (renamed to creditNames) available inside the template article.jats_publishing.

My first try was $ defField "creditNames" creditNames because this group is also where some other things that appear in the template are referenced, but I am unfortunately not familiar with Haskell and this is a very complex codebase! Any help appreciated :)

https://github.com/cthoyt/pandoc/blob/71d53c6e2635ab23929287a94087bb50ee56b79b/src/Text/Pandoc/Writers/JATS.hs#L183

@jgm
Copy link
Owner

jgm commented Sep 24, 2024

My first try was $ defField "creditNames" creditNames

what happens when you try that?

By the way, our usual convention for variable names would favor credit-names.

@cthoyt
Copy link
Author

cthoyt commented Sep 24, 2024

It seems the issue was the definition of creditNames :: M.Map String String - it didn't seem to have a way to handle strings and gave this error:

src/Text/Pandoc/Writers/JATS.hs:182:17: error: [GHC-39999]
    • Could not deduce ‘Text.DocTemplates.Internal.ToContext
                          Text (M.Map String String)’
        arising from a use of ‘defField’
      from the context: PandocMonad m
        bound by the type signature for:
                   docToJATS :: forall (m :: * -> *).
                                PandocMonad m =>
                                WriterOptions -> Pandoc -> JATS m Text
        at src/Text/Pandoc/Writers/JATS.hs:124:1-68

Switching the signature to use Text instead of String in creditNames :: M.Map Text Text and finally got it to compile, but it seems like the Text values in the dictionary don't get displayed in the template and instead only evaluate to true. Is there either:

  1. A way to add handling for regular dictionaries
  2. Unpack the Pandoc Text to be a regular string inside the template?

@jgm
Copy link
Owner

jgm commented Sep 24, 2024

I don't understand why you'd be getting this behavior. Nested Maps seem to work fine in ToContext: here I explore using cabal repl in jgm/doctemplates:

ghci> toContext $ fromList [("a"::Text, fromList [("b"::Text, fromList [("c"::Text,"d"::Text)])])] :: Context Text
Context {unContext = fromList [("a",MapVal (Context {unContext = fromList [("b",MapVal (Context {unContext = fromList [("c",SimpleVal (Text 1 "d"))]}))]}))]}
ghci> Right (tpl :: Template Text) <- compileTemplate "." "$a.b.c$" 
ghci> renderTemplate tpl context
Text 1 "d"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for CRediT roles in JATS export
2 participants