-
Notifications
You must be signed in to change notification settings - Fork 1
/
mjp2rdf.xsl
415 lines (343 loc) · 15.5 KB
/
mjp2rdf.xsl
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
413
414
415
<?xml version="1.0" encoding="UTF-8"?>
<!--
A set of XSL templates for transforming the METS records produced by
the Modernist Journals Project (the MJP objects) into RDF suitable for ingestion into
ModNets.
REFERENCES: http://wiki.collex.org/index.php/Submitting_RDF
-->
<!-- This stylesheet uses the "pull" method of XSL processing,
because the purpose is to create a conformant Collex document, not to
account for all elements in the MJP MODS record. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mjp="http://modjourn.org/schema#"
xmlns:mets="http://www.loc.gov/METS/" xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/" xmlns:collex="http://www.collex.org/schema#"
xmlns:role="http://www.loc.gov/loc.terms/relators/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs mods" version="2.0">
<xsl:output indent="yes"/>
<!--
GLOBAL DECLARATIONS
-->
<!-- Collex REQUIRES "a shorthand reference to the contributing project or journal." -->
<xsl:variable name="project-id" as="xs:string">mjp</xsl:variable>
<!-- Update (1/25/2015): We're now supplying a journal-specific collex:archive value (see below) -->
<!-- Collex REQUIRES one or more federation ids. An authorized string for ModNets would be nice
but this will do for now. -->
<xsl:variable name="federation-id" as="xs:string">ModNets</xsl:variable>
<!-- Collex REQUIRES one or more disciplines. These are not terribly well defined; for
now, Literature seems to be the only one universally applicable to MJP materials. -->
<xsl:variable name="disciplines">
<disciplines>
<discipline>Literature</discipline>
</disciplines>
</xsl:variable>
<!--
TEMPLATES
-->
<xsl:template match="/">
<!-- The top-level RDF element is REQUIRED. -->
<rdf:RDF>
<xsl:apply-templates/>
</rdf:RDF>
</xsl:template>
<!--
The MJP library contains resources of the following types:
text.periodicals.issue
text.biographies
image
text.essays
collection
text.indexes
text.books
text.periodicals
text
Each requies a different kind of RDF.
-->
<!--
Periodical Issues (text.periodicals.issue)
-->
<xsl:template match="mets:mets[@TYPE='text.periodicals.issue']">
<!-- An element with an rdf:about element is REQUIRED.
The spec says it should be an arbitrary element in the
project's namespace. -->
<xsl:variable name="objid" select="@OBJID"/>
<mjp:Description rdf:about="http://modjourn.org/{@OBJID}">
<xsl:apply-templates select="//mods:mods">
<xsl:with-param name="objid" select="@OBJID"/>
</xsl:apply-templates>
</mjp:Description>
<!-- Generate an RDF object for each issue constituent. -->
<xsl:for-each select="//mods:mods/mods:relatedItem[@type='constituent']">
<!-- The MJP does not assign IDs to relatedItems (it should)
so we must construct a unique id for the relatedItem
from its position in the sequence of relatedItems. -->
<mjp:Description rdf:about="http://modjourn.org/{$objid}#{position()}">
<dcterms:isPartOf rdf:resource="http://modjourn.org/{$objid}"/>
<xsl:apply-templates select=".">
<xsl:with-param name="objid" select="$objid"/>
</xsl:apply-templates>
</mjp:Description>
</xsl:for-each>
</xsl:template>
<xsl:template match="mods:mods">
<xsl:param name="objid"/>
<!-- One or more <collex:federation> elements are REQUIRED. -->
<collex:federation>
<xsl:value-of select="$federation-id"/>
</collex:federation>
<!-- A SINGLE <collex:archive> element is REQUIRED. -->
<collex:archive>
<!-- <xsl:value-of select="$project-id"/> -->
<xsl:value-of select="mjp:archive-id(mods:identifier[@type='local'])" />
</collex:archive>
<!-- A SINGLE <dc:title> element is REQUIRED. -->
<!--Some issues may have more than one title element; use the
first one. -->
<dc:title>
<xsl:apply-templates select="mods:titleInfo[1]"/>
</dc:title>
<!-- ONE OR MORE <dc:type> elements are REQUIRED. We determine
the dc:type from the mods:genre; NB that the mods:genre
element is also used to determine the collex:genre. -->
<dc:type>
<xsl:apply-templates select="mods:genre"/>
</dc:type>
<!-- ONE OR MORE <role:*> elements are REQUIRED. The MJP does not
presently record roles (like editor) for top-level titles, volumes, or issues. -->
<xsl:choose>
<xsl:when test="mods:name">
<xsl:apply-templates select="mods:name"/>
</xsl:when>
<xsl:otherwise><role:AUT>Unknown</role:AUT></xsl:otherwise>
</xsl:choose>
<!-- One or more <collex:discipline> elements are REQUIRED. -->
<xsl:for-each select="$disciplines/disciplines/discipline">
<collex:discipline>
<xsl:value-of select="current()"/>
</collex:discipline>
</xsl:for-each>
<!-- ONE OR MORE <collex:genre> elements are REQUIRED. -->
<xsl:apply-templates select="mods:genre" mode="collex-genre"/>
<!-- ONE OR MORE <dc:date> elements are REQUIRED. -->
<dc:date>
<xsl:value-of select="mods:originInfo/mods:dateIssued[@keyDate='yes']"/>
</dc:date>
<!-- ONE <rdfs:seeAlso> element with the URL of the resource is REQUIRED.
We write a function, mjp:object-URL(), that returns this URL. -->
<rdfs:seeAlso>
<xsl:attribute name="rdf:resource" select="mjp:object-URL($objid)"/>
</rdfs:seeAlso>
<!-- END OF REQUIRED ELEMENTS -->
<!-- Generate a <collex:source_xml> element that points to the TEI file
associated with this object. Unfortunately, that file is not represented in the
fileSec of the METS. Fortunately, there is a naming convention: the
TEI derivative is named MJPID.tei.xml, where MJPID is the ID of the MODS record,
so we write a function, mjp:tei-URL() that returns a URL. -->
<collex:source_xml>
<xsl:value-of select="mjp:tei-URL(@ID)"/>
</collex:source_xml>
<!-- MODS constituents are represented as explicit resources (objects).
In the parent (issue) object, their relationship with the parent object
is represented with <dcterms:hasPart> elements. -->
<xsl:for-each select="mods:relatedItem[@type='constituent']">
<dcterms:hasPart rdf:resource="http://modjourn.org/{$objid}#{position()}"/>
</xsl:for-each>
</xsl:template>
<!-- This template converts a mods:titleInfo element into a formatted string.
The complete format is the following: NonSort Title: Subtitle (Part) -->
<xsl:template match="mods:titleInfo">
<xsl:variable name="nonSort">
<xsl:choose>
<xsl:when test="mods:nonSort">
<xsl:value-of select="concat(mods:nonSort/text(), ' ')"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="title">
<xsl:value-of select="mods:title[1]/text()"/>
</xsl:variable>
<xsl:variable name="subTitle">
<xsl:choose>
<xsl:when test="mods:subTitle">
<xsl:value-of select="concat(': ', mods:subTitle[1]/text())"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="part">
<xsl:choose>
<xsl:when test="mods:partNumber">
<xsl:value-of select="concat(' (',mods:partNumber[1]/text(),')')"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat($nonSort,$title,$subTitle,$part)"/>
</xsl:template>
<xsl:template match="mods:genre[@authority='aat' or @authority='marcgt']">
<!-- <dc:type> is poorly implemented in Collex.
For purposes of ingestion into Collex, we identify
magazine issues as Collections and the contents of
issues as Periodical. -->
<xsl:choose>
<xsl:when test="./text() = 'periodicals'">
<xsl:text>Collection</xsl:text>
</xsl:when>
<xsl:otherwise>Periodical</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- We need a default for the genre of *all* constituent content;
the only reasonable value is Periodical. -->
<xsl:template match="mods:genre">
<xsl:text>Periodical</xsl:text>
</xsl:template>
<xsl:template match="mods:genre" mode="collex-genre">
<collex:genre>
<xsl:choose>
<xsl:when test="./text() = 'periodicals'">
<xsl:text>Collection</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'articles'">
<xsl:text>Nonfiction</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'advertisements'">
<xsl:text>Ephemera</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'letters'">
<xsl:text>Correspondence</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'poetry'">
<xsl:text>Poetry</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'fiction'">
<xsl:text>Fiction</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'drama'">
<xsl:text>Drama</xsl:text>
</xsl:when>
<xsl:when test="./text() = 'images'">
<xsl:text>Visual Art</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Unspecified</xsl:text>
</xsl:otherwise>
</xsl:choose>
</collex:genre>
</xsl:template>
<xsl:template match="mods:name">
<!-- ARC has a fixed set of elements to denote roles. -->
<!-- The MJP data occasionally uses namePart[@type='date'] and
namePart[@type='termsOfAddress'] but mostly uses untyped
nameParts (no 'given' or 'family'). We pluck out the
untyped namePart for the RDF. -->
<!-- MJP data is somewhat dirty. There are <mods:name>
elements with <mods:role> subelements but no
<mods:namePart> element. We have to check for this.-->
<xsl:if test="mods:namePart[empty(@type)]">
<xsl:variable name="name">
<xsl:apply-templates select="mods:namePart[empty(@type)]" />
</xsl:variable>
<xsl:if test="$name">
<xsl:variable name="roleTerm" select="mods:role/mods:roleTerm/text()"/>
<xsl:choose>
<xsl:when test="$roleTerm = 'editor'">
<role:EDT>
<xsl:value-of select="$name"/>
</role:EDT>
</xsl:when>
<xsl:when test="$roleTerm = 'creator'">
<role:CRE>
<xsl:value-of select="$name"/>
</role:CRE>
</xsl:when>
<xsl:when test="$roleTerm = 'translator'">
<role:TRL>
<xsl:value-of select="$name"/>
</role:TRL>
</xsl:when>
<xsl:when test="$roleTerm='art'">
<role:ART>
<xsl:value-of select="$name"/>
</role:ART>
</xsl:when>
<xsl:otherwise> <!-- Default to "contributor" -->
<role:CTB>
<xsl:value-of select="$name"/>
</role:CTB>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:function name="mjp:object-URL">
<xsl:param name="objid" as="xs:string"/>
<xsl:value-of
select="concat('http://modjourn.org/render.php?id=', $objid,'&', 'view=mjp_object')"
/>
</xsl:function>
<xsl:function name="mjp:tei-URL">
<xsl:param name="modsid" as="xs:string"/>
<xsl:value-of select="concat('http://dl.lib.brown.edu/mjp/teifiles/', $modsid, '.tei.xml')"
/>
</xsl:function>
<xsl:function name="mjp:archive-id">
<xsl:param name="mjpid" as="xs:string" />
<xsl:value-of select="concat('mjp_', substring-before($mjpid, ':'))" />
</xsl:function>
<!-- Template for processing issue constituents. There's a good
deal of overlap with the mods:mods template, so some code
refactoring needs to be done. -->
<xsl:template match="mods:relatedItem[@type='constituent']">
<xsl:param name="objid"/>
<!-- One or more <collex:federation> elements are REQUIRED. -->
<collex:federation>
<xsl:value-of select="$federation-id"/>
</collex:federation>
<!-- A SINGLE <collex:archive> element is REQUIRED. -->
<collex:archive>
<!-- <xsl:value-of select="$project-id"/> -->
<xsl:value-of select="mjp:archive-id(ancestor::mods:mods/mods:identifier[@type='local'])" />
</collex:archive>
<!-- A SINGLE <dc:title> element is REQUIRED. -->
<dc:title>
<xsl:choose>
<xsl:when test="mods:titleInfo[1]">
<xsl:apply-templates select="mods:titleInfo[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>[untitled]</xsl:text>
</xsl:otherwise>
</xsl:choose>
</dc:title>
<!-- One or more <dc:type> elements are REQUIRED. -->
<dc:type>
<xsl:apply-templates select="mods:genre"/>
</dc:type>
<!-- One or more <role:*> elements are REQUIRED. The MJP does not
presently record roles (like editor) for top-level titles, volumes, or issues.
ARC advises to encode <role:AUT>Unknown</role:AUT> to indicate that the
-->
<xsl:choose>
<xsl:when test="mods:name and not(empty(mods:name/text()))">
<xsl:apply-templates select="mods:name"/>
</xsl:when>
<xsl:otherwise><role:AUT>Unknown</role:AUT></xsl:otherwise>
</xsl:choose>
<!-- One or more <collex:discipline> elements are REQUIRED. -->
<xsl:for-each select="$disciplines/disciplines/discipline">
<collex:discipline>
<xsl:value-of select="current()"/>
</collex:discipline>
</xsl:for-each>
<!-- One or more <collex:genre> elements are REQUIRED. -->
<xsl:apply-templates select="mods:genre" mode="collex-genre"/>
<!-- One or more <dc:date> elements are REQUIRED. -->
<dc:date>
<xsl:value-of
select="ancestor::mods:mods/mods:originInfo/mods:dateIssued[@keyDate='yes']"/>
</dc:date>
<!-- ONE <rdfs:seeAlso> element with the URL of the resource is REQUIRED. -->
<rdfs:seeAlso>
<xsl:attribute name="rdf:resource" select="mjp:object-URL($objid)"/>
</rdfs:seeAlso>
</xsl:template>
</xsl:stylesheet>