-
Notifications
You must be signed in to change notification settings - Fork 5
/
The Brain.ts
229 lines (207 loc) · 6.35 KB
/
The Brain.ts
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
declare const Zotero: any
const aliases = Object.entries({
bookTitle: 'publicationTitle',
thesisType: 'type',
university: 'publisher',
letterType: 'type',
manuscriptType: 'type',
interviewMedium: 'medium',
distributor: 'publisher',
videoRecordingFormat: 'medium',
genre: 'type',
artworkMedium: 'medium',
websiteType: 'type',
websiteTitle: 'publicationTitle',
institution: 'publisher',
reportType: 'type',
reportNumber: 'number',
billNumber: 'number',
codeVolume: 'volume',
codePages: 'pages',
dateDecided: 'date',
reporterVolume: 'volume',
firstPage: 'pages',
caseName: 'title',
docketNumber: 'number',
documentNumber: 'number',
patentNumber: 'number',
issueDate: 'date',
dateEnacted: 'date',
publicLawNumber: 'number',
nameOfAct: 'title',
subject: 'title',
mapType: 'type',
blogTitle: 'publicationTitle',
postType: 'type',
forumTitle: 'publicationTitle',
audioRecordingFormat: 'medium',
label: 'publisher',
presentationType: 'type',
studio: 'publisher',
network: 'publisher',
episodeNumber: 'number',
programTitle: 'publicationTitle',
audioFileType: 'medium',
company: 'publisher',
proceedingsTitle: 'publicationTitle',
encyclopediaTitle: 'publicationTitle',
dictionaryTitle: 'publicationTitle',
})
function clean(txt) {
return txt.replace(/\r/g, '').replace(/\n/g, ' ').replace(/;/g, ',').replace(/["“”]/g, "'")
}
function url(txt) {
const arbitrary_tb_limit = 185
const ellipses = ' ...'
if (txt.length <= arbitrary_tb_limit) return txt
return txt.substr(0, arbitrary_tb_limit - ellipses.length) + ellipses
}
const ignore = new Set(['attachment', 'note'])
function detail(txt, prefix) {
if (!txt) return
txt = prefix === '+' ? url(txt) : clean(txt)
if (prefix) prefix += ' '
Zotero.write(`\t${prefix}${txt}\n`)
}
function doExport() {
let item
while (item = Zotero.nextItem()) {
if (ignore.has(item.itemType)) continue
for (const [alias, field] of aliases) {
if (item[alias]) {
item[field] = item[alias]
delete item[alias]
}
}
const reference = []
const creators = (item.creators || []).map(creator => {
let name = ''
if (creator.name) name = creator.name
if (creator.lastName) name = creator.lastName
if (creator.firstName) name += (name ? ', ' : '') + creator.firstName
return name
})
switch (creators.length) {
case 0:
break
case 1:
reference.push(creators[0])
break
default:
reference.push(`${creators[0]} et al`)
break
}
const date = Zotero.Utilities.strToDate(item.date)
const year = (date && typeof date.year !== 'undefined') ? date.year : ''
if (year) reference.push(year)
let title = item.title
if (reference.length) title += `, (${reference.join(', ')})`
Zotero.write(clean(title) + '\n')
detail(item.url, '+')
for (const att of (item.attachments || [])) {
detail(att.localPath || att.defaultPath || att.url, '+')
}
detail(item.abstractNote, '-')
for (const note of (item.notes || [])) {
detail(note.note.replace(/<[^>]*>?/g, ''), '-')
}
for (const name of creators) {
detail(name, '#')
}
detail(year, '#')
detail(item.publicationTitle, '#')
for (const tag of (item.tags || [])) {
if (tag.type === 1) continue // automatic tag
detail(tag.tag, '#')
}
let itemType = item.itemType.charAt(0).toUpperCase() + item.itemType.slice(1)
itemType = itemType.replace(/([A-Z]+)/g, ' $1').trim()
detail(itemType, '#')
for (const line of (item.extra || '').split(/\r?\n/).map(l => l.trim())) {
if (line.match(/^[0-9]{5}$/)) {
detail(`Citations: ${line.replace(/^0+/, '')}`, '')
}
}
detail(item.uri.split('/').pop(), '')
Zotero.write('\n')
}
}
/*
{
"relations" : {},
"attachments" : [
{
"contentType" : "application/pdf",
"itemType" : "attachment",
"parentItem" : "VUL8ZVJ8",
"uri" : "http://zotero.org/users/local/6z7M0kXV/items/UTUXSHXA",
"filename" : "Araz et al. - 2014 - Using Google Flu Trends data in forecasting influe.pdf",
"tags" : [],
"version" : 0,
"charset" : "",
"localPath" : "/home/emile/.BBTZ5TEST/zotero/storage/UTUXSHXA/Araz et al. - 2014 - Using Google Flu Trends data in forecasting influe.pdf",
"dateModified" : "2019-01-16T14:48:43Z",
"linkMode" : "imported_file",
"relations" : {},
"title" : "Araz et al. - 2014 - Using Google Flu Trends data in forecasting influe.pdf",
"dateAdded" : "2019-01-16T14:48:43Z"
}
],
"url" : "http://www.ajemjournal.com/article/S0735-6757(14)00421-5/abstract",
"dateAdded" : "2019-01-16T11:47:49Z",
"accessDate" : "2016-10-07T22:48:15Z",
"publicationTitle" : "The American Journal of Emergency Medicine",
"notes" : [
{
"dateModified" : "2019-01-16T14:40:52Z",
"relations" : {},
"dateAdded" : "2019-01-16T14:40:43Z",
"itemType" : "note",
"note" : "<p>stuf with <strong>bold</strong></p>",
"parentItem" : "VUL8ZVJ8",
"tags" : [],
"key" : "DUSDL5F2",
"version" : 0
}
],
"version" : 0,
"ISSN" : "0735-6757, 1532-8171",
"collections" : [],
"extra" : "PMID: 25037278",
"title" : "Using Google Flu Trends data in forecasting influenza-like-illness related ED visits in Omaha, Nebraska",
"language" : "English",
"pages" : "1016–1023",
"dateModified" : "2019-01-16T14:03:46Z",
"abstractNote" : "Introduction\nEmergency department (ED) visits ... and overcrowding.",
"date" : "2014-09-01",
"DOI" : "10.1016/j.ajem.2014.05.052",
"journalAbbreviation" : "The American Journal of Emergency Medicine",
"tags" : [
{
"tag" : "qwef"
}
],
"uri" : "http://zotero.org/users/local/6z7M0kXV/items/VUL8ZVJ8",
"issue" : "9",
"creators" : [
{
"lastName" : "Araz",
"creatorType" : "author",
"firstName" : "Ozgur M."
},
{
"creatorType" : "author",
"firstName" : "Dan",
"lastName" : "Bentley"
},
{
"creatorType" : "author",
"firstName" : "Robert L.",
"lastName" : "Muelleman"
}
],
"itemType" : "journalArticle",
"volume" : "32",
"libraryCatalog" : "www.ajemjournal.com"
}
*/