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 TIND Repository translator #3387

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 349 additions & 0 deletions TIND Repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
{
"translatorID": "802aa72e-80dd-459d-8712-131f6eeccd4c",
"label": "TIND Repository",
"creator": "Thomas Rambø",
"target": "/record/[0-9]+",
"minVersion": "3.0",
"maxVersion": "",
"priority": 250,
"inRepository": true,
"translatorType": 5,
"browserSupport": "gcsibv",
"lastUpdated": "2024-11-20 09:32:40"
}

/*
This file is part of Zotero.

Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
*/

const SCHEMA_ORG_ZOTERO_TYPE_MAPPING = {
"CreativeWork": "document",
"Article": "journalArticle",
"Book": "book",
"Chapter": "bookSection"
};

/**
*
* @param {Document} doc The page document
* @param {string} url The page url
*/
function detectWeb(doc, url) {
const schemaOrgElement = /** @type {HTMLScriptElement | null} */ (
Copy link
Member

Choose a reason for hiding this comment

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

We use tabs for indentation, and Scaffold should be saving with tabs.

doc.getElementById("detailed-schema-org")
);

if (schemaOrgElement === null) {
return;
}

let schemaOrg;
try {
schemaOrg = JSON.parse(schemaOrgElement.textContent);
} catch (error) {
return;
}

const schemaOrgType = schemaOrg["@type"];
const type = SCHEMA_ORG_ZOTERO_TYPE_MAPPING[schemaOrgType];

if (type !== undefined) {
return type;
}
}

/**
*
* @param {Document} doc The page document
* @param {string} url The page url
*/
function doWeb(doc, url) {
const schemaOrgElement = /** @type {HTMLScriptElement | null} */ (
doc.getElementById("detailed-schema-org")
);

if (schemaOrgElement === null) {
return;
}

const translator = Zotero.loadTranslator("import");
translator.setTranslator("802aa72e-80dd-459d-8712-131f6eeccd4c");
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be an import translator. Right now this would break all JSON imports (e.g. CSL JSON). Import translators are for data formats shared between multiple translators, like Primo Normalized XML, or data interchange formats that sites might provide exports in or that people might want to import from disk, like BibTeX.

I'm not sure if you turned this into an import translator in order to add tests, but web translators can already have tests.

Can just undo these changes.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if you turned this into an import translator in order to add tests

Yes, this is exactly the reason. But I don't have any urls available to add for tests, so how would I go about testing the web translators?


translator.setString(schemaOrgElement.textContent);

translator.setHandler("debug", function (translate, message) {
Zotero.debug(message);
});

translator.translate();
}

function detectImport() {
const schemaOrgText = [];

while (true) {
const line = Zotero.read();

if (!line) {
break;
}

schemaOrgText.push(line);
}

try {
JSON.parse(schemaOrgText.join(""));
} catch (error) {
return false;
}

return true;
}

function doImport() {
const schemaOrgText = [];

while (true) {
const line = Zotero.read();

if (!line) {
break;
}

schemaOrgText.push(line);
}

let schemaOrg;
try {
schemaOrg = JSON.parse(schemaOrgText.join(""));
} catch (error) {
Zotero.debug(`Schema.org JSON could not be parsed: ${error}`);
return;
}

const schemaOrgType = schemaOrg["@type"];
const type = SCHEMA_ORG_ZOTERO_TYPE_MAPPING[schemaOrgType];

if (type === undefined) {
return;
}

const item = new Zotero.Item(type);

item.url = schemaOrg["@id"];

if (schemaOrg.isbn) {
item.ISBN = schemaOrg.isbn;
}

for (const { value, propertyID } of schemaOrg.identifier || []) {
if (propertyID === "DOI") {
item.DOI = value;
}

if (propertyID === "ISSN") {
item.ISSN = value;
}
}

for (const { alternateName } of schemaOrg.inLanguage || []) {
if (!alternateName) {
continue;
}

item.language = alternateName;
break;
}

item.title = schemaOrg.name;

for (const { name: authorName } of schemaOrg.author || []) {
if (!authorName) {
continue;
}

item.creators.push({ lastName: authorName, creatorType: "author", fieldMode: 1 });
}

for (const { name: publisherName } of schemaOrg.publisher || []) {
if (!publisherName) {
continue;
}

item.publisher = publisherName;
break;
}

if (schemaOrg.datePublished) {
item.date = schemaOrg.datePublished;
}

if (schemaOrg.description) {
item.abstract = schemaOrg.description;
}

for (const keyword of [...schemaOrg.keywords || [], schemaOrg.keyword]) {
if (!keyword) {
continue;
}

item.tags.push(keyword);
}

item.complete();
}

