diff --git a/src/somef/export/json_export.py b/src/somef/export/json_export.py index 85dc6cf1..98714867 100644 --- a/src/somef/export/json_export.py +++ b/src/somef/export/json_export.py @@ -482,10 +482,10 @@ def format_date(date_string): author_list = [] for author in authors: - family_name = author.get("family-names") - given_name = author.get("given-names") + family_name = author.get(constants.PROP_FAMILY_NAME) + given_name = author.get(constants.PROP_GIVEN_NAME) orcid = author.get("orcid") - name = author.get("name") + name = author.get(constants.PROP_NAME) if family_name and given_name: author_entry = { @@ -806,12 +806,11 @@ def parse_contributors(raw): def is_scholarly_article(article_dict): - if article_dict.get("type") in ["SoftwareApplication", "software"]: - return False - + if article_dict.get("doi") or article_dict.get("journal"): return True - + if article_dict.get("type") in ["SoftwareApplication", "software"]: + return False if article_dict.get("type") == "ScholarlyArticle": return True diff --git a/src/somef/test/test_codemeta_export.py b/src/somef/test/test_codemeta_export.py index dd557adf..0d0a1a54 100644 --- a/src/somef/test/test_codemeta_export.py +++ b/src/somef/test/test_codemeta_export.py @@ -812,6 +812,51 @@ def test_author_organization_issue_983(self): assert author.get("email") == "sunpy@googlegroups.com", f"Expected email 'sunpy@googlegroups.com', got: {author.get('email')}" os.remove(output_path) + + + def test_codemeta_sunpy_reference_publication(self): + """ + Checks that a CITATION.cff with DOI, title and structured authors is exported as + referencePublication (not creditText) in codemeta, and that individual authors + are considered Person with familyName/givenName rather than @type Organization. + """ + output_path = test_data_path + 'test_codemeta_sunpy_refpub.json' + + somef_cli.run_cli(threshold=0.9, + ignore_classifiers=False, + repo_url=None, + doc_src=None, + local_repo=test_data_repositories + "sunpy", + in_file=None, + output=None, + graph_out=None, + graph_format="turtle", + codemeta_out=output_path, + pretty=True, + missing=False, + requirements_mode="all") + + with open(output_path, "r") as f: + json_content = json.load(f) + + ref_pub = json_content.get(constants.CAT_CODEMETA_REFERENCEPUBLICATION, []) + # print(f"Reference publications: {ref_pub}") + assert len(ref_pub) > 0, "Expected referencePublication entries" + assert ref_pub[0].get("@type") == "ScholarlyArticle" + + found_person = False + for pub in ref_pub: + for author in pub.get("author", []): + if author.get("@type") == "Person": + assert "familyName" in author + assert "givenName" in author + found_person = True + + assert found_person, "No Person-type author found with familyName/givenName" + + os.remove(output_path) + + @classmethod def tearDownClass(cls): """delete temp file JSON just if all the test pass""" diff --git a/src/somef/test/test_data/repositories/sunpy/CITATION.cff b/src/somef/test/test_data/repositories/sunpy/CITATION.cff new file mode 100644 index 00000000..51695fb8 --- /dev/null +++ b/src/somef/test/test_data/repositories/sunpy/CITATION.cff @@ -0,0 +1,79 @@ +cff-version: '1.1.0' +message: 'Please cite the following work when using this software.' +authors: + - name: 'The SunPy Community' + - family-names: 'Barnes' + given-names: 'Will T.' + - family-names: 'Bobra' + given-names: 'Monica G.' + - family-names: 'Christe' + given-names: 'Steven D.' + - family-names: 'Freij' + given-names: 'Nabil' + - family-names: 'Hayes' + given-names: 'Laura A.' + - family-names: 'Ireland' + given-names: 'Jack' + - family-names: 'Mumford' + given-names: 'Stuart' + - family-names: 'Perez-Suarez' + given-names: 'David' + - family-names: 'Ryan' + given-names: 'Daniel F.' + - family-names: 'Shih' + given-names: 'Albert Y.' + - family-names: 'Chanda' + given-names: 'Prateek' + - family-names: 'Glogowski' + given-names: 'Kolja' + - family-names: 'Hewett' + given-names: 'Russell' + - family-names: 'Hughitt' + given-names: 'V. Keith' + - family-names: 'Hill' + given-names: 'Andrew' + - family-names: 'Hiware' + given-names: 'Kaustubh' + - family-names: 'Inglis' + given-names: 'Andrew' + - family-names: 'Kirk' + given-names: 'Michael S. F.' + - family-names: 'Konge' + given-names: 'Sudarshan' + - family-names: 'Mason' + given-names: 'James Paul' + - family-names: 'Maloney' + given-names: 'Shane Anthony' + - family-names: 'Murray' + given-names: 'Sophie A.' + - family-names: 'Panda' + given-names: 'Asish' + - family-names: 'Park' + given-names: 'Jongyeob' + - family-names: 'Pereira' + given-names: 'Tiago M. D.' + - family-names: 'Reardon' + given-names: 'Kevin' + - family-names: 'Savage' + given-names: 'Sabrina' + - family-names: 'Sipőcz' + given-names: 'Brigitta M.' + - family-names: 'Stansby' + given-names: 'David' + - family-names: 'Jain' + given-names: 'Yash' + - family-names: 'Taylor' + given-names: 'Garrison' + - family-names: 'Yadav' + given-names: 'Tannmay' + - family-names: 'Rajul' + - family-names: 'Dang' + given-names: 'Trung Kien' +doi: '10.3847/1538-4357/ab4f7a' +identifiers: + - type: 'doi' + value: '10.3847/1538-4357/ab4f7a' + - type: 'url' + value: 'https://iopscience.iop.org/article/10.3847/1538-4357/ab4f7a' +title: 'The SunPy Project: Open Source Development and Status of the Version 1.0 Core Package' +url: 'https://iopscience.iop.org/article/10.3847/1538-4357/ab4f7a' \ No newline at end of file