-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzenodo2markdown.groovy
94 lines (80 loc) · 2.92 KB
/
zenodo2markdown.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2023-2024 Egon Willighagen <egon.willighagen@gmail.com>
//
// GPL v3
@Grab(group='io.github.egonw.bacting', module='managers-rdf', version='1.0.3')
@Grab(group='io.github.egonw.bacting', module='managers-ui', version='1.0.3')
@Grab(group='io.github.egonw.bacting', module='managers-zenodo', version='1.0.3')
@Grab(group='io.github.egonw.bacting', module='net.bioclipse.managers.jsoup', version='1.0.3')
import groovy.xml.XmlParser
bioclipse = new net.bioclipse.managers.BioclipseManager(".");
zenodo = new net.bioclipse.managers.ZenodoManager(".");
jsoup = new net.bioclipse.managers.JSoupManager(".");
xml = zenodo.getOAIPMHData(args[0])
def oaiDatacite = new XmlParser().parseText(xml)
org = "Undefined"
orgURL = "https://www.nanosafetycluster.eu/"
oaiDatacite.GetRecord.record.header.setSpec.each { it ->
if (it.text() == "user-nanosolveit") {
org = "NanoSolveIT"
orgURL = "https://nanosolveit.eu/"
} else if (it.text() == "user-nsc") {
org = "EU NanoSafety Cluster"
orgURL = "https://www.nanosafetycluster.eu/"
} else {
println "<!-- Unknown organisation: ${it.text()} -->"
}
}
oaiDatacite.GetRecord.record.metadata.oai_datacite.payload.resource.fundingReferences.fundingReference.each { it ->
if (it.funderIdentifier.text() == "00k4n6c32" && it.awardNumber.text() == "814572") {
org = "NanoSolveIT"
orgURL = "https://nanosolveit.eu/"
} else {
println "<!-- Unknown funder: ${it.text()} -->"
}
}
record = oaiDatacite.GetRecord.record.metadata.oai_datacite.payload.resource
doi = record.identifier.text()
title = record.titles.title[0].text()
date = record.dates.date[0].text()
license = record.rightsList.rights[0].@rightsURI
licenseTitle = record.rightsList.rights[0].text()
description = jsoup.removeHTMLTags(record.descriptions.description[0].text())
keywords = ""
if (record.subjects.subject.size() > 0) {
keywords = record.subjects.subject.iterator().collect{it.text()}.join(", ")
}
url = "https://doi.org/${doi}"
keywordLine = ""
if (keywords.length() > 0) {
keywordLine = """
\"keywords\": \"${keywords}\","""
}
print """
<div style="float: right; width: 200px" class='altmetric-embed' data-badge-type='donut' data-condensed='true' data-badge-details='right' data-doi="${doi}"></div>
## ${title}
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Dataset",
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/Dataset/1.0-RELEASE" },
"@id": "https://doi.org/${doi}",
"identifier": "${doi}",
"name": "${title}",
"description": "${description}",
"license": "${license}",
"url": "${url}",${keywordLine}
"creator": [
{
"@type": "Organization",
"name": "${org}"
}
],
"datePublished": "${date}"
}
</script>
* Date: ${date}
* License: [${licenseTitle}](${license})
* Project: [${org}](${orgURL})
* URL: [${url}](${url})
* DOI: ${doi}
"""