/** BEGIN TEST CASES **/
var testCases = [
{
"type": "import",
"input": "{\"name\": \"Study of a dE/dx measurement and the gas-gain saturation by a prototype drift chamber for the BELLE-CDC\", \"@context\": \"https://schema.org\", \"@type\": \"CreativeWork\", \"author\": [{\"@type\": \"Person\", \"affiliation\": \"KEK\", \"name\": \"Emi, K\"}, {\"@type\": \"Person\", \"name\": \"Tsukamoto, T\"}, {\"@type\": \"Person\", \"name\": \"Hirano, H\"}, {\"@type\": \"Person\", \"name\": \"Mamada, H\"}, {\"@type\": \"Person\", \"name\": \"Sakai, Y\"}, {\"@type\": \"Person\", \"name\": \"Uno, S\"}, {\"@type\": \"Person\", \"name\": \"Itami, S\"}, {\"@type\": \"Person\", \"name\": \"Kajikawa, R\"}, {\"@type\": \"Person\", \"name\": \"Nitoh, O\"}, {\"@type\": \"Person\", \"name\": \"Ohishi, N\"}, {\"@type\": \"Person\", \"name\": \"Sugiyama, A\"}, {\"@type\": \"Person\", \"name\": \"Suzuki, S\"}, {\"@type\": \"Person\", \"name\": \"Takahashi, T\"}, {\"@type\": \"Person\", \"name\": \"Tamagawa, Y\"}, {\"@type\": \"Person\", \"name\": \"Tomoto, M\"}, {\"@type\": \"Person\", \"name\": \"Yamaki, T\"}], \"datePublished\": \"Jan 1996\", \"inLanguage\": [{\"@type\": \"Language\", \"alternateName\": \"eng\"}], \"publisher\": [{\"@type\": \"Organization\", \"name\": \"KEK\"}], \"@id\": \"https://cicero.tind.io/record/71\"}\n",
"items": [
{
"itemType": "document",
"creators": [
{
"lastName": "Emi, K",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Tsukamoto, T",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Hirano, H",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Mamada, H",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Sakai, Y",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Uno, S",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Itami, S",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Kajikawa, R",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Nitoh, O",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Ohishi, N",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Sugiyama, A",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Suzuki, S",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Takahashi, T",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Tamagawa, Y",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Tomoto, M",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Yamaki, T",
"creatorType": "author",
"fieldMode": 1
}
],
"language": "eng",
"title": "Study of a dE/dx measurement and the gas-gain saturation by a prototype drift chamber for the BELLE-CDC",
"publisher": "KEK",
"date": "Jan 1996",
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"url": "https://cicero.tind.io/record/71"
}
]
},
{
"type": "import",
"input": "{\"name\": \"Influence of processing parameters on the manufacturing of anode-supported solid oxide fuel cells by different wet chemical routes\", \"description\": \"Anode-supported solid oxide fuel cells (SOFC) are manufactured at Forschungszentrum J\\u00fclich by different wet chemical powder processes and subsequent sintering at high temperatures. Recently, the warm pressing of Coat-Mix powders has been replaced by tape casting as the shaping technology for the NiO/8YSZ-containing substrate in order to decrease the demand for raw materials due to lower substrate thickness and in order to increase reproducibility and fabrication capacities (scalable process). Different processing routes for the substrates require the adjustment of process parameters for further coating with functional layers. Therefore, mainly thermal treatment steps have to be adapted to the properties of the new substrate types in order to obtain high-performance cells with minimum curvature (for stack assembly). In this presentation, the influence of selected process parameters during cell manufacturing will be characterized with respect to the resulting physical parameters such as slurry viscosity, green tape thickness, relative density, substrate strength, electrical conductivity, and shrinkage of the different newly developed substrate types. The influencing factors during manufacturing and the resulting characteristics will be presented and possible applications for the various substrates identified.\", \"identifier\": [{\"@type\": \"PropertyValue\", \"value\": \"10.4028/www.scientific.net/MSF.638-642.1098\", \"propertyID\": \"DOI\"}, {\"@type\": \"PropertyValue\", \"value\": \"VDB:125298\", \"propertyID\": \"VDB\"}, {\"@type\": \"PropertyValue\", \"value\": \"0255-5476\", \"propertyID\": \"ISSN\"}, {\"@type\": \"PropertyValue\", \"propertyID\": \"inh\"}], \"@context\": \"https://schema.org\", \"@type\": \"CreativeWork\", \"author\": [{\"@type\": \"Person\", \"@id\": \"PER:96536\", \"name\": \"Menzler, N.H.\"}, {\"@type\": \"Person\", \"@id\": \"PER:76694\", \"name\": \"Schafbauer, W.\"}, {\"@type\": \"Person\", \"@id\": \"PER:96316\", \"name\": \"Buchkremer, H.P.\"}], \"datePublished\": \"2010\", \"inLanguage\": [{\"@type\": \"Language\", \"alternateName\": \"English\"}], \"@id\": \"https://cicero.tind.io/record/128\"}\n",
"items": [
{
"itemType": "document",
"creators": [
{
"lastName": "Menzler, N.H.",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Schafbauer, W.",
"creatorType": "author",
"fieldMode": 1
},
{
"lastName": "Buchkremer, H.P.",
"creatorType": "author",
"fieldMode": 1
}
],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [],
"url": "https://cicero.tind.io/record/128",
"DOI": "10.4028/www.scientific.net/MSF.638-642.1098",
"ISSN": "0255-5476",
"language": "English",
"title": "Influence of processing parameters on the manufacturing of anode-supported solid oxide fuel cells by different wet chemical routes",
"date": "2010",
"abstract": "Anode-supported solid oxide fuel cells (SOFC) are manufactured at Forschungszentrum Jülich by different wet chemical powder processes and subsequent sintering at high temperatures. Recently, the warm pressing of Coat-Mix powders has been replaced by tape casting as the shaping technology for the NiO/8YSZ-containing substrate in order to decrease the demand for raw materials due to lower substrate thickness and in order to increase reproducibility and fabrication capacities (scalable process). Different processing routes for the substrates require the adjustment of process parameters for further coating with functional layers. Therefore, mainly thermal treatment steps have to be adapted to the properties of the new substrate types in order to obtain high-performance cells with minimum curvature (for stack assembly). In this presentation, the influence of selected process parameters during cell manufacturing will be characterized with respect to the resulting physical parameters such as slurry viscosity, green tape thickness, relative density, substrate strength, electrical conductivity, and shrinkage of the different newly developed substrate types. The influencing factors during manufacturing and the resulting characteristics will be presented and possible applications for the various substrates identified."
}
]
}
]
/** END TEST CASES **/
Loading