-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_citations.py
76 lines (54 loc) · 2.54 KB
/
output_citations.py
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
import json
import requests
# Load citations data
citations_file = open('./dataset_data_citations.json', encoding='utf-8')
#citations_file = open('./debug-datasets.json')
citations = json.load(citations_file)
# Loop through and output Markdown
if "datasets" in citations:
datasets = citations["datasets"]
num_datasets = len(datasets)
print("[INFO] Number of datasets to process: " + str(num_datasets))
# Open file for writing citation markdown
markdown_file = open("./citation_markdown.md", "w", encoding='utf-8')
markdown_file.write("# SPARC Dataset Citations \n \n")
idx = 0
citation_count = 0
while idx < num_datasets:
dataset_record = datasets[idx]
print("[INFO] Processing dataset: " + str(idx))
citations = dataset_record["citations"]
num_citations = len(citations)
citation_count = citation_count + num_citations
print("[INFO] Processing citations: " + str(num_citations))
if num_citations > 0:
name = dataset_record["name"]
markdown_file.write("## " + name + " \n")
doi = dataset_record["doi"]
dataset_id = dataset_record["id"]
dataset_version = dataset_record["version"]
markdown_file.write(
"**DOI:** " + str(doi) + " **Dataset ID:** " + str(dataset_id) + " **Dataset Version:** " + str(dataset_version) + " \n\n")
dataset_citation = dataset_record["citation"]
markdown_file.write("**Citation:** " + str(dataset_citation) + " \n \n")
markdown_file.write("## Dataset Citations" + " \n")
citation_idx = 0
while citation_idx < num_citations:
citation_type = citations[citation_idx]["type"]
citation_curie = citations[citation_idx]["curie"]
citation_text = citations[citation_idx]["citation"]
markdown_file.write(" DOI: " + str(citation_curie) )
if citation_type == 'Originating Publication':
markdown_file.write(" [Originating Publication] \n")
elif citation_type == 'Protocol':
markdown_file.write(" [Protocol] \n")
else:
markdown_file.write(" [Citation] \n")
markdown_file.write(" Citation: " + str(citation_text) + " \n \n")
citation_idx =citation_idx +1
idx = idx + 1
markdown_file.close()
print("[INFO] Number of Citations: " + str(citation_count))
else:
print("[ERROR] No datasets")
exit(0)