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

Added option to export in CFF (Citation File Format) #10917

Merged
merged 11 commits into from
Feb 27, 2024
Merged

Added option to export in CFF (Citation File Format) #10917

merged 11 commits into from
Feb 27, 2024

Conversation

jeanprbt
Copy link
Contributor

@jeanprbt jeanprbt commented Feb 25, 2024

This PR adds the possibility to export BibEntries in CFF format, as requested in #10661. It supports several entries per .cff file, but I don't know if this is permitted by the CFF format. This is hard to solve since the export process in the code is intended for several entries. Also, since the CFF format is primarily intended for pieces of software, this exporter uses credit redirection with the line preferred-citation to specify another type of document.
The fields supported are entry type, author's name, abstract, DOI, volume and URL.

The date is quite complicated since CFF forces date to be of the form "yyyy-mm-dd". This causes problems if only month and year are specified, i.e. 2021-03. It can be solved using a DateFormatter specifically for the CFF exporter and using a default day number, but I did not know if that was necessary, hence I did not implement this.

Documentation is not up-to-date, CFF as export format must be documented.

article new_entry success result

Closes #10661

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@Siedlerchr
Copy link
Member

Thanks for the contribution!

For date, you could checkout the dateformatter, howeer I don't know how it behaves with missing info. Maybe you can add some more test strings for that (DateFormatterTest)

DateFormatter : formats a date. With no argument, the date is given in ISO-format (yyyy-MM-dd), which is also the expected format of the input. The argument may contain yyyy, MM, and dd in any combination. For example \format[DateFormatter(MM/yyyy)]{\date} will output 07/2016 if the date field contains 2016-07-15.

https://docs.jabref.org/collaborative-work/export/customexports

@jeanprbt
Copy link
Contributor Author

I fixed the date and implemented this field when exporting to CFF.
Now, when a date contains year, month and day, it is displayed as following :

date-released: yyyy-mm-dd

It it only contains month and year, it is displayed as follows :

 month: mm
 year: yyyy

It is only contains year, it is displayed as follows:

year: yyyy

Finally, if it is poorly formatted, is is displayed as follows:

issue-date: <date-as-is>

This allows not to invent a day and adapt the format to acceptable CFF fields if day or month are missing. Hope you're happy with that !

article result

Siedlerchr
Siedlerchr previously approved these changes Feb 26, 2024
Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, I'm okay with the pragmatic date approach

@Siedlerchr
Copy link
Member

A bit out of scope, but if you ever need to parse more complicated date formats you can see Jabref's Date class which contains some more crazy formats

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 26, 2024
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution.

Some small comments.

Do you have time to craft a roundtrip test? We now have an exporter and an importer.

src/main/java/org/jabref/logic/layout/format/CffDate.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/layout/format/CffDate.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/logic/layout/format/CffDate.java Outdated Show resolved Hide resolved
src/main/resources/resource/layout/cff.layout Outdated Show resolved Hide resolved
@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 26, 2024
dependabot bot and others added 4 commits February 27, 2024 09:33
* Bump org.apache.lucene:lucene-queries from 9.9.1 to 9.10.0

Bumps org.apache.lucene:lucene-queries from 9.9.1 to 9.10.0.

---
updated-dependencies:
- dependency-name: org.apache.lucene:lucene-queries
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* introduce var for lucene

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Siedlerchr <[email protected]>
* Implemented the feature that deleting files which linked to selected entries when user select deletion, and keeping files unchanged when user select cut

* The following features are implemented: 1.Initializes a pop-up dialog box to confirm whether the user wants to delete attached files from selected entry. 2.Keep track of user preference: if the user prefers always delete attached files, delete the files without displaying the dialog box. 3. Add preference options in File>Preference>Linked Files>Attached files so that users can manage preferences

* update CHANGELOG.md

* Add language keys to english language file

* restore files in src/main/resources/csl-locales and src/main/resources/csl-styles

* Removed unnecessary comments and finxed some requested changes. Added new features: 1. When deleting attached files, the name of files to be deleted will be displayed. 2. Solved the access error caused by repeated deletion of files when one file is attached to multiple entries.

* Add language keys to english language file

* Modify language keys to english language file

* made deleteFileFromDisk method static

* update comment of method deleteFileFromDisk

* fixed coding styles

* restored unexpected code changes

* fix logic

* try null

* todo

* Unify dialogs that confirmation deleting files

* Get around LinkedFile in LIbraryTab, Encapsulate LinkedFile into LinkedFileViewModel

* fix style

* restore files

* Unified the different dialogs when deleting entries, removerd unnecessary dialogs

* fix csl-styles

* try to fix csl-styles

* try to fix csl-styles again

* try to fix csl-styles again 2

* try to fix csl-styles again 3

* Update prompts in en.properties

* New features

- Add to Trash
- Group file-related language strings together

* Fix architecture tests

* Introduce list of files to delete

* Streamline 1 vs. many files

* Fix openRewrite

* Discard changes to src/test/resources/org/jabref/logic/search/test-library-with-attached-files.bib

* Adapt true/false logic according to expectations

* Add "Trash" to CHANGELOG.md

* Fix localization

* Fix JabRef_en.properties

* Add some debug statements

* Fix preferences

* Separate log entries by empty line

* More refined dialog

---------

Co-authored-by: Siedlerchr <[email protected]>
Co-authored-by: Oliver Kopp <[email protected]>
Co-authored-by: Carl Christian Snethlage <[email protected]>
#10914)

* Fix duplicate check/merge entries dialog not triggered on import from browser


Refs #5858

* changelog

* remove double duplicate check

* remove l10n

* add icon, downloading is also handled in import entries

* changelog

* fix l10n

* Update JabRef_en.properties

* Update ImportEntriesDialog.java

---------

Co-authored-by: Oliver Kopp <[email protected]>
Made a class comment in CffDate.java
Replaced System.lineseparator() with OS.NEWLINE in CffDate.java
Added a final newline in cff.layout file
@jeanprbt
Copy link
Contributor Author

jeanprbt commented Feb 27, 2024

I do not have much time to implement a roundtrip test, but I think this is more complicated than it seems. In fact, the importer only handles two types of entries, software and dataset. Because the exporter supports a much wider range of entries, using the preferred-citation reference block, this is hard to get the same input and output files.
Furthermore, I did not find any way to extract the first name of an author separately from his last name. This means I am forced to use the field name for authors, whereas many .cff files use separate last-name and given-names fields.
But the exporter is conform to the .cff format right now, and I fixed all your requested changes. :)

@Siedlerchr
Copy link
Member

I'm okay with that for the moment. Then we create a new task for roundtrip test.
For author parsing:

* Retrieve an AuthorList for the given string of authors or editors.
* <p>
* This function tries to cache the parsed AuthorLists by the string passed in.
*
* @param authors The string of authors or editors in bibtex format to parse.
* @return An AuthorList object representing the given authors.
*/
public static AuthorList parse(final String authors) {

@Raahitya-14
Copy link

Thank you for the contribution.

Some small comments.

Do you have time to craft a roundtrip test? We now have an exporter and an importer.

Hey, I am Jean's friend, I can work on crafting a round-trip test! Please let me know if that's fine.

@koppor
Copy link
Member

koppor commented Feb 27, 2024

@Raahitya-14 Sure, go ahead! Maybe the importer has to be improved, too.

As first test https://github.com/JabRef/jabref/blob/main/CITATION.cff Should be imported. Maybe, your work turns out to improve the importer...

@Siedlerchr
Copy link
Member

@Raahitya-14 I suggest you create a new PR for this then

@Raahitya-14
Copy link

@Raahitya-14 I suggest you create a new PR for this then

Sure, I will create a new PR

@koppor koppor added this pull request to the merge queue Feb 27, 2024
Merged via the queue into JabRef:main with commit 7317c2e Feb 27, 2024
20 checks passed
@jeanprbt jeanprbt deleted the issue/10661 branch February 28, 2024 10:02
@jeanprbt jeanprbt restored the issue/10661 branch February 28, 2024 10:16
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 exporter for Citation File Format (CFF) (yaml based)
5 participants