1 // so we can tell if it's a book or other type
2 load_lib('record_type.js');
3 load_lib('JSON_v1.js');
5 environment.result = {};
7 var marcdoc = new XML(environment.marc);
8 var marc_ns = new Namespace('http://www.loc.gov/MARC21/slim');
10 var modsdoc = new XML(environment.mods);
11 var mods_ns = new Namespace('http://www.loc.gov/mods/');
12 default xml namespace = marc_ns;
14 //var mods3_ns = new Namespace('http://www.loc.gov/mods/v3');
17 var rtype = recordType(marcdoc); // BKS, SER, VIS, MIX, MAP, SCO, REC, COM
24 // first, related items entries (700t)
25 var t = marcdoc.datafield.( @tag == '700' ).subfield.( @code == 't');
26 if (!t.length()) throw "No title in related item added entry (700)";
28 a = t.parent().subfield.( @code == 'a' );
32 log_debug("title: " + t);
33 log_debug("author: " + a);
36 log_debug("Looking in main entries");
41 try { // uniform title
42 _t = marcdoc.datafield.( @tag == '240' ).subfield.( @code == 'a' );
43 if (!_t.length()) throw "No title in 240";
44 } catch(e) { // translation of title
46 _t = marcdoc.datafield.( @tag == '242' ).subfield.( @code == 'a' );
47 if (!_t.length()) throw "No title in 242";
49 } catch(e) { // alternate title (not as note)
51 _t = marcdoc.datafield.( @tag == '246' && !(@ind1.match(/0|1/)) ).subfield.( @code == 'a' );
52 if (!_t.length()) throw "No title in 246";
56 log_debug("Title: " + t);
61 log_debug("Using title proper (245a)");
62 t = marcdoc.datafield.( @tag == '245' ).subfield.( @code == 'a' );
68 var _a = marcdoc.datafield.( @tag == '100' || @tag == '110' || @tag == '111').subfield.( @code == 'a' );
69 if (!_a.length()) throw "No author in 100, 110, 111";
72 log_debug("Author: " + a);
76 log_debug("Trying to find a publisher (260b)");
77 a = marcdoc.datafield.( @tag == '260' ).subfield.( @code == 'b' );
83 quality += marcdoc.datafield.length() / 2;
85 quality += 40 + marcdoc.datafield.length();
90 log_debug("no title found");
93 title = title.toString();
98 .replace(/\[.+?\]/,'')
99 .replace(/\bthe\b|\ban?d?\b|\W+/g,'');
106 author = author.toString();
109 author = author.toLowerCase().replace(/^\s*(\w+).*?$/,"$1");
111 environment.result.fingerprint = title + author;
113 if (marcdoc.datafield.(@tag == '040').subfield.(@code == 'a').toString().match(/DLC/)) {
115 log_debug( 'got DLC bump' );
118 if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/oclc/i)) {
120 log_debug( 'got OCLC source bump' );
122 } else if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/isxn/i)) {
124 log_debug( 'got ISxN source bump' );
126 } else if (marcdoc.datafield.(@tag == '039').subfield.(@code == 'b').toString().match(/local/i)) {
128 log_debug( 'got Local source bump' );
131 if (extractFixedField(marcdoc, 'Lang') == 'eng') {
133 log_debug( 'got language bump for ' + extractFixedField(marcdoc, 'Lang') );
137 environment.result.quality = quality;