]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/backend/catalog/biblio_fingerprint.js
beginings of the fingerprinting script
[Evergreen.git] / Open-ILS / src / javascript / backend / catalog / biblio_fingerprint.js
1 //var marcdoc = new XML(environment.marc);
2 //var marc_ns = new Namespace('http://www.loc.gov/MARC21/slim');
3
4 var modsdoc = new XML(environment.mods);
5 var mods_ns = new Namespace('http://www.loc.gov/mods/');
6
7 //var mods3_ns = new Namespace('http://www.loc.gov/mods/v3');
8
9 default xml namespace = mods_ns;
10
11 var t = null;
12
13 function extract_typed_title( ti ) {
14         log_debug(ti.toString());
15
16         return  ti.(hasOwnProperty("@type") && @type == 'uniform')[0] ||
17                 ti.(hasOwnProperty("@type") && @type == 'translated')[0] ||
18                 ti.(hasOwnProperty("@type") && @type == 'alternative')[0];
19 }
20
21 function extract_author( au ) {
22         log_debug(au.toString());
23
24         if ( au..role.length > 0 ) au = au.(role.text == 'creator' || role.text == 'author');
25         
26         if ( au.(hasOwnProperty("@type")) ) {
27                 au = au.(@type == 'personal')[0] ||
28                         au.(@type == 'corporate')[0] ||
29                         au.(@type == 'conference')[0];
30         }
31
32         return au ? au.namePart[0] : '';
33 }
34
35 log_debug("typeOfResource is " + modsdoc.typeOfResource);
36
37 var quality = 0;
38
39 // Treat non-text differently
40 if (modsdoc.typeOfResource != 'text') {
41         quality = 10;
42
43         // Look in related items for a good title
44         for ( var index in modsdoc.relatedItem.( /^(?:host)|(?:series)$/.test(@type) ) ) {
45                 var ri = modsdoc.relatedItem[index];
46                 if ( ri.(!hasOwnProperty("@type") )) {
47                         t = extract_typed_title( ti.titleInfo.(hasOwnProperty('@type')) );
48                         if (!t) {
49                                 t = ri.titleInfo[0];
50                                 quality += 10;
51                         } else {
52                                 quality += 15;
53                         }
54                 }
55
56                 if (t != null) {
57                         log_debug('Found ['+modsdoc.typeOfResource+'] related titleInfo node: ' + t.toXMLString());
58                         break;
59                 }
60         }
61
62         // Couldn't find a usable title in a related item
63         if (t == null) {
64                 t = extract_typed_title( modsdoc.titleInfo.(hasOwnProperty('@type')) );
65                 if (!t) {
66                         t = modsdoc.titleInfo[0];
67                         quality += 5;
68                 } else {
69                         quality += 10;
70                 }
71         }
72
73         log_debug('Found ['+modsdoc.typeOfResource+'] main titleInfo node: ' + t.toXMLString());
74
75 } else {
76         quality = 20;
77
78         if (modsdoc.titleInfo.(hasOwnProperty('@type')))
79                 t = extract_typed_title( modsdoc.titleInfo );
80
81         if (t == null) {
82                 t = modsdoc.titleInfo[0];
83                 quality += 15;
84         } else {
85                 quality += 10;
86         }
87
88         log_debug('Found ['+modsdoc.typeOfResource+'] main titleInfo node: ' + t.toXMLString());
89 }
90
91 var title = t.title
92         .toLowerCase()
93         .replace(/\[.+?\]/,'')
94         .replace(/\bthe\b|\ban?d?\b|\W+/g,'');
95
96
97 var author = (
98         ( modsdoc.typeOfResource != 'text' ?
99                 extract_author(modsdoc.relatedItem.name) :
100                 extract_author(modsdoc.name) ) ||
101         ''
102 ).toLowerCase().replace(/^\s*(\w+).*?$/,"$1");
103
104 result.fingerprint = title + author;
105 result.quality = '' + quality;
106