|
| 1 | +xquery version "3.0"; |
| 2 | + |
| 3 | +(: |
| 4 | +: Module Name: MARC/XML BIB 2 BIBFRAME RDF using Saxon |
| 5 | +: |
| 6 | +: Module Version: 1.0 |
| 7 | +: |
| 8 | +: Date: 2012 December 03 |
| 9 | +: |
| 10 | +: Copyright: Public Domain |
| 11 | +: |
| 12 | +: Proprietary XQuery Extensions Used: saxon (Saxon) |
| 13 | +: |
| 14 | +: Xquery Specification: January 2007 |
| 15 | +: |
| 16 | +: Module Overview: Transforms MARC/XML Bibliographic records |
| 17 | +: to RDF conforming to the BIBFRAME model. Outputs RDF/XML, |
| 18 | +: N-triples, or JSON. |
| 19 | +: |
| 20 | +:) |
| 21 | + |
| 22 | +(:~ |
| 23 | +: Transforms MARC/XML Bibliographic records |
| 24 | +: to RDF conforming to the BIBFRAME model. Outputs RDF/XML, |
| 25 | +: N-triples, or JSON. |
| 26 | +: |
| 27 | +: adding holdings capability; allow <marcxml:collection> with multiple records,some holdings, related to bibs on 004 |
| 28 | +
|
| 29 | +: @author Kevin Ford (kefo@loc.gov) |
| 30 | +: @since December 17, 2014 |
| 31 | +: @version 1.0 |
| 32 | +:) |
| 33 | + |
| 34 | +(: IMPORTED MODULES :) |
| 35 | +import module namespace marcbib2bibframe = "info:lc/id-modules/marcbib2bibframe#" at "../modules/module.MARCXMLBIB-2-BIBFRAME.xqy"; |
| 36 | +import module namespace rdfxml2nt = "info:lc/id-modules/rdfxml2nt#" at "../modules/module.RDFXML-2-Ntriples.xqy"; |
| 37 | +import module namespace rdfxml2json = "info:lc/id-modules/rdfxml2json#" at "../modules/module.RDFXML-2-JSON.xqy"; |
| 38 | +import module namespace bfRDFXML2exhibitJSON = "info:lc/bf-modules/bfRDFXML2exhibitJSON#" at "../modules/module.RDFXML-2-ExhibitJSON.xqy"; |
| 39 | +import module namespace RDFXMLnested2flat = "info:lc/bf-modules/RDFXMLnested2flat#" at "../modules/module.RDFXMLnested-2-flat.xqy"; |
| 40 | + |
| 41 | +(: NAMESPACES :) |
| 42 | + |
| 43 | +declare namespace marcxml = "http://www.loc.gov/MARC21/slim"; |
| 44 | +declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; |
| 45 | +declare namespace rdfs = "http://www.w3.org/2000/01/rdf-schema#"; |
| 46 | + |
| 47 | +declare namespace bf = "http://bibframe.org/vocab/"; |
| 48 | +declare namespace madsrdf = "http://www.loc.gov/mads/rdf/v1#"; |
| 49 | +declare namespace relators = "http://id.loc.gov/vocabulary/relators/"; |
| 50 | +declare namespace identifiers = "http://id.loc.gov/vocabulary/identifiers/"; |
| 51 | +declare namespace notes = "http://id.loc.gov/vocabulary/notes/"; |
| 52 | +declare namespace saxon = "http://saxon.sf.net/"; |
| 53 | +declare namespace mods = "http://www.loc.gov/mods/v3"; |
| 54 | +declare option saxon:output "indent=yes"; |
| 55 | + |
| 56 | +(:~ |
| 57 | +: This variable is for the base uri for your Authorites/Concepts. |
| 58 | +: It is the base URI for the rdf:about attribute. |
| 59 | +: |
| 60 | +:) |
| 61 | +declare variable $baseuri as xs:string external :="""http://example.org/"""; |
| 62 | + |
| 63 | +(:~ |
| 64 | +: This variable determines whether bnodes should identify resources instead of |
| 65 | +: http URIs, except for the "main" Work derived from each MARC record. At this time, |
| 66 | +: the "main" Work must be identified by HTTP URI (using the $baseuri variable |
| 67 | +: above). |
| 68 | +: |
| 69 | +:) |
| 70 | +declare variable $usebnodes as xs:string external := """false"""; |
| 71 | + |
| 72 | +(:~ |
| 73 | +: This variable is for the MARCXML location - externally defined. |
| 74 | +:) |
| 75 | +declare variable $marcxmluri as xs:string external := """NONE"""; |
| 76 | + |
| 77 | +(:~ |
| 78 | +: This variable is for desired serialzation. Expected values are: rdfxml (default), ntriples, json |
| 79 | +:) |
| 80 | +declare variable $serialization as xs:string external := """rdfxml"""; |
| 81 | + |
| 82 | +let $marcxml := |
| 83 | + if ($marcxmluri ne "NONE") then |
| 84 | + fn:doc($marcxmluri)//marcxml:record |
| 85 | + else |
| 86 | + (://marcxml:record ??? :) |
| 87 | + () |
| 88 | +(:let $mods:= fn:doc($marcxmluri)//mods:mods:) |
| 89 | + |
| 90 | +let $usebnodes:= if ($usebnodes="") then "false" else $usebnodes |
| 91 | + |
| 92 | +let $resources := |
| 93 | + (:for $r in $marcxml:) |
| 94 | + ( for $r in $marcxml[@type="Bibliographic" or fn:not(@type)] |
| 95 | + |
| 96 | + let $controlnum := xs:string($r/marcxml:controlfield[@tag eq "001"][1]) |
| 97 | + let $holds:= |
| 98 | + for $hold in $marcxml[fn:string(marcxml:controlfield[@tag="004"])=$controlnum] |
| 99 | + return $hold |
| 100 | + |
| 101 | + let $httpuri := fn:concat($baseuri , $controlnum) |
| 102 | + let $recordset:= element marcxml:collection{$r,$holds} |
| 103 | + let $bibframe := marcbib2bibframe:marcbib2bibframe($recordset,$httpuri) |
| 104 | + return $bibframe/child::node()[fn:name()] |
| 105 | + (: , |
| 106 | + for $r in $mods |
| 107 | + let $controlnum := xs:string($r//mods:recordIdentifier[1]) |
| 108 | + let $httpuri := fn:concat($baseuri , $controlnum) |
| 109 | + return marcbib2bibframe:modsbib2bibframe(element mods:collection{$r}):) |
| 110 | + ) |
| 111 | +let $rdfxml-raw := |
| 112 | + element rdf:RDF { |
| 113 | + $resources |
| 114 | + } |
| 115 | + |
| 116 | +let $rdfxml := |
| 117 | + if ( $serialization ne "rdfxml-raw" ) then |
| 118 | + RDFXMLnested2flat:RDFXMLnested2flat($rdfxml-raw, $baseuri, $usebnodes) |
| 119 | + else |
| 120 | + $rdfxml-raw |
| 121 | + |
| 122 | +let $response := |
| 123 | + if ($serialization eq "ntriples") then |
| 124 | + rdfxml2nt:rdfxml2ntriples($rdfxml) |
| 125 | + else if ($serialization eq "json") then |
| 126 | + rdfxml2json:rdfxml2json($rdfxml) |
| 127 | + else if ($serialization eq "exhibitJSON") then |
| 128 | + bfRDFXML2exhibitJSON:bfRDFXML2exhibitJSON($rdfxml, $baseuri) |
| 129 | + else |
| 130 | + $rdfxml |
| 131 | + |
| 132 | +return $response |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
0 commit comments