1 // so we can tell if it's a book or other type
2 load_lib('record_type.js');
4 environment.result = {};
6 var marcdoc = new XML(environment.marc);
7 var marc_ns = new Namespace('http://www.loc.gov/MARC21/slim');
9 var modsdoc = new XML(environment.mods);
10 var mods_ns = new Namespace('http://www.loc.gov/mods/');
11 default xml namespace = marc_ns;
13 //var mods3_ns = new Namespace('http://www.loc.gov/mods/v3');
16 var rtype = recordType(marcdoc); // BKS, SER, VIS, MIX, MAP, SCO, REC, COM
23 // first, related items entries (700t)
24 var t = marcdoc.datafield.( @tag == '700' ).subfield.( @code == 't');
25 if (!t.length()) throw "No title in related item added entry (700)";
27 a = t.parent().subfield.( @code == 'a' );
31 log_debug("title: " + t);
32 log_debug("author: " + a);
35 log_debug("Looking in main entries");
40 try { // uniform title
41 _t = marcdoc.datafield.( @tag == '240' ).subfield.( @code == 'a' );
42 if (!_t.length()) throw "No title in 240";
43 } catch(e) { // translation of title
45 _t = marcdoc.datafield.( @tag == '242' ).subfield.( @code == 'a' );
46 if (!_t.length()) throw "No title in 242";
48 } catch(e) { // alternate title (not as note)
50 _t = marcdoc.datafield.( @tag == '246' && !(@ind1.match(/0|1/)) ).subfield.( @code == 'a' );
51 if (!_t.length()) throw "No title in 246";
55 log_debug("Title: " + t);
60 log_debug("Using title proper (245a)");
61 t = marcdoc.datafield.( @tag == '245' ).subfield.( @code == 'a' );
67 var _a = marcdoc.datafield.( @tag == '100' || @tag == '110' || @tag == '111').subfield.( @code == 'a' );
68 if (!_a.length()) throw "No author in 100, 110, 111";
71 log_debug("Author: " + a);
75 log_debug("Trying to find a publisher (260b)");
76 a = marcdoc.datafield.( @tag == '260' ).subfield.( @code == 'b' );
82 quality += marcdoc.datafield.length() / 2;
84 quality += 20 + marcdoc.datafield.length();
89 log_debug("no title found");
92 title = title.toString();
97 .replace(/\[.+?\]/,'')
98 .replace(/\bthe\b|\ban?d?\b|\W+/g,'');
105 author = author.toString();
108 author = author.toLowerCase().replace(/^\s*(\w+).*?$/,"$1");
110 environment.result.fingerprint = title + author;
112 if (marcdoc.datafield.(@tag == '040').subfield.(@code == 'a').toString().match(/DLC/)) {
114 log_debug( 'got DLC bump' );
117 if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/oclc/i)) {
119 log_debug( 'got OCLC source bump' );
121 } else if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/isxn/i)) {
123 log_debug( 'got ISxN source bump' );
125 } else if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/local/i)) {
127 log_debug( 'got Local source bump' );
130 if (extractFixedField(marcdoc, 'Lang') == 'eng') {
132 log_debug( 'got language bump for ' + extractFixedField(marcdoc, 'Lang') );
136 environment.result.quality = quality;