My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
package org.solrmarc.index;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.marc4j.marc.ControlField;
import org.marc4j.marc.DataField;
import org.marc4j.marc.Record;
import org.marc4j.marc.Subfield;

/**
*
* @author Robert Haschart
* @version $Id$
*
*/
public class VuFindIndexer extends SolrIndexer
{

// Initialize logging category
static Logger logger = Logger.getLogger(VuFindIndexer.class.getName());

/**
* Default constructor
* @param propertiesMapFile
* @throws Exception
*/
/*
public VuFindIndexer(final String propertiesMapFile) throws FileNotFoundException, IOException, ParseException
{
super(propertiesMapFile);
}
*/
public VuFindIndexer(final String propertiesMapFile, final String solrMarcDir)
throws FileNotFoundException, IOException, ParseException {
super(propertiesMapFile, solrMarcDir);
}

/**
* Determine Record Format(s)
*
* @param Record record
* @return Set<String> format of record
*/
public Set<String> getFormat(final Record record){
Set<String> result = new LinkedHashSet<String>();
String leader = record.getLeader().toString();
char leaderBit;
ControlField fixedField = (ControlField) record.getVariableField("008");
DataField title = (DataField) record.getVariableField("245");
char formatCode = ' ';

// check if there's an h in the 245
if (title != null) {
if (title.getSubfield('h') != null){
if (title.getSubfield('h').getData().toLowerCase().contains("[electronic resource]")) {
result.add("Electronic");
return result;
}
}
}

// check the 007 - this is a repeating field
List<ControlField> fields = record.getVariableFields("007");
Iterator<ControlField> fieldsIter = fields.iterator();
if (fields != null) {
ControlField formatField;
while(fieldsIter.hasNext()) {
formatField = (ControlField) fieldsIter.next();
formatCode = formatField.getData().toUpperCase().charAt(0);
switch (formatCode) {
case 'A':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'D':
result.add("Atlas");
break;
default:
result.add("Map");
break;
}
break;
case 'C':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'A':
result.add("Tape Cartridge");
break;
case 'B':
result.add("Chip Cartridge");
break;
case 'C':
result.add("Disc Cartridge");
break;
case 'F':
result.add("Tape Cassette");
break;
case 'H':
result.add("Tape Reel");
break;
case 'J':
result.add("Floppy Disk");
break;
case 'M':
case 'O':
result.add("CDROM");
break;
case 'R':
// Do not return - this will cause anything with an
// 856 field to be labeled as "Electronic"
break;
default:
result.add("Software");
break;
}
break;
case 'D':
result.add("Globe");
break;
case 'F':
result.add("Braille");
break;
case 'G':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'C':
case 'D':
result.add("Filmstrip");
break;
case 'T':
result.add("Transparency");
break;
default:
result.add("Slide");
break;
}
break;
case 'H':
result.add("Microfilm");
break;
case 'K':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'C':
result.add("Collage");
break;
case 'D':
result.add("Drawing");
break;
case 'E':
result.add("Painting");
break;
case 'F':
result.add("Print");
break;
case 'G':
result.add("Photonegative");
break;
case 'J':
result.add("Print");
break;
case 'L':
result.add("Drawing");
break;
case 'O':
result.add("Flash Card");
break;
case 'N':
result.add("Chart");
break;
default:
result.add("Photo");
break;
}
break;
case 'M':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'F':
result.add("Video Cassette");
break;
case 'R':
result.add("Filmstrip");
break;
default:
result.add("Motion Picture");
break;
}
break;
case 'O':
result.add("Kit");
break;
case 'Q':
result.add("Musical Score");
break;
case 'R':
result.add("Sensor Image");
break;
case 'S':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'D':
result.add("Sound Disc");
break;
case 'S':
result.add("Sound Cassette");
break;
default:
result.add("Sound Recording");
break;
}
break;
case 'V':
switch(formatField.getData().toUpperCase().charAt(1)) {
case 'C':
result.add("Video Cartridge");
break;
case 'D':
result.add("Video Disc");
break;
case 'F':
result.add("Video Cassette");
break;
case 'R':
result.add("Video Reel");
break;
default:
result.add("Video");
break;
}
break;
}
}
if (!result.isEmpty()) {
return result;
}
}

// check the Leader at position 6
leaderBit = leader.charAt(6);
switch (Character.toUpperCase(leaderBit)) {
case 'C':
case 'D':
result.add("Musical Score");
break;
case 'E':
case 'F':
result.add("Map");
break;
case 'G':
result.add("Slide");
break;
case 'I':
result.add("Sound Recording");
break;
case 'J':
result.add("Music Recording");
break;
case 'K':
result.add("Photo");
break;
case 'M':
result.add("Electronic");
break;
case 'O':
case 'P':
result.add("Kit");
break;
case 'R':
result.add("Physical Object");
break;
case 'T':
result.add("Manuscript");
break;
}
if (!result.isEmpty()) {
return result;
}

// check the Leader at position 7
leaderBit = leader.charAt(7);
switch (Character.toUpperCase(leaderBit)) {
// Monograph
case 'M':
if (formatCode == 'C') {
result.add("eBook");
} else {
result.add("Book");
}
break;
// Serial
case 'S':
// Look in 008 to determine what type of Continuing Resource
formatCode = fixedField.getData().toUpperCase().charAt(21);
switch (formatCode) {
case 'N':
result.add("Newspaper");
break;
case 'P':
result.add("Journal");
break;
default:
result.add("Serial");
break;
}
}

// Nothing worked!
if (result.isEmpty()) {
result.add("Unknown");
}

return result;
}

/**
* Extract the call number label from a record
* @param record
* @return Call number label
*/
public String getCallNumberLabel(final Record record) {

String val = getFirstFieldVal(record, "090a:050a");

if (val != null) {
int dotPos = val.indexOf(".");
if (dotPos > 0) {
val = val.substring(0, dotPos);
}
return val;
} else {
return val;
}
}

/**
* Extract the subject component of the call number
*
* Can return null
*
* @param record
* @return Call number label
*/
public String getCallNumberSubject(final Record record) {

String val = getFirstFieldVal(record, "090a:050a");

if (val != null) {
String [] callNumberSubject = val.split("[^A-Z]+");
return callNumberSubject[0];
} else {
return val;
}
}

/**
* Extract all topics from a record
*
* @param record
* @return
*/
public Set<String> getFullTopic(final Record record) {
Set<String> result = new LinkedHashSet<String>();

result.addAll(getAllSubfields(record, "600"));
result.addAll(getAllSubfields(record, "610"));
result.addAll(getAllSubfields(record, "630"));
result.addAll(getAllSubfields(record, "650"));
return result;
}

/**
* Extract all subject geographic regions from a record
*
* @param record
* @return
*/
public Set<String> getFullGeographic(final Record record) {
Set<String> result = new LinkedHashSet<String>();

result.addAll(getAllSubfields(record, "651"));
return result;
}

/**
* Extract all genres from a record
*
* @param record
* @return
*/
public Set<String> getFullGenre(final Record record) {
Set<String> result = new LinkedHashSet<String>();

result.addAll(getAllSubfields(record, "655"));
return result;
}

/**
* Create a string from the entire 245 field
*
* @param record
* @return
*/
public Set<String> getFullTitle(final Record record) {
return getAllSubfields(record, "245");
}

/**
* Creates individual strings for each iteration of the MARC field designated
* @param Record record The Record object to pull the data from
* @param String marcFieldNum The marc field number as a string (e.g. "245")
* @return
*/
public Set<String> getAllSubfields(final Record record, String marcFieldNum)
{
Set<String> result = new LinkedHashSet<String>();

List<DataField> fields = record.getVariableFields(marcFieldNum);
Iterator<DataField> fieldsIter = fields.iterator();
DataField field;

List<DataField> subfields;
Iterator<DataField> subfieldsIter;
Subfield subfield;

// Loop through fields
while(fieldsIter.hasNext()) {
field = (DataField) fieldsIter.next();

StringBuffer buffer = new StringBuffer("");

// Loop through subfields
subfields = field.getSubfields();
subfieldsIter = subfields.iterator();
while (subfieldsIter.hasNext()) {
subfield = (Subfield) subfieldsIter.next();
if (buffer.length() > 0) {
buffer.append(" " + subfield.getData());
} else {
buffer.append(subfield.getData());
}
}
result.add(buffer.toString());
}

return result;
}

/**
* Loops through all datafields and creates a field for "all fields"
* searching
*
* @param record Marc record to extract data from
*/
public String getAllFields(final Record record)
{
StringBuffer buffer = new StringBuffer("");

List<DataField> fields = record.getDataFields();
Iterator<DataField> fieldsIter = fields.iterator();
DataField field;

List<DataField> subfields;
Iterator<DataField> subfieldsIter;
Subfield subfield;

// Loop through fields
while(fieldsIter.hasNext()) {
field = (DataField) fieldsIter.next();

// Get all fields starting with the 100 and ending with the 839
// This will ignore any "code" fields and only use textual fields
int tag = Integer.parseInt(field.getTag());
if ((tag >= 100) && (tag < 840)) {
// Loop through subfields
subfields = field.getSubfields();
subfieldsIter = subfields.iterator();
while (subfieldsIter.hasNext()) {
subfield = (Subfield) subfieldsIter.next();
if (buffer.length() > 0) {
buffer.append(" " + subfield.getData());
} else {
buffer.append(subfield.getData());
}
}
}
}

return buffer.toString();
}


}

Change log

r149 by asnagy on Aug 28, 2008   Diff
reworked getFormat to allow for multiple
formats as well as expanded number of
formats. Reworked getAllSubfields to
return multiple strings for each iteration
of the field specified
Go to: 
Project members, sign in to write a code review

Older revisions

r127 by asnagy on Aug 14, 2008   Diff
fixed syntax errors
r126 by asnagy on Aug 14, 2008   Diff
fixed getCallNumberLabel method
r107 by asnagy on Aug 4, 2008   Diff
added getFullTitle method
All revisions of this file

File info

Size: 17263 bytes, 510 lines

File properties

svn:keywords
Id
Powered by Google Project Hosting