-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathLingBuzz.js
359 lines (336 loc) · 10.3 KB
/
LingBuzz.js
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
{
"translatorID": "e048e70e-8fea-43e9-ac8e-940bc3d71b0b",
"label": "LingBuzz",
"creator": "Göktuğ Kayaalp and Abe Jellinek",
"target": "^https://(ling\\.auf|lingbuzz)\\.net/lingbuzz/(repo/semanticsArchive/article/)?(\\d+|_search)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2022-05-04 01:00:37"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2021 Göktuğ Kayaalp <self at gkayaalp dot com> and Abe Jellinek
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/>.
***** END LICENSE BLOCK *****
*/
const preprintType = ZU.fieldIsValidForType('title', 'preprint')
? 'preprint'
: 'report';
function detectWeb(doc, url) {
if (url.includes("/_search") && getSearchResults(doc, true)) {
return "multiple";
}
return preprintType;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
// exclude author links
var rows = doc.querySelectorAll('td a:not([href*="?_s="])');
for (let row of rows) {
let href = row.href;
let title = ZU.trimInternal(
row.textContent.replace(/\s+\[semanticsArchive\]$/, "")
);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (items) ZU.processDocuments(Object.keys(items), scrape);
});
}
else {
scrape(doc, url);
}
}
function scrape(doc, url) {
if (url.match(/semanticsArchive/)) {
scrapeSA(doc, url);
return;
}
var newItem = new Zotero.Item(preprintType);
if (preprintType == "report") {
newItem.extra = "type: article\n";
}
// Collect information.
var idBlock = doc.querySelector("center");
var title = text(idBlock, "a[href*='.pdf']");
var authors = idBlock.querySelectorAll("a[href*='_k=']");
// These are unpleasant but they're the best we have.
var date = idBlock.lastChild.textContent;
var abstract = idBlock.nextElementSibling.nextSibling.textContent;
var tableRows = doc.querySelectorAll("tbody tr");
for (let row of tableRows) {
let [left, right] = row.querySelectorAll("td");
if (!left || !right) continue;
let fieldName = left.innerText.toLowerCase();
if (fieldName.includes("format")) {
let pdfUrl = right.querySelector("a[href*='.pdf']").href;
newItem.attachments.push({ url: pdfUrl, title: "LingBuzz Full Text PDF", mimeType: "application/pdf" });
}
else if (fieldName.includes("keywords")) {
newItem.tags.push(...right.innerText.split(/[;,] /));
}
else if (fieldName.includes("published in")) {
newItem.extra = (newItem.extra || '') + 'LingBuzz Published In: ' + right.innerText + '\n';
}
}
newItem.title = title;
for (let authorLink of authors) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(authorLink.innerText, "author"));
}
newItem.abstractNote = abstract;
newItem.date = ZU.strToISO(date);
newItem.url = url;
newItem.attachments.push({ document: doc, title: "Snapshot" });
newItem.publisher = "LingBuzz";
newItem.complete();
}
function scrapeSA(doc, url) {
var newItem = new Zotero.Item(preprintType);
if (preprintType == "report") {
newItem.extra = "type: article\n";
}
// Collect information.
var idBlock = doc.querySelector("center");
// This is even worse than the usual LingBuzz pages.
var title = text(idBlock, "a:first-child");
var authors = idBlock.querySelectorAll("a:not(:first-child)");
// These are unpleasant but they're the best we have.
var date = idBlock.lastChild.textContent;
let pdfUrl = idBlock.querySelector("a:first-child").href;
newItem.attachments.push({ url: pdfUrl,
title: "LingBuzz (SemanticsArchive) Full Text PDF",
mimeType: "application/pdf" });
var tableRows = doc.querySelectorAll("tbody tr");
for (let row of tableRows) {
let [left, right] = row.querySelectorAll("td");
if (!left || !right) continue;
let fieldName = left.innerText.toLowerCase();
if (fieldName.includes("keywords")) {
newItem.tags.push(...right.innerText.split(/[;,] /));
}
}
newItem.title = title;
for (let authorLink of authors) {
newItem.creators.push(
Zotero.Utilities.cleanAuthor(authorLink.innerText, "author"));
}
newItem.date = ZU.strToISO(date);
newItem.url = url;
newItem.attachments.push({ document: doc, title: "Snapshot" });
newItem.publisher = "LingBuzz (SemanticsArchive)";
newItem.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://ling.auf.net/lingbuzz/005988",
"items": [
{
"itemType": "preprint",
"title": "Verb height indeed determines prosodic phrasing: evidence from Iron Ossetic",
"creators": [
{
"firstName": "Lena",
"lastName": "Borise",
"creatorType": "author"
},
{
"firstName": "David",
"lastName": "Erschler",
"creatorType": "author"
}
],
"date": "2021-05",
"abstractNote": "We provide novel evidence in favor of the proposal by Hamlaoui and Szendrői (2015, 2017), who argue for a flexible mapping between an Intonational Phrase (ɩ) and syntactic constituents. According to them, ɩ corresponds to the highest projection that hosts verbal material, together with its specifier. The prediction is that the size of ɩ co-varies with the height of the verb, if the latter is variable. Our evidence comes from Iron Ossetic (East Iranian), a language with multiple projections available for verb raising, depending on context. The flexible ɩ-mapping approach – but not more rigid approaches to ɩ-formation – can account for the properties of ɩ-formation in Iron Ossetic. This applies to the prosody of utterances that contain negative indefinites, narrow foci, and single wh-phrases. More complex wh-questions (those with multiple wh-phrases and/or negative indefinites) provide evidence that syntax-based flexible ɩ-mapping approach interacts with language-specific eurhythmic constraints. The Iron Ossetic facts, therefore, provide support for the flexible ɩ-mapping approach, which has not been tested until now on languages of this type.",
"extra": "LingBuzz Published In: Proceedings of NELS 51",
"libraryCatalog": "LingBuzz",
"repository": "LingBuzz",
"shortTitle": "Verb height indeed determines prosodic phrasing",
"url": "https://ling.auf.net/lingbuzz/005988",
"attachments": [
{
"title": "LingBuzz Full Text PDF",
"mimeType": "application/pdf"
},
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "focus"
},
{
"tag": "iranian"
},
{
"tag": "iron ossetic"
},
{
"tag": "phonology"
},
{
"tag": "prosodic phrasing"
},
{
"tag": "syntax"
},
{
"tag": "syntax-prosody interface"
},
{
"tag": "wh-questions"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://ling.auf.net/lingbuzz/repo/semanticsArchive/article/001471",
"items": [
{
"itemType": "preprint",
"title": "Review of Barker and Shan (2015) Continuations and Natural Language",
"creators": [
{
"firstName": "Yusuke",
"lastName": "Kubota",
"creatorType": "author"
}
],
"date": "2015-06",
"libraryCatalog": "LingBuzz",
"repository": "LingBuzz (SemanticsArchive)",
"url": "https://ling.auf.net/lingbuzz/repo/semanticsArchive/article/001471",
"attachments": [
{
"title": "LingBuzz (SemanticsArchive) Full Text PDF",
"mimeType": "application/pdf"
},
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "binding"
},
{
"tag": "categorial grammar"
},
{
"tag": "continuations"
},
{
"tag": "crossover"
},
{
"tag": "reconstruction"
},
{
"tag": "scope"
},
{
"tag": "semantics"
},
{
"tag": "semanticsarchive"
},
{
"tag": "syntax"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://ling.auf.net/lingbuzz/_search?q=svan",
"items": "multiple"
},
{
"type": "web",
"url": "https://ling.auf.net/lingbuzz/_search?q=construction+grammar",
"items": "multiple"
},
{
"type": "web",
"url": "https://ling.auf.net/lingbuzz/_search?q=semanticsarchive",
"items": "multiple"
},
{
"type": "web",
"url": "https://lingbuzz.net/lingbuzz/006559",
"items": [
{
"itemType": "preprint",
"title": "Object drop in Spanish is not island-sensitive",
"creators": [
{
"firstName": "Matías",
"lastName": "Verdecchia",
"creatorType": "author"
}
],
"date": "2022-04",
"abstractNote": "Campos (1986) argues that object drop in Spanish exhibits island effects. This claim has remained unchallenged up to date and is largely assumed in the literature. In this squib, I show that this characterization is not empirically correct: given a proper discourse context, null objects can easily appear within a syntactic island in Spanish. This observation constitutes a non-trivial problem for object drop analyses based on movement.",
"extra": "LingBuzz Published In: To appear in Journal of Linguistics",
"libraryCatalog": "LingBuzz",
"repository": "LingBuzz",
"url": "https://lingbuzz.net/lingbuzz/006559",
"attachments": [
{
"title": "LingBuzz Full Text PDF",
"mimeType": "application/pdf"
},
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
{
"tag": "object drop - islands - spanish - movement"
},
{
"tag": "syntax"
}
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/