Here's a query that catalogers will love! It leverages Library of Congress Classification numbers from MARCXML records to create subject facets. We used this for a discovery portal for digitized theology books. (This application is not live yet, but I'll add the link when it is.)
We got the idea for this query from Kurt Cagle's example which makes an XQuery typeswitch expression more like a traditional switch. Each LC class is turned into a temporary element to get the typeswitch to work. The end result is a new class element with a value assigned for the subject facet.
Also, This query was refactored and turned into a library module. I'd be glad to share it (thought it was too long for a blog post).
xquery version "1.0-ml"; (: 2/12/11 Query for mapping LCC to subject categories using typeswitch expression. This updated
version includes all of the LCC, not just the B class. :) declare default element namespace "http://www.catalogingfutures.com/ia"; declare namespace m = "http://www.loc.gov/MARC21/slim"; for $meta in xdmp:directory("/xml/")/doc/metadata let $oldNode := $meta/class let $marcMeta :=$meta/marc/m:record let $lcClass := ($marcMeta/m:datafield[@tag=("050", "055", "090")]/m:subfield[@code="a"])[1] let $bsClass := for $classNum in $lcClass where fn:starts-with($lcClass, "BS") return if (fn:number(fn:substring($lcClass, 3, 4)) < 701) then "BS1" else if (fn:number(fn:substring($lcClass, 3, 4)) < 1901) then "BS2" else if (fn:number(fn:substring($lcClass, 3, 4)) > 1900) then "BS3" else () let $bvClass := for $classNum in $lcClass where fn:starts-with($lcClass, "BV") return if (fn:number(fn:substring($lcClass, 3, 4)) < 590) then "BV1" else if (fn:number(fn:substring($lcClass, 3, 4)) < 2000) then "BV2" else if (fn:number(fn:substring($lcClass, 3, 4)) < 3750) then "BV3" else if (fn:number(fn:substring($lcClass, 3, 4)) < 4200) then "BV4" else if (fn:number(fn:substring($lcClass, 3, 4)) < 4485) then "BV5" else if (fn:number(fn:substring($lcClass, 3, 4))
<= 5099) then "BV6" else () let $bxClass := for $classNum in $lcClass where fn:starts-with($lcClass, "BX") return if (fn:number(fn:substring($lcClass, 3, 4)) < 100) then "BX1" else if (fn:number(fn:substring($lcClass, 3, 4)) < 800) then "BX2" else if (fn:number(fn:substring($lcClass, 3, 4)) < 4800) then "BX3" else if (fn:number(fn:substring($lcClass, 3, 4)) <= 9999) then "BX4" else () let $bClass := if (fn:matches($lcClass, "^B\D\d")) then fn:substring($lcClass, 1, 2) else () let $azClass := if ($lcClass) then fn:substring($lcClass, 1, 1) else () let $newClass := ($bsClass, $bvClass, $bxClass, $bClass, $azClass, "Unclassified")[1] where $oldNode = "Unclassified" return for $class in $newClass let $c := element { $class }{} return let $newNode := typeswitch ($c) case $c as element (B) return <class>Philosophy</class> case $c as element (BC) return <class>Logic</class> case $c as element (BD) return <class>Philosophy</class> case $c as element (BF) return <class>Psychology</class> case $c as element (BH) return <class>Aesthetics</class> case $c as element (BJ) return <class>Ethics</class> case $c as element (BL) return <class>Religion</class> case $c as element (BM) return <class>Judaism</class> case $c as element (BP) return <class>Islam</class> case $c as element (BQ) return<class>Buddhism</class> case $c as element (BR) return <class>Church History</class> case $c as element (BS1) return <class>Bibles</class> case $c as element (BS2) return <class>Old Testament</class> case $c as element (BS3) return <class>New Testament</class> case $c as element (BT) return <class>Theology</class> case $c as element (BV1) return <class>Worship</class> case $c as element (BV2) return <class>Ecclesiology</class> case $c as element (BV3) return <class>Missions</class> case $c as element (BV4) return <class>Practical Theology</class> case $c as element (BV5) return <class>Preaching</class> case $c as element (BV6) return <class>Practical Theology</class> case $c as element (BX1) return <class>Ecumenism</class> case $c as element (BX2) return <class>Eastern churches</class> case $c as element (BX3) return <class>Catholic Church</class> case $c as element (BX4) return <class>Protestantism</class> case $c as element (A) return <class>General Works</class> case $c as element (C) return <class>History</class> case $c as element (D) return <class>History</class> case $c as element (E) return <class>History</class> case $c as element (F) return <class>History</class> case $c as element (G) return <class>Geography and Anthropology</class> case $c as element (H) return <class>Social Sciences</class> case $c as element (J) return <class>Political Science</class> case $c as element (K) return <class>Law</class> case $c as element (L) return <class>Education</class> case $c as element (M) return <class>Music</class> case $c as element (N) return <class>Fine Arts</class> case $c as element (P) return <class>Language and Literature</class> case $c as element (Q) return <class>Science</class> case $c as element (R) return <class>Medicine</class> case $c as element (S) return <class>Agriculture</class> case $c as element (T) return <class>Technology</class> case $c as element (U) return <class>Military Science</class> case $c as element (V) return <class>Military Science</class> case $c as element (Z) return <class>Bibliography</class> default $c return <class>Unclassified</class> return xdmp:node-replace($oldNode, $newNode)
Recent Comments