hydra-mods 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,500 @@
1
+ require 'active_fedora'
2
+ require 'hydra/datastream/common_mods_index_methods'
3
+
4
+ # @deprecated Leftover app-specific code from Hydrangea or Hydra at Hull. Please use Hydra::Datastream::ModsGenericContent instead.
5
+ module Hydra
6
+ module Datastream
7
+ class ModsImage < ActiveFedora::NokogiriDatastream
8
+ include Hydra::Datastream::CommonModsIndexMethods
9
+
10
+ set_terminology do |t|
11
+ t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
12
+
13
+ t.title_info(:path=>"titleInfo") {
14
+ t.main_title(:path=>"title", :label=>"title")
15
+ t.language(:index_as=>[:facetable],:path=>{:attribute=>"lang"})
16
+ }
17
+
18
+ t.language{
19
+ t.lang_code(:index_as=>[:facetable], :path=>"languageTerm", :attributes=>{:type=>"code"})
20
+ }
21
+ t.abstract
22
+ t.subject {
23
+ t.topic
24
+ }
25
+ t.topic_tag(:index_as=>[:facetable],:path=>"subject", :default_content_path=>"topic")
26
+
27
+ # mods:physicaldescription/mods:extent - used for storing file size in human-readable form.
28
+ t.physical_description(:path => "physicalDescription") {
29
+ t.extent( :path => "extent" )
30
+ }
31
+
32
+ # This is a mods:name. The underscore is purely to avoid namespace conflicts.
33
+ t.name_ {
34
+ # this is a namepart
35
+ t.namePart(:type=>:string, :label=>"generic name")
36
+ # affiliations are great
37
+ t.affiliation
38
+ t.institution(:path=>"affiliation", :index_as=>[:facetable], :label=>"organization")
39
+ t.displayForm
40
+ t.role(:ref=>[:role])
41
+ t.description
42
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
43
+ t.last_name(:path=>"namePart", :attributes=>{:type=>"family"})
44
+ t.first_name(:path=>"namePart", :attributes=>{:type=>"given"}, :label=>"first name")
45
+ t.terms_of_address(:path=>"namePart", :attributes=>{:type=>"termsOfAddress"})
46
+ }
47
+ # lookup :person, :first_name
48
+ t.person(:ref=>:name, :attributes=>{:type=>"personal"}, :index_as=>[:facetable])
49
+ t.organization(:ref=>:name, :attributes=>{:type=>"corporate"}, :index_as=>[:facetable])
50
+ t.conference(:ref=>:name, :attributes=>{:type=>"conference"}, :index_as=>[:facetable])
51
+ t.role {
52
+ t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
53
+ t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
54
+ }
55
+ t.journal(:path=>'relatedItem', :attributes=>{:type=>"host"}) {
56
+ t.title_info(:index_as=>[:facetable],:ref=>[:title_info])
57
+ t.origin_info(:path=>"originInfo") {
58
+ t.publisher
59
+ t.date_issued(:path=>"dateIssued")
60
+ }
61
+ t.issn(:path=>"identifier", :attributes=>{:type=>"issn"})
62
+ t.issue(:path=>"part") {
63
+ t.volume(:path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
64
+ t.level(:path=>"detail", :attributes=>{:type=>"number"}, :default_content_path=>"number")
65
+ t.extent
66
+ t.pages(:path=>"extent", :attributes=>{:unit=>"pages"}) {
67
+ t.start
68
+ t.end
69
+ }
70
+ t.start_page(:proxy=>[:pages, :start])
71
+ t.end_page(:proxy=>[:pages, :end])
72
+ t.publication_date(:path=>"date")
73
+ }
74
+ }
75
+ end
76
+
77
+ # accessor :title, :term=>[:mods, :title_info, :main_title]
78
+
79
+ # Generates an empty Mods Image (used when you call ModsImage.new without passing in existing xml)
80
+ def self.xml_template
81
+ builder = Nokogiri::XML::Builder.new do |xml|
82
+ xml.mods(:version=>"3.3", "xmlns:xlink"=>"http://www.w3.org/1999/xlink",
83
+ "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
84
+ "xmlns"=>"http://www.loc.gov/mods/v3",
85
+ "xsi:schemaLocation"=>"http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-3.xsd") {
86
+ xml.titleInfo(:lang=>"") {
87
+ xml.title
88
+ }
89
+ xml.name(:type=>"personal") {
90
+ xml.namePart(:type=>"given")
91
+ xml.namePart(:type=>"family")
92
+ xml.affiliation
93
+ xml.role {
94
+ xml.roleTerm(:authority=>"marcrelator", :type=>"text")
95
+ }
96
+ }
97
+ xml.typeOfResource
98
+ xml.genre(:authority=>"marcgt")
99
+ xml.language {
100
+ xml.languageTerm(:authority=>"iso639-2b", :type=>"code")
101
+ }
102
+ # mods:physicaldescription/mods:extent - used for storing file size in human-readable form.
103
+ xml.physicalDescription {
104
+ xml.extent
105
+ }
106
+ xml.abstract
107
+ xml.subject {
108
+ xml.topic
109
+ }
110
+ xml.relatedItem(:type=>"host") {
111
+ xml.titleInfo {
112
+ xml.title
113
+ }
114
+ xml.identifier(:type=>"issn")
115
+ xml.originInfo {
116
+ xml.publisher
117
+ xml.dateIssued
118
+ }
119
+ xml.part {
120
+ xml.detail(:type=>"volume") {
121
+ xml.number
122
+ }
123
+ xml.detail(:type=>"number") {
124
+ xml.number
125
+ }
126
+ xml.extent(:unit=>"pages") {
127
+ xml.start
128
+ xml.end
129
+ }
130
+ xml.date
131
+ }
132
+ }
133
+ xml.location {
134
+ xml.url
135
+ }
136
+ }
137
+ end
138
+ return builder.doc
139
+ end
140
+
141
+ # Generates a new Person node
142
+ def self.person_template
143
+ builder = Nokogiri::XML::Builder.new do |xml|
144
+ xml.name(:type=>"personal") {
145
+ xml.namePart(:type=>"family")
146
+ xml.namePart(:type=>"given")
147
+ xml.affiliation
148
+ xml.role {
149
+ xml.roleTerm(:type=>"text")
150
+ }
151
+ }
152
+ end
153
+ return builder.doc.root
154
+ end
155
+
156
+ def self.full_name_template
157
+ builder = Nokogiri::XML::Builder.new do |xml|
158
+ xml.full_name(:type => "personal")
159
+ end
160
+ return builder.doc.root
161
+ end
162
+
163
+ # Generates a new Organization node
164
+ # Uses mods:name[@type="corporate"]
165
+ def self.organization_template
166
+ builder = Nokogiri::XML::Builder.new do |xml|
167
+ xml.name(:type=>"corporate") {
168
+ xml.namePart
169
+ xml.role {
170
+ xml.roleTerm(:authority=>"marcrelator", :type=>"text")
171
+ }
172
+ }
173
+ end
174
+ return builder.doc.root
175
+ end
176
+
177
+ # Generates a new Conference node
178
+ def self.conference_template
179
+ builder = Nokogiri::XML::Builder.new do |xml|
180
+ xml.name(:type=>"conference") {
181
+ xml.namePart
182
+ xml.role {
183
+ xml.roleTerm(:authority=>"marcrelator", :type=>"text")
184
+ }
185
+ }
186
+ end
187
+ return builder.doc.root
188
+ end
189
+
190
+ # Inserts a new contributor (mods:name) into the mods document
191
+ # creates contributors of type :person, :organization, or :conference
192
+ def insert_contributor(type, opts={})
193
+ case type.to_sym
194
+ when :person
195
+ node = Hydra::Datastream::ModsImage.person_template
196
+ nodeset = self.find_by_terms(:person)
197
+ when :organization
198
+ node = Hydra::Datastream::ModsImage.organization_template
199
+ nodeset = self.find_by_terms(:organization)
200
+ when :conference
201
+ node = Hydra::Datastream::ModsImage.conference_template
202
+ nodeset = self.find_by_terms(:conference)
203
+ else
204
+ ActiveFedora.logger.warn("#{type} is not a valid argument for Hydra::Datastream::ModsImage.insert_contributor")
205
+ node = nil
206
+ index = nil
207
+ end
208
+
209
+ unless nodeset.nil?
210
+ if nodeset.empty?
211
+ self.ng_xml.root.add_child(node)
212
+ index = 0
213
+ else
214
+ nodeset.after(node)
215
+ index = nodeset.length
216
+ end
217
+ self.dirty = true
218
+ end
219
+
220
+ return node, index
221
+ end
222
+
223
+ # Remove the contributor entry identified by @contributor_type and @index
224
+ def remove_contributor(contributor_type, index)
225
+ self.find_by_terms( {contributor_type.to_sym => index.to_i} ).first.remove
226
+ self.dirty = true
227
+ end
228
+
229
+ def self.common_relator_terms
230
+ {"aut" => "Author",
231
+ "clb" => "Collaborator",
232
+ "com" => "Compiler",
233
+ "ctb" => "Contributor",
234
+ "cre" => "Creator",
235
+ "edt" => "Editor",
236
+ "ill" => "Illustrator",
237
+ "oth" => "Other",
238
+ "trl" => "Translator",
239
+ }
240
+ end
241
+
242
+ def self.person_relator_terms
243
+ {"aut" => "Author",
244
+ "clb" => "Collaborator",
245
+ "com" => "Compiler",
246
+ "cre" => "Creator",
247
+ "ctb" => "Contributor",
248
+ "edt" => "Editor",
249
+ "ill" => "Illustrator",
250
+ "res" => "Researcher",
251
+ "rth" => "Research team head",
252
+ "rtm" => "Research team member",
253
+ "trl" => "Translator"
254
+ }
255
+ end
256
+
257
+ def self.conference_relator_terms
258
+ {
259
+ "hst" => "Host"
260
+ }
261
+ end
262
+
263
+ def self.organization_relator_terms
264
+ {
265
+ "fnd" => "Funder",
266
+ "hst" => "Host"
267
+ }
268
+ end
269
+
270
+ def self.dc_relator_terms
271
+ {"acp" => "Art copyist",
272
+ "act" => "Actor",
273
+ "adp" => "Adapter",
274
+ "aft" => "Author of afterword, colophon, etc.",
275
+ "anl" => "Analyst",
276
+ "anm" => "Animator",
277
+ "ann" => "Annotator",
278
+ "ant" => "Bibliographic antecedent",
279
+ "app" => "Applicant",
280
+ "aqt" => "Author in quotations or text abstracts",
281
+ "arc" => "Architect",
282
+ "ard" => "Artistic director ",
283
+ "arr" => "Arranger",
284
+ "art" => "Artist",
285
+ "asg" => "Assignee",
286
+ "asn" => "Associated name",
287
+ "att" => "Attributed name",
288
+ "auc" => "Auctioneer",
289
+ "aud" => "Author of dialog",
290
+ "aui" => "Author of introduction",
291
+ "aus" => "Author of screenplay",
292
+ "aut" => "Author",
293
+ "bdd" => "Binding designer",
294
+ "bjd" => "Bookjacket designer",
295
+ "bkd" => "Book designer",
296
+ "bkp" => "Book producer",
297
+ "bnd" => "Binder",
298
+ "bpd" => "Bookplate designer",
299
+ "bsl" => "Bookseller",
300
+ "ccp" => "Conceptor",
301
+ "chr" => "Choreographer",
302
+ "clb" => "Collaborator",
303
+ "cli" => "Client",
304
+ "cll" => "Calligrapher",
305
+ "clt" => "Collotyper",
306
+ "cmm" => "Commentator",
307
+ "cmp" => "Composer",
308
+ "cmt" => "Compositor",
309
+ "cng" => "Cinematographer",
310
+ "cnd" => "Conductor",
311
+ "cns" => "Censor",
312
+ "coe" => "Contestant -appellee",
313
+ "col" => "Collector",
314
+ "com" => "Compiler",
315
+ "cos" => "Contestant",
316
+ "cot" => "Contestant -appellant",
317
+ "cov" => "Cover designer",
318
+ "cpc" => "Copyright claimant",
319
+ "cpe" => "Complainant-appellee",
320
+ "cph" => "Copyright holder",
321
+ "cpl" => "Complainant",
322
+ "cpt" => "Complainant-appellant",
323
+ "cre" => "Creator",
324
+ "crp" => "Correspondent",
325
+ "crr" => "Corrector",
326
+ "csl" => "Consultant",
327
+ "csp" => "Consultant to a project",
328
+ "cst" => "Costume designer",
329
+ "ctb" => "Contributor",
330
+ "cte" => "Contestee-appellee",
331
+ "ctg" => "Cartographer",
332
+ "ctr" => "Contractor",
333
+ "cts" => "Contestee",
334
+ "ctt" => "Contestee-appellant",
335
+ "cur" => "Curator",
336
+ "cwt" => "Commentator for written text",
337
+ "dfd" => "Defendant",
338
+ "dfe" => "Defendant-appellee",
339
+ "dft" => "Defendant-appellant",
340
+ "dgg" => "Degree grantor",
341
+ "dis" => "Dissertant",
342
+ "dln" => "Delineator",
343
+ "dnc" => "Dancer",
344
+ "dnr" => "Donor",
345
+ "dpc" => "Depicted",
346
+ "dpt" => "Depositor",
347
+ "drm" => "Draftsman",
348
+ "drt" => "Director",
349
+ "dsr" => "Designer",
350
+ "dst" => "Distributor",
351
+ "dtc" => "Data contributor ",
352
+ "dte" => "Dedicatee",
353
+ "dtm" => "Data manager ",
354
+ "dto" => "Dedicator",
355
+ "dub" => "Dubious author",
356
+ "edt" => "Editor",
357
+ "egr" => "Engraver",
358
+ "elg" => "Electrician ",
359
+ "elt" => "Electrotyper",
360
+ "eng" => "Engineer",
361
+ "etr" => "Etcher",
362
+ "exp" => "Expert",
363
+ "fac" => "Facsimilist",
364
+ "fld" => "Field director ",
365
+ "flm" => "Film editor",
366
+ "fmo" => "Former owner",
367
+ "fpy" => "First party",
368
+ "fnd" => "Funder",
369
+ "frg" => "Forger",
370
+ "gis" => "Geographic information specialist ",
371
+ "grt" => "Graphic technician",
372
+ "hnr" => "Honoree",
373
+ "hst" => "Host",
374
+ "ill" => "Illustrator",
375
+ "ilu" => "Illuminator",
376
+ "ins" => "Inscriber",
377
+ "inv" => "Inventor",
378
+ "itr" => "Instrumentalist",
379
+ "ive" => "Interviewee",
380
+ "ivr" => "Interviewer",
381
+ "lbr" => "Laboratory ",
382
+ "lbt" => "Librettist",
383
+ "ldr" => "Laboratory director ",
384
+ "led" => "Lead",
385
+ "lee" => "Libelee-appellee",
386
+ "lel" => "Libelee",
387
+ "len" => "Lender",
388
+ "let" => "Libelee-appellant",
389
+ "lgd" => "Lighting designer",
390
+ "lie" => "Libelant-appellee",
391
+ "lil" => "Libelant",
392
+ "lit" => "Libelant-appellant",
393
+ "lsa" => "Landscape architect",
394
+ "lse" => "Licensee",
395
+ "lso" => "Licensor",
396
+ "ltg" => "Lithographer",
397
+ "lyr" => "Lyricist",
398
+ "mcp" => "Music copyist",
399
+ "mfr" => "Manufacturer",
400
+ "mdc" => "Metadata contact",
401
+ "mod" => "Moderator",
402
+ "mon" => "Monitor",
403
+ "mrk" => "Markup editor",
404
+ "msd" => "Musical director",
405
+ "mte" => "Metal-engraver",
406
+ "mus" => "Musician",
407
+ "nrt" => "Narrator",
408
+ "opn" => "Opponent",
409
+ "org" => "Originator",
410
+ "orm" => "Organizer of meeting",
411
+ "oth" => "Other",
412
+ "own" => "Owner",
413
+ "pat" => "Patron",
414
+ "pbd" => "Publishing director",
415
+ "pbl" => "Publisher",
416
+ "pdr" => "Project director",
417
+ "pfr" => "Proofreader",
418
+ "pht" => "Photographer",
419
+ "plt" => "Platemaker",
420
+ "pma" => "Permitting agency",
421
+ "pmn" => "Production manager",
422
+ "pop" => "Printer of plates",
423
+ "ppm" => "Papermaker",
424
+ "ppt" => "Puppeteer",
425
+ "prc" => "Process contact",
426
+ "prd" => "Production personnel",
427
+ "prf" => "Performer",
428
+ "prg" => "Programmer",
429
+ "prm" => "Printmaker",
430
+ "pro" => "Producer",
431
+ "prt" => "Printer",
432
+ "pta" => "Patent applicant",
433
+ "pte" => "Plaintiff -appellee",
434
+ "ptf" => "Plaintiff",
435
+ "pth" => "Patent holder",
436
+ "ptt" => "Plaintiff-appellant",
437
+ "rbr" => "Rubricator",
438
+ "rce" => "Recording engineer",
439
+ "rcp" => "Recipient",
440
+ "red" => "Redactor",
441
+ "ren" => "Renderer",
442
+ "res" => "Researcher",
443
+ "rev" => "Reviewer",
444
+ "rps" => "Repository",
445
+ "rpt" => "Reporter",
446
+ "rpy" => "Responsible party",
447
+ "rse" => "Respondent-appellee",
448
+ "rsg" => "Restager",
449
+ "rsp" => "Respondent",
450
+ "rst" => "Respondent-appellant",
451
+ "rth" => "Research team head",
452
+ "rtm" => "Research team member",
453
+ "sad" => "Scientific advisor",
454
+ "sce" => "Scenarist",
455
+ "scl" => "Sculptor",
456
+ "scr" => "Scribe",
457
+ "sds" => "Sound designer",
458
+ "sec" => "Secretary",
459
+ "sgn" => "Signer",
460
+ "sht" => "Supporting host",
461
+ "sng" => "Singer",
462
+ "spk" => "Speaker",
463
+ "spn" => "Sponsor",
464
+ "spy" => "Second party",
465
+ "srv" => "Surveyor",
466
+ "std" => "Set designer",
467
+ "stl" => "Storyteller",
468
+ "stm" => "Stage manager",
469
+ "stn" => "Standards body",
470
+ "str" => "Stereotyper",
471
+ "tcd" => "Technical director",
472
+ "tch" => "Teacher",
473
+ "ths" => "Thesis advisor",
474
+ "trc" => "Transcriber",
475
+ "trl" => "Translator",
476
+ "tyd" => "Type designer",
477
+ "tyg" => "Typographer",
478
+ "vdg" => "Videographer",
479
+ "voc" => "Vocalist",
480
+ "wam" => "Writer of accompanying material",
481
+ "wdc" => "Woodcutter",
482
+ "wde" => "Wood -engraver",
483
+ "wit" => "Witness"}
484
+ end
485
+
486
+ def self.valid_child_types
487
+ ["data", "supporting file", "profile", "lorem ipsum", "dolor"]
488
+ end
489
+
490
+ def to_solr(solr_doc=Hash.new)
491
+ super(solr_doc)
492
+ solr_doc.merge!(extract_person_full_names)
493
+ solr_doc.merge!(extract_person_organizations)
494
+ solr_doc.merge!(:object_type_facet => "Image")
495
+ solr_doc
496
+ end
497
+
498
+ end
499
+ end
500
+ end