UB-Mannheim / zotkat

Erweiterung von Zotero für die Katalogisierung
GNU Affero General Public License v3.0
45 stars 22 forks source link

[WQS]: Refactor statement generation #64

Closed nichtich closed 6 years ago

nichtich commented 6 years ago

Slightly refactore the code of Wikidata QuickStatements.js to get a better testable function that maps a Zotero item to a QuickStatements string (see #55).

zuphilip commented 6 years ago

Thank you! This looks good from my first glance (I have to look closer some time later...).

BTW I think we can also use another function like this (code is untested):

formatStatement(subject, property, object, addQuotationMarks) {
   if (addQuotationMarks) {
      object = '"' + object + '"';
   }
   var elements = [subject, property, object];
   return elements.join('\t');
}

What do you think @nichtich ? We then use code like

formatStatement('LAST', 'P31', typeMapping[itemType], false);
formatStatement(formatStatement('LAST', 'P2093' creatorValue, true), 'P1545', index, true);
nichtich commented 6 years ago

Ok I extended the code similar to suggested and also added a unit test: see this branch: https://github.com/gbv/zotkat/tree/wqs-test