egdb3_13_6
.biblio
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
extract_quality(marc text, best_lang text, best_type text)
Parameters
Name
Type
Mode
marc
text
IN
best_lang
text
IN
best_type
text
IN
Definition
DECLARE qual INT; ldr TEXT; tval TEXT; tval_rec RECORD; bval TEXT; bval_rec RECORD; type_map RECORD; ff_pos RECORD; ff_tag_data TEXT; BEGIN IF marc IS NULL OR marc = '' THEN RETURN NULL; END IF; -- First, the count of tags qual := ARRAY_UPPER(oils_xpath('//*[local-name()="datafield"]', marc), 1); -- now go through a bunch of pain to get the record type IF best_type IS NOT NULL THEN ldr := (oils_xpath('//*[local-name()="leader"]/text()', marc))[1]; IF ldr IS NOT NULL THEN SELECT * INTO tval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'Type' LIMIT 1; -- They're all the same SELECT * INTO bval_rec FROM config.marc21_ff_pos_map WHERE fixed_field = 'BLvl' LIMIT 1; -- They're all the same tval := SUBSTRING( ldr, tval_rec.start_pos + 1, tval_rec.length ); bval := SUBSTRING( ldr, bval_rec.start_pos + 1, bval_rec.length ); -- RAISE NOTICE 'type %, blvl %, ldr %', tval, bval, ldr; SELECT * INTO type_map FROM config.marc21_rec_type_map WHERE type_val LIKE '%' || tval || '%' AND blvl_val LIKE '%' || bval || '%'; IF type_map.code IS NOT NULL THEN IF best_type = type_map.code THEN qual := qual + qual / 2; END IF; FOR ff_pos IN SELECT * FROM config.marc21_ff_pos_map WHERE fixed_field = 'Lang' AND rec_type = type_map.code ORDER BY tag DESC LOOP ff_tag_data := SUBSTRING((oils_xpath('//*[@tag="' || ff_pos.tag || '"]/text()',marc))[1], ff_pos.start_pos + 1, ff_pos.length); IF ff_tag_data = best_lang THEN qual := qual + 100; END IF; END LOOP; END IF; END IF; END IF; -- Now look for some quality metrics -- DCL record? IF ARRAY_UPPER(oils_xpath('//*[@tag="040"]/*[@code="a" and contains(.,"DLC")]', marc), 1) = 1 THEN qual := qual + 10; END IF; -- From OCLC? IF (oils_xpath('//*[@tag="003"]/text()', marc))[1] ~* E'oclo?c' THEN qual := qual + 10; END IF; RETURN qual; END;