forked from ERM-HD/issnimporter.ontowiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImportSimpleCSV.php
More file actions
146 lines (119 loc) · 5.8 KB
/
ImportSimpleCSV.php
File metadata and controls
146 lines (119 loc) · 5.8 KB
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
<?php
$publication_title = '' ;
$title_id = '' ;
$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: Title ID aka Proprietary ID
// Search for title_id
if ($csvColumn[3] !== '') {
$title_id = $csvColumn[3];
}
// write statement for title_id as proprietaryID
if ($title_id !== '') {
$data[$itemUri][$nsAmsl . 'proprietaryID'][] = array(
'type' => 'literal',
'value' => $title_id
);
}
// COLUMN 4: item price
if (preg_match('/\d+(?:[\.,]\d{1,2})?/',$csvColumn[4],$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