forked from aretteen/wos2mods
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wos2mods.php
224 lines (181 loc) · 9.6 KB
/
wos2mods.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
//
// CONFIGURABLE VARIABLE
//
// filePath declares where the JSON .txt file is located.
// The easiest configuration is to place the .txt file in the same
// directory as this wos2mods.php file and then just put the
// filename between the quotes.
// Example: $filePath = "WoS_Endnote_12-14-16_OASelections-xlsx.txt";
$filePath = "WOS_FinalDraftSet-xlsx.txt";
////////////////
//
// SCRIPT START
//
//
$jsonFile = file_get_contents("{$filePath}") or die("Could not open JSON File");
$jsonDecoded = json_decode($jsonFile);
foreach($jsonDecoded->rows as $key){
// Start XML Build
$xml = new SimpleXMLElement('<mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:etd="http://www.ndltd.org/standards/metadata/etdms/1.0/" xmlns:flvc="info:flvc/manifest/v1" xsi:schemaLocation="http://www.loc.gov/standards/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd" version="3.4"></mods>');
// Build Title
$newTitle = htmlspecialchars($key->{'Base Title'});
$xml->addChild('titleInfo');
$xml->titleInfo->addAttribute('lang','eng');
if($key->{'Nonsort An'}){
$xml->titleInfo->addChild('nonSort',"An");
$newTitle = trim(substr($newTitle, 2));
}
if($key->{'Nonsort A'}){
$xml->titleInfo->addChild('nonSort',"A");
$newTitle = trim(substr($newTitle, 1));
}
if($key->{'Nonsort The'}){
$xml->titleInfo->addChild('nonSort',"The");
$newTitle = trim(substr($newTitle, 3));
}
$xml->titleInfo->addChild('title', $newTitle);
if($key->Subtitle){
$xml->titleInfo->addChild('subTitle', trim(htmlspecialchars($key->Subtitle)));
}
// Build Author
$authorsExploded = explode("; ", $key->Author);
foreach($authorsExploded as $authorKey){
$brokenDown = explode(", ", $authorKey);
$a = $xml->addChild('name');
$a->addAttribute('type', 'personal');
$a->addAttribute('authority','local');
$a->addChild('namePart',htmlspecialchars($brokenDown[1]))->addAttribute('type','given');
$a->addChild('namePart',htmlspecialchars($brokenDown[0]))->addAttribute('type','family');
$a->addChild('role');
$r1 = $a->role->addChild('roleTerm', 'author');
$r1->addAttribute('authority', 'rda');
$r1->addAttribute('type', 'text');
$r2 = $a->role->addChild('roleTerm', 'aut');
$r2->addAttribute('authority', 'marcrelator');
$r2->addAttribute('type', 'code');
}
// Build originInfo
$xml->addChild('originInfo');
$xml->originInfo->addChild('dateIssued', htmlspecialchars($key->Date));
$xml->originInfo->dateIssued->addAttribute('encoding','w3cdtf');
$xml->originInfo->dateIssued->addAttribute('keyDate','yes');
// Build abstract, if field is not empty
if($key->{'Abstract Note'}){
$xml->addChild('abstract', htmlspecialchars($key->{'Abstract Note'}));
}
// Build identifiers
// IID
$xml->addChild('identifier',$key->IID)->addAttribute('type','IID');
// DOI
if($key->DOI){
$xml->addChild('identifier',$key->DOI)->addAttribute('type','DOI');
}
// Build Related Item
$xml->addChild('relatedItem')->addAttribute('type','host');
$xml->relatedItem->addChild('titleInfo');
$xml->relatedItem->titleInfo->addChild('title', htmlspecialchars($key->{'Publication Title'}));
if($key->ISSN){
$xml->relatedItem->addChild('identifier',$key->ISSN)->addAttribute('type','issn');
}
if($key->Volume || $key->Issue || $key->Pages){
$xml->relatedItem->addChild('part');
if($key->Volume) {
$volXML = $xml->relatedItem->part->addChild('detail');
$volXML->addAttribute('type','volume');
$volXML->addChild('number', htmlspecialchars($key->Volume));
$volXML->addChild('caption','vol.');
}
if($key->Issue) {
$issXML = $xml->relatedItem->part->addChild('detail');
$issXML->addAttribute('type','issue');
$issXML->addChild('number', htmlspecialchars($key->Issue));
$issXML->addChild('caption','iss.');
}
if($key->Pages) {
$pagXML = $xml->relatedItem->part->addChild('extent');
$pagXML->addAttribute('unit','page');
$xml->relatedItem->part->extent->addChild('start', htmlspecialchars($key->Start));
// In this JSON set, not all entries have ends. Data is prepared with Start and End columns based on Open Refine alterations
if($key->End){
$xml->relatedItem->part->extent->addChild('end', htmlspecialchars($key->End));
}
}
}
// Build Notes
if($key->{'Manual Tags'}){
$xml->addChild('note', htmlspecialchars($key->{'Manual Tags'}))->addAttribute('displayLabel','Keywords');
}
if($key->{'Publication note'}){
$xml->addChild('note', htmlspecialchars($key->{'Publication note'}))->addAttribute('displayLabel','Publication Note');
}
// Build FLVC extensions
$flvc = $xml->addChild('extension')->addChild('flvc:flvc', '', 'info:flvc/manifest/v1');
$flvc->addChild('flvc:owningInstitution', 'FSU');
$flvc->addChild('flvc:submittingInstitution', 'FSU');
// Add other static elements
$xml->addChild('typeOfResource', 'text');
$genre = $xml->addChild('genre', 'journal article');
$genre->addAttribute('authority', 'coar');
$genre->addAttribute('authorityURI', 'http://purl.org/coar/resource_type');
$genre->addAttribute('valueURI', 'http://purl.org/coar/resource_type/c_6501');
$xml->addChild('genre', 'text')->addAttribute('authority', 'rdacontent');
$xml->addChild('language');
$l1 = $xml->language->addChild('languageTerm', 'English');
$l1->addAttribute('type', 'text');
$l2 = $xml->language->addChild('languageTerm', 'eng');
$l2->addAttribute('type', 'code');
$l2->addAttribute('authority', 'iso639-2b');
$xml->addChild('physicalDescription');
$rda_media = $xml->physicalDescription->addChild('form', 'computer');
$rda_media->addAttribute('authority', 'rdamedia');
$rda_media->addAttribute('type', 'RDA media terms');
$rda_carrier = $xml->physicalDescription->addChild('form', 'online resource');
$rda_carrier->addAttribute('authority', 'rdacarrier');
$rda_carrier->addAttribute('type', 'RDA carrier terms');
$xml->physicalDescription->addChild('extent', '1 online resource');
$xml->physicalDescription->addChild('digitalOrigin', 'born digital');
$xml->physicalDescription->addChild('internetMediaType', 'application/pdf');
$xml->addChild('recordInfo');
$xml->recordInfo->addChild('recordCreationDate', date('Y-m-d'))->addAttribute('encoding', 'w3cdtf');
$xml->recordInfo->addChild('descriptionStandard', 'rda');
/*
// BUILD PURL
// COMMENT OUT IF USING ISLANDORA ZIP LOADER, WHICH DOES THIS PART ON INGEST
//
$purlLink = "https://purl.lib.fsu.edu/diginole/" . $key->IID;
$xml->addChild('location');
$xml->location->addAttribute('displayLabel','purl');
$xml->location->addChild('url',$purlLink);
*/
//
// CONFIGURABLE VARIABLE
//
// Handle declares where you want the MODS Records to be saved to.
// Make sure you have write permissions for the destination
// Pro-tip: have output go to a Folder, not your desktop! Do not use the foward slash if the file path is relative (Windows).
// Example: $handle = "/output/{$key->IID}.xml";
$handle = "output/{$key->IID}.xml";
//
// WRITE MODS FILE
//
$output = fopen($handle,"w");
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
fwrite($output,$dom->saveXML());
fclose($output);
print "Processed {$key->IID}! <a href=\"file://{$handle}\">View XML</a>";
print "<br>";
} // forEach closing bracket
?>
</body>
</html>