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

Handle custom fields in Citavi 5 XML.js #3183

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zuphilip
Copy link
Contributor

@zuphilip zuphilip commented Nov 9, 2023

In Citavi, it is possible to define and use custom fields (=Freitextfelder). These changes provide them as well in Zotero.

The import now saves the contents into separate notes prefixed with the label of custom fields. For example:

grafik

Custom fields (=Freitextfelder) in Citavi can be defined and used.
This changes imports them as well in Zotero.
Also fixing potential problems handling keywords with
other tags in general.
@zuphilip
Copy link
Contributor Author

I have pushed now some further improvements to the Citavi translator. Most fixed issues are from the forum post https://forums.zotero.org/discussion/comment/449182/#Comment_449182 and the provided example. Additionally saving the BibTeX key was mentioned in another round and I picked this up to include it now in the official translator. It would be great to hear any feedback to this pull request.

@zuphilip zuphilip force-pushed the citavi-custom-fields branch from 2cd7b19 to fc0978d Compare November 28, 2023 11:39
@zuphilip zuphilip force-pushed the citavi-custom-fields branch from fc0978d to 06adfb9 Compare November 28, 2023 11:44
@zuphilip
Copy link
Contributor Author

zuphilip commented Jan 18, 2024

Bump

It would be great if this could be discussed and merged. I know that there probably more and more people will need to migrate from Citavi as several contracts in Germany ended or will end soon. This PR improves several things which were reported from such people.

CC @adam3smith

@adam3smith
Copy link
Collaborator

adam3smith commented Jan 21, 2024

This all looks good to me -- could we either get a test or at a minimum link to test data (ideally linked from a comment in the tranlsator)? That'd help hugely with maintenance.

var label = rememberCustomFields[field];
var customField = ZU.xpathText(references[i], './' + field);
if (customField) {
item.notes.push({ note: label + ": " + customField, tags: ["#CustomField"] });
Copy link
Member

Choose a reason for hiding this comment

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

We don't typically add automatic tags to notes AFAIK, especially with a hash prefix. Can we leave it out?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we do for RIS and Endnote XML to allow quick filter and delete?

Copy link
Contributor Author

@zuphilip zuphilip Jan 23, 2024

Choose a reason for hiding this comment

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

Similar tags in notes are used already in this Citavi translator itself: #Notes, #TableOfContents, #Evaluation, and #todo (from tasks imported as standalone notes). There are different fields in Citavi which are all mapped to notes in Zotero. With the tags one can still differentiate them and possibly also filter for them as @adam3smith suggested.

I think that this is especially useful for custom fields, which in some cases have a better field in Zotero to save the information. This now could then be realized by using a little script after the import translator here. For example I started with this adaptable proof-of-concept script for moving the #customFields notes to some other field within Zotero. Overall, one would then need to do the import first (which is the same for everyone), and possibly some individual script to move some notes further afterwards.

@zuphilip
Copy link
Contributor Author

This all looks good to me -- could we either get a test or at a minimum link to test data (ideally linked from a comment in the translator)? That'd help hugely with maintenance.

The custom fields are already part of some of the saved test cases now. However, I can also check whether it is possible to provide another example covering the things here.

@adam3smith
Copy link
Collaborator

The custom fields are already part of some of the saved test cases now. However, I can also check whether it is possible to provide another example covering the things here.

But then they should up in changed tests, no? In that case, maybe just need to update the tests, or am I misunderstanding what you're saying?

@zuphilip
Copy link
Contributor Author

But then they should up in changed tests, no? In that case, maybe just need to update the tests, or am I misunderstanding what you're saying?

No, the test cases are not part of the translator here. I think there was an parsing error when we first tried that, but I can't remember exactly because that was some years ago. Instead test data for Citavi translator is saved in some gists and then just linked here as comments in the translator:

/*
TEST DATA can be found here:
- Single reference (162 KB) text: https://gist.github.com/zuphilip/02d6478ace4636e4e090e348443c551e
- Larger project (1221 KB): https://gist.github.com/zuphilip/76ce89ebbdac0386507b36cff3fd499a
- Other project (1,11 MB): https://gist.github.com/anonymous/10fc363b6d79dae897e296a4327aa707
- Citavi 6 project (935 KB): https://gist.github.com/zuphilip/00a4ec6df58ac24b68366e32531bae4b
- Nested categories: (34 KB): https://gist.github.com/tnajdek/b2375e52b48c7bf82f9f592b4f2122f5
*/

Copy link

@JAC28 JAC28 left a comment

Choose a reason for hiding this comment

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

Proposal for further extension of the translator to take into account image notes.

importCategories({ categories, doc, progress });
}

function extractNote(doc, noteXML, rememberTags) {
Copy link

Choose a reason for hiding this comment

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

One major drawback when import data from Citavi to Zotero is loosing all knowledge-items with images ("Bildzitat"). As far as I am aware, it is currently not possible to attach an image to a note, which results in many notes without much content after import. To simplify manual fixing afterward, I suggest tagging the note and include the filename into the note, as follows. The result could look like
grafik

noteObject.id = ZU.xpathText(noteXML, '@id');
var title = ZU.xpathText(noteXML, 'CoreStatement');
var text = ZU.xpathText(noteXML, 'Text');
var pages = extractPages(ZU.xpathText(noteXML, 'PageRange'));
Copy link

Choose a reason for hiding this comment

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

Suggested change
var pages = extractPages(ZU.xpathText(noteXML, 'PageRange'));
var pages = extractPages(ZU.xpathText(noteXML, 'PageRange'));
var address = ZU.xpathText(citations[j], 'Address');
var hasMissingImage =false;

if (text) {
text = text.split(/\r?\n/).join("<br />");
noteObject.note += "<p>" + text + "</p>\n";
}
Copy link

Choose a reason for hiding this comment

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

Add text to note if address is file name. Empty line before text to ease inserting of image later.

Suggested change
}
}
if (address) {
var addressMap = JSON.parse(address);
// Based on Demo project mapping is:
// 1->File
// 5->Link
if (addressMap.LinkedResourceType==1){
noteObject.note += "<p></p><p>" + '<strong>Missing Image with filename:</strong> </p>';
noteObject.note += "<pre><code>" + addressMap.UriString + "</code></pre>\n";
var hasMissingImage = true;
}
}

for (let j = 0; j < rememberTags[noteObject.id]; j++) {
noteObject.tags.append(rememberTags[noteObject.id][j]);
}
}
Copy link

Choose a reason for hiding this comment

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

Finally, add a tag similar as #todo for easy filtering

Suggested change
}
}
if (hasMissingImage) {
noteObject.tags.push("#missingImage");
}

JAC28 added a commit to JAC28/ZoteroTranslators that referenced this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants