forked from ERM-HD/issnimporter.ontowiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportKBART.php
412 lines (323 loc) · 16.9 KB
/
ImportKBART.php
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php
$publication_title = '' ;
$date_first_issue_online = '' ;
$num_first_vol_online = '' ;
$num_first_issue_online = '' ;
$date_last_issue_online = '' ;
$num_last_vol_online = '' ;
$num_last_issue_online = '' ;
$title_url = '' ;
$first_author = '' ;
$title_id = '' ;
$embargo_info = '' ;
$coverage_depth = null ;
$coverage_notes = '' ;
$publisher_name = '' ;
$price = '' ;
// COLUMN 0: publication_title
// Search for publication_title
if ($csvColumn[0] !== '') {
$publication_title = $csvColumn[0];
}
// write statement for title_id as dc:title
if ($publication_title !== '') {
$data[$itemUri][$nsDc . 'title'][] = array(
'type' => 'literal',
'value' => $publication_title
);
}
// COLUMS 1 and two: print_identifier and online_identifier
//SEARCH
// Search for E-ISSN in online_identifier
if (preg_match_all('/\d{4}\-\d{3}[\dxX]/', $csvColumn[2], $eissn)) {
# Found an EISSN, create URI and write first statemntes
$foundEISSN = true;
} else {
$eissn = null;
}
// Search for P-ISSN in print_identifier
if (preg_match_all('/\d{4}\-\d{3}[\dxX]/', $csvColumn[1], $pissn)) {
$foundPISSN = true;
} else {
$pissn = null;
}
// Search for E-ISBN in online_identifier
if (preg_match_all($regISBN, str_replace('-', '', $csvColumn[2]), $eisbn)) {
// it is possible to match a ISSN expression within a ISBN string
// if this is the case reset the ISSN values
if ($foundEISSN === true) {
$eissn = null;
}
} else {
$eisbn = null;
}
// Search for P-ISBN in print_identifier
if (preg_match_all($regISBN, str_replace('-', '', $csvColumn[1]), $pisbn)) {
// it is possible to match a ISSN expression within a ISBN string
// if this is the case reset the ISSN values
if ($foundPISSN === true) {
$pissn = null;
}
} else {
$pisbn = null;
}
//WRITE STATEMENTS
// write statements linking to found E-ISSNs
if (isset($eissn[0])) {
foreach ($eissn[0] as $value) {
$data[$itemUri][$nsAmsl . 'eissn'][] = array(
'type' => 'uri',
'value' => 'urn:ISSN:' . $value
);
}
}
// write statements linking to found E-ISBNs
if (isset($eisbn[0])) {
foreach ($eisbn[0] as $value) {
$data[$itemUri][$nsAmsl . 'eisbn'][] = array(
'type' => 'uri',
'value' => 'urn:ISBN:' . $value
);
}
}
# write statements linking to found P-ISSNs
if (isset($pissn[0])) {
foreach ($pissn[0] as $value) {
$data[$itemUri][$nsAmsl . 'pissn'][] = array(
'type' => 'uri',
'value' => 'urn:ISSN:' . $value
);
}
}
// write statements linking to found P-ISBNs
if (isset($pisbn[0])) {
foreach ($pisbn[0] as $value) {
$data[$itemUri][$nsAmsl . 'pisbn'][] = array(
'type' => 'uri',
'value' => 'urn:ISBN:' . $value
);
}
}
// COLUMN 3: Date of first issue available online
if ($csvColumn[3] !== '') {
$date_first_issue_online = $csvColumn[3] ;
$dateType = '' ;
// check for date Types
if (preg_match('(^\d{4}-\d{2}-\d{2}$)',$date_first_issue_online)) {
$dateType = 'date';
} elseif (preg_match('(^\d{4}-\d{2}$)',$date_first_issue_online)) {
$dateType = 'gYearMonth';
} elseif (preg_match('(^\d{4}$)',$date_first_issue_online)) {
$dateType = 'gYear';
} else {
$dateType = FALSE ;
}
// write statements
// doesn't yet throw error for incorrect dates, just doesn't write any triples
if ($dateType !== FALSE) {
$data[$itemUri][$nsAmsl . 'dateFirstIssueOnline'][] = array(
'type' => 'literal',
// 'datatype' => $nsXsd . $dateType , // doesn't work due to virtuoso bug
'value' => $date_first_issue_online
);
}
}
// COLUMN 4: Number of first volume available online
// Search for num_first_vol_online
if ($csvColumn[4] !== '') {
$num_first_vol_online = $csvColumn[4];
}
// write statement for num_first_vol_online as numFirstVolumeOnline
if ($num_first_vol_online !== '') {
$data[$itemUri][$nsAmsl . 'numberFirstVolumeOnline'][] = array(
'type' => 'literal',
'value' => $num_first_vol_online
);
}
// COLUMN 5: Number of first issue available online
// Search for num_first_issue_online
if ($csvColumn[5] !== '') {
$num_first_issue_online = $csvColumn[5];
}
// write statement for num_first_issue_online as numFirstIssueOnline
if ($num_first_issue_online !== '') {
$data[$itemUri][$nsAmsl . 'numberFirstIssueOnline'][] = array(
'type' => 'literal',
'value' => $num_first_issue_online
);
}
// COLUMN 6: Date of last issue available online
if ($csvColumn[6] !== '') {
$date_last_issue_online = $csvColumn[6] ;
$dateType = '' ;
// check for date Types
if (preg_match('(^\d{4}-\d{2}-\d{2}$)',$date_last_issue_online)) {
$dateType = 'date';
} elseif (preg_match('(^\d{4}-\d{2}$)',$date_last_issue_online)) {
$dateType = 'gYearMonth';
} elseif (preg_match('(^\d{4}$)',$date_last_issue_online)) {
$dateType = 'gYear';
} else {
$dateType = FALSE ;
}
// write statements
// doesn't yet throw error for incorrect dates, just doesn't write any triples
if ($dateType !== FALSE) {
$data[$itemUri][$nsAmsl . 'dateLastIssueOnline'][] = array(
'type' => 'literal',
// 'datatype' => $nsXsd . $dateType , // doesn't work due to virtuoso bug
'value' => $date_last_issue_online
);
}
}
// COLUMN 7: Number of last volume available online
// Search for num_last_vol_online
if ($csvColumn[4] !== '') {
$num_last_vol_online = $csvColumn[4];
}
// write statement for num_last_vol_online as numLastVolumeOnline
if ($num_last_vol_online !== '') {
$data[$itemUri][$nsAmsl . 'numberLastVolumeOnline'][] = array(
'type' => 'literal',
'value' => $num_last_vol_online
);
}
// COLUMN 8: Number of last issue available online
// Search for num_last_issue_online
if ($csvColumn[5] !== '') {
$num_last_issue_online = $csvColumn[5];
}
// write statement for num_last_issue_online as numLastIssueOnline
if ($num_last_issue_online !== '') {
$data[$itemUri][$nsAmsl . 'numberLastIssueOnline'][] = array(
'type' => 'literal',
'value' => $num_last_issue_online
);
}
// COLUMN 9: Title-Level URL
// Search for title_url
if ($csvColumn[9] !== '') {
$title_url = $csvColumn[9];
}
// write statement for title_url as primaryAccessURI
if ($title_url !== '') {
$data[$itemUri][$nsAmsl . 'primaryAccessURI'][] = array(
'type' => 'uri',
'value' => $title_url
);
//add label to URI-Resource to improve readability in OntoWiki Resource View
$data[$title_url][EF_RDFS_LABEL][] = array(
'type' => 'literal',
'value' => $title_url
);
}
// COLUMN 10: First author (for monographs)
// Search for first_author
if ($csvColumn[10] !== '') {
$first_author = $csvColumn[10];
}
// write statement for first_author as dc:creator
if ($first_author !== '') {
$data[$itemUri][$nsDc . 'creator'][] = array(
'type' => 'literal',
'value' => $first_author
);
}
// COLUMN 11: Title ID
// Search for title_id
if ($csvColumn[11] !== '') {
$title_id = $csvColumn[11];
}
// write statement for title_id as proprietaryID
if ($title_id !== '') {
$data[$itemUri][$nsAmsl . 'proprietaryID'][] = array(
'type' => 'literal',
'value' => $title_id
);
}
// COLUMN 12: Embargo
// Search for embargo_info
if ($csvColumn[12] !== '') {
$embargo_info = $csvColumn[12];
}
// write statement for embargo_info as embargoInfo
if ($embargo_info !== '') {
$data[$itemUri][$nsAmsl . 'embargoInfo'][] = array(
'type' => 'literal',
'value' => $embargo_info
);
}
// COLUMN 13: Coverage Depth
// Can only have three values: fulltext, selected articles and abstracts - but spelling might vary in different files.
// --> Regex for the first three characters in each value (ful, sel, abs) as they are unique
// Search for coverage depth values in coverage_depth
if ($csvColumn[13] !== '') {
preg_match_all('/(ful)|(sel)|(abs)/i', $csvColumn[13], $coverage_depth) ;
// write statements
if (isset($coverage_depth[0])) {
foreach ($coverage_depth[0] as $value) {
$value = strtolower($value) ;
if ($value == 'ful') {
$data[$itemUri][$nsAmsl . 'coverageDepth'][] = array(
'type' => 'uri',
'value' => $nsAmsl . 'FulltextCoverage'
);
} elseif ($value == 'sel') {
$data[$itemUri][$nsAmsl . 'coverageDepth'][] = array(
'type' => 'uri',
'value' => $nsAmsl . 'SelectedArticlesCoverage'
);
} elseif ($value == 'abs' ) {
$data[$itemUri][$nsAmsl . 'coverageDepth'][] = array(
'type' => 'uri',
'value' => $nsAmsl . 'AbstractCoverage'
);
}
}
}
}
// COLUMN 14: Coverage Note
// Search for coverage_note
if ($csvColumn[14] !== '') {
$coverage_notes = $csvColumn[14];
}
// write statement for coverage_note as coverageNote
if ($coverage_notes !== '') {
$data[$itemUri][$nsAmsl . 'coverageNotes'][] = array(
'type' => 'literal',
'value' => $coverage_notes
);
}
// COLUMN 15: Publisher Name
// Search for publisher_name
if ($csvColumn[15] !== '') {
$publisher_name = $csvColumn[15];
}
// write statement for publisher_name as dc:publisher
if ($publisher_name !== '') {
$data[$itemUri][$nsDc . 'publisher'][] = array(
'type' => 'literal',
'value' => $publisher_name
);
}
// COLUMN 16: item price
if (count($csvColumn) >= 17) {
if (preg_match('/\d+(?:[\.,]\d{1,2})?/',$csvColumn[16],$price)) {
$value = $price[0];
# Check if price contains comma and replace with
# dot if so
if (strpos($value,',')!==FALSE) {
$value = str_replace(',','.',$value);
# Check for missing dot and build a valid price
} else {
if (strpos($value,'.')===FALSE) {
$value.= '.00';
}
}
$data[$itemUri][$nsAmsl . 'itemPrice'][] = array(
'type' => 'literal',
'value' => $value
);
}
}
// END IMPORT