improving extraction of related/variant headings' thesaurus
authorGalen Charlton <gmc@esilibrary.com>
Tue, 10 Jan 2017 20:54:08 +0000 (15:54 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 10 Jan 2017 20:54:08 +0000 (15:54 -0500)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.authority.sql

index ed01132..6feae1a 100644 (file)
@@ -49,15 +49,16 @@ CREATE TABLE authority.heading_field (
     component_xpath TEXT                        NOT NULL,
     type_xpath      TEXT                        NULL, -- to extract related or variant type
     thesaurus_xpath TEXT                        NULL,
+    thesaurus_override_xpath TEXT               NULL,
     joiner          TEXT                        NULL
 );
 
-INSERT INTO authority.heading_field(heading_type, heading_purpose, label, heading_xpath, component_xpath, type_xpath, thesaurus_xpath) VALUES
-( 'topical_term', 'main',    'Main Topical Term',    '/mads21:mads/mads21:authority', '//mads21:topic', NULL, '//mads21:topic[1]/@authority' ),
-( 'topical_term', 'variant', 'Variant Topical Term', '/mads21:mads/mads21:variant',   '//mads21:topic', '/mads21:variant/@type', '//mads21:topic[1]/@authority'),
-( 'topical_term', 'related', 'Broader Topical Term', '/mads21:mads/mads21:related',   '//mads21:topic', '/mads21:related/@type', '//mads21:topic[1]/@authority'),
-( 'personal_name', 'main', 'Main Personal name',     '/mads21:mads/mads21:authority', '//mads21:name', NULL, NULL ),
-( 'personal_name', 'variant', 'Variant Personal name',     '/mads21:mads/mads21:variant', '//mads21:name', NULL, NULL )
+INSERT INTO authority.heading_field(heading_type, heading_purpose, label, heading_xpath, component_xpath, type_xpath, thesaurus_xpath, thesaurus_override_xpath) VALUES
+( 'topical_term', 'main',    'Main Topical Term',    '/mads21:mads/mads21:authority', '//mads21:topic', NULL, '/mads21:mads/mads21:authority/mads21:topic[1]/@authority', NULL ),
+( 'topical_term', 'variant', 'Variant Topical Term', '/mads21:mads/mads21:variant',   '//mads21:topic', '/mads21:variant/@type', '/mads21:mads/mads21:authority/mads21:topic[1]/@authority', '//mads21:topic[1]/@authority'),
+( 'topical_term', 'related', 'Broader Topical Term', '/mads21:mads/mads21:related',   '//mads21:topic', '/mads21:related/@type', '/mads21:mads/mads21:authority/mads21:topic[1]/@authority', '//mads21:topic[1]/@authority'),
+( 'personal_name', 'main', 'Main Personal name',     '/mads21:mads/mads21:authority', '//mads21:name', NULL, NULL, NULL ),
+( 'personal_name', 'variant', 'Variant Personal name',     '/mads21:mads/mads21:variant', '//mads21:name', NULL, NULL, NULL )
 ;
 
 CREATE TYPE authority.heading AS (
@@ -85,6 +86,7 @@ DECLARE
     curr_text   TEXT;
     joiner      TEXT;
     type_value  TEXT;
+    base_thesaurus TEXT := NULL;
     output_row  authority.heading;
 BEGIN
 
@@ -113,6 +115,10 @@ BEGIN
             prev_xfrm := xfrm.name;
         END IF;
 
+        IF idx.thesaurus_xpath IS NOT NULL THEN
+            base_thesaurus := ARRAY_TO_STRING(oils_xpath(idx.thesaurus_xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]), '');
+        END IF;
+
         heading_node_list := oils_xpath( idx.heading_xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
 
         FOR heading_node IN SELECT x FROM unnest(heading_node_list) AS x LOOP
@@ -141,8 +147,11 @@ BEGIN
                 END;
             END IF;
  
-            IF idx.thesaurus_xpath IS NOT NULL THEN
-                output_row.thesaurus =  ARRAY_TO_STRING(oils_xpath(idx.thesaurus_xpath, heading_node, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]), '');
+            IF idx.thesaurus_override_xpath IS NOT NULL THEN
+                output_row.thesaurus := ARRAY_TO_STRING(oils_xpath(idx.thesaurus_override_xpath, heading_node, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]), '');
+            END IF;
+            IF output_row.thesaurus IS NULL THEN
+                output_row.thesaurus := base_thesaurus;
             END IF;
 
             raw_text := NULL;