ld4l-works_rdf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +25 -0
  4. data/.travis.yml +14 -0
  5. data/CHANGES.md +3 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +170 -0
  9. data/Rakefile +2 -0
  10. data/ld4l-works_rdf.gemspec +42 -0
  11. data/lib/ld4l/works_rdf.rb +131 -0
  12. data/lib/ld4l/works_rdf/configuration.rb +41 -0
  13. data/lib/ld4l/works_rdf/models/bibframe/bibframe_identifier.rb +17 -0
  14. data/lib/ld4l/works_rdf/models/bibframe/bibframe_instance.rb +23 -0
  15. data/lib/ld4l/works_rdf/models/bibframe/bibframe_organization.rb +16 -0
  16. data/lib/ld4l/works_rdf/models/bibframe/bibframe_person.rb +16 -0
  17. data/lib/ld4l/works_rdf/models/bibframe/bibframe_place.rb +16 -0
  18. data/lib/ld4l/works_rdf/models/bibframe/bibframe_provider.rb +18 -0
  19. data/lib/ld4l/works_rdf/models/bibframe/bibframe_title.rb +18 -0
  20. data/lib/ld4l/works_rdf/models/bibframe/bibframe_work.rb +16 -0
  21. data/lib/ld4l/works_rdf/models/bibo/bibo_book.rb +19 -0
  22. data/lib/ld4l/works_rdf/models/bibo/bibo_document.rb +14 -0
  23. data/lib/ld4l/works_rdf/models/bibo/vivo_authorship.rb +15 -0
  24. data/lib/ld4l/works_rdf/models/bibo/vivo_book.rb +18 -0
  25. data/lib/ld4l/works_rdf/models/generic_work.rb +13 -0
  26. data/lib/ld4l/works_rdf/models/schema/oclc_schema_book.rb +16 -0
  27. data/lib/ld4l/works_rdf/models/schema/schema_book.rb +23 -0
  28. data/lib/ld4l/works_rdf/models/schema/schema_person.rb +17 -0
  29. data/lib/ld4l/works_rdf/models/schema/schema_publisher.rb +15 -0
  30. data/lib/ld4l/works_rdf/models/work_metadata.rb +212 -0
  31. data/lib/ld4l/works_rdf/services/attempt_generic_metadata_extraction.rb +41 -0
  32. data/lib/ld4l/works_rdf/services/conversion_services/get_rdfxml_from_marcxml.rb +44 -0
  33. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.ErrorCodes.xqy +56 -0
  34. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-MADSRDF.xqy +1702 -0
  35. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-RecordInfoRDF.xqy +216 -0
  36. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-2-BIBFRAME.xqy +140 -0
  37. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-BFUtils.xqy +3287 -0
  38. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-2-BIBFRAME-Shared.xqy +4112 -0
  39. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-Default-2-BF.xqy +61 -0
  40. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-NotatedMusic-2-BF.xqy +105 -0
  41. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-ExhibitJSON.xqy +119 -0
  42. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-JSON.xqy +193 -0
  43. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-Ntriples.xqy +276 -0
  44. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXMLnested-2-flat.xqy +380 -0
  45. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/ml.xqy +239 -0
  46. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/saxon.xqy +134 -0
  47. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba.xqy +359 -0
  48. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba2-0.xqy +249 -0
  49. data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba3-0.xqy +362 -0
  50. data/lib/ld4l/works_rdf/services/conversion_services/saxon/saxon9he.jar +0 -0
  51. data/lib/ld4l/works_rdf/services/get_metadata_from_marcxml_uri.rb +43 -0
  52. data/lib/ld4l/works_rdf/services/get_metadata_from_oclc_uri.rb +25 -0
  53. data/lib/ld4l/works_rdf/services/get_metadata_from_solr_query.rb +29 -0
  54. data/lib/ld4l/works_rdf/services/get_metadata_from_vivo_uri.rb +25 -0
  55. data/lib/ld4l/works_rdf/services/get_model_from_uri.rb +62 -0
  56. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibframe_models.rb +60 -0
  57. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibo_model.rb +42 -0
  58. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_generic_model.rb +41 -0
  59. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_oclc_model.rb +42 -0
  60. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb +67 -0
  61. data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_vivo_model.rb +45 -0
  62. data/lib/ld4l/works_rdf/services/metadata_services/set_error_in_metadata.rb +27 -0
  63. data/lib/ld4l/works_rdf/services/model_services/populate_bibframe_models_from_repository.rb +46 -0
  64. data/lib/ld4l/works_rdf/services/model_services/populate_generic_model_from_repository.rb +30 -0
  65. data/lib/ld4l/works_rdf/services/model_services/populate_oclc_model_from_repository.rb +27 -0
  66. data/lib/ld4l/works_rdf/services/model_services/populate_vivo_model_from_repository.rb +27 -0
  67. data/lib/ld4l/works_rdf/services/negotiation_services/get_marcxml_from_uri.rb +35 -0
  68. data/lib/ld4l/works_rdf/services/negotiation_services/get_rdfxml_from_uri.rb +37 -0
  69. data/lib/ld4l/works_rdf/services/negotiation_services/get_solr_results_from_solr_query.rb +35 -0
  70. data/lib/ld4l/works_rdf/services/negotiation_services/get_turtle_from_uri.rb +37 -0
  71. data/lib/ld4l/works_rdf/services/negotiation_services/response_header.rb +51 -0
  72. data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_rdfxml.rb +22 -0
  73. data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_turtle.rb +21 -0
  74. data/lib/ld4l/works_rdf/services/repository_services/populate_repository_from_graph.rb +25 -0
  75. data/lib/ld4l/works_rdf/version.rb +5 -0
  76. data/lib/ld4l/works_rdf/vocab/bf.rb +29 -0
  77. data/lib/ld4l/works_rdf/vocab/bgn.rb +5 -0
  78. data/lib/ld4l/works_rdf/vocab/bibo.rb +10 -0
  79. data/lib/ld4l/works_rdf/vocab/library.rb +6 -0
  80. data/lib/ld4l/works_rdf/vocab/vitro.rb +5 -0
  81. data/lib/ld4l/works_rdf/vocab/vivo.rb +11 -0
  82. data/spec/ld4l/works_rdf/configuration_spec.rb +166 -0
  83. data/spec/ld4l/works_rdf/models/books/vivo_book_rdf_spec.rb +267 -0
  84. data/spec/ld4l/works_rdf/services/get_metadata_from_uri_spec.rb +39 -0
  85. data/spec/ld4l/works_rdf/services/get_model_from_uri_spec.rb +34 -0
  86. data/spec/ld4l/works_rdf_spec.rb +53 -0
  87. data/spec/spec_helper.rb +26 -0
  88. metadata +321 -0
@@ -0,0 +1,41 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class AttemptGenericMetadataExtraction
4
+
5
+ ##
6
+ # Attempt to get metadata from the source of the URI via content negotiation.
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ #
10
+ # @returns an instance of one of the generic work models
11
+ def self.call( uri )
12
+ raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
13
+ uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
14
+
15
+ begin
16
+ turtle = LD4L::WorksRDF::GetTurtleFromURI.call(uri)
17
+ graph = LD4L::WorksRDF::PopulateGraphFromTurtle.call(turtle)
18
+ rescue
19
+ begin
20
+ rdfxml = LD4L::WorksRDF::GetRdfxmlFromURI.call(uri)
21
+ graph = LD4L::WorksRDF::PopulateGraphFromRdfxml.call(rdfxml)
22
+ rescue
23
+ metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to extract metadata as turtle or rdfxml from URI')
24
+ return metadata
25
+ end
26
+ end
27
+
28
+ repository = LD4L::WorksRDF::PopulateRepositoryFromGraph.call(graph) if graph
29
+ metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to populate repository from graph') unless repository
30
+
31
+ model = LD4L::WorksRDF::PopulateGenericModelFromRepository.call(uri,repository) if repository
32
+ metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to populate models from repository') unless model
33
+
34
+ metadata = LD4L::WorksRDF::GetMetadataFromGenericModel.call(uri,model) if model
35
+ metadata
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetRdfxmlFromMarcxml
4
+
5
+ ##
6
+ # Get rdfxml from marcxml
7
+ #
8
+ # @param [String] marcxml to be converted
9
+ #
10
+ # @returns a string holding rdfxml triples
11
+ def self.call( marcxml, baseuri )
12
+ raise ArgumentError, 'marcxml argument must be a non-empty string' unless
13
+ marcxml.kind_of?(String) && marcxml.size > 0
14
+
15
+ marcxml = marcxml.force_encoding('ASCII-8BIT').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
16
+
17
+ # TODO: Where should tmp files be saved? The following puts them in the lib directory
18
+ uuid = SecureRandom.uuid
19
+ rdfxml_file = File.join(File.dirname(__FILE__), "tmp_#{uuid}.rdf")
20
+ marcxml_file = File.join(File.dirname(__FILE__), "tmp_#{uuid}.marcxml")
21
+ File.open(marcxml_file, 'w') { |file| file.write marcxml; file.close }
22
+
23
+ saxon = File.join(File.dirname(__FILE__), 'saxon', 'saxon9he.jar')
24
+ xquery = File.join(File.dirname(__FILE__), 'marc2bibframe', 'xbin', 'saxon.xqy')
25
+
26
+ `java -cp #{saxon} net.sf.saxon.Query #{xquery} marcxmluri=#{marcxml_file} baseuri=#{baseuri} > #{rdfxml_file}`
27
+
28
+ # command = "java -cp #{saxon} net.sf.saxon.Query #{xquery} marcxmluri=#{marcxml_file} baseuri=#{baseuri} > #{rdfxml_file}"
29
+
30
+ rdfxml = ""
31
+ File.open(rdfxml_file, 'r') do |file|
32
+ file.each_line {|line| rdfxml << line }
33
+ end
34
+
35
+ # Delete temporary files
36
+ File.delete(marcxml_file,rdfxml_file)
37
+
38
+ rdfxml
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,56 @@
1
+ xquery version "1.0";
2
+ (:
3
+ : Module Name: Error checks and codes.
4
+ :
5
+ : Module Version: 1.0
6
+ :
7
+ : Date: 2014 Oct 3
8
+ :
9
+ : Copyright: Public Domain
10
+ :
11
+ : Proprietary XQuery Extensions Used: None
12
+ :
13
+ : Xquery Specification: January 2007
14
+ :
15
+ : Module Overview: Check MARC/XML for errors before processing.
16
+ :
17
+ :)
18
+
19
+ (:~
20
+ : Check MARC/XML for errors before processing.
21
+ :
22
+ : @author Kevin Ford (kefo@loc.gov)
23
+ : @author Nate Trail (ntra@loc.gov)
24
+ : @since October 3, 2014
25
+ : @version 1.0
26
+ :)
27
+
28
+ module namespace marcerrors = 'info:lc/id-modules/marcerrors#';
29
+
30
+
31
+ (: NAMESPACES :)
32
+ declare namespace marcxml = "http://www.loc.gov/MARC21/slim";
33
+ declare namespace marcerr = "http://www.loc.gov/MARC21/error";
34
+
35
+ (:~
36
+ : This is the main function. It expects a MARCXML record as input.
37
+ : It check's it for basic errors.
38
+ :
39
+ : @param $marcxml element is the marc record
40
+ :)
41
+ declare function marcerrors:check(
42
+ $marcxml as element(marcxml:record)
43
+ )
44
+ {
45
+ if ( fn:not($marcxml/marcxml:leader) ) then
46
+ fn:error(fn:QName('http://www.loc.gov/MARC21/error', 'marcerr:LEADER001'), 'No leader found.')
47
+
48
+ else if ( fn:not($marcxml/marcxml:controlfield[@tag eq "001"][1]) ) then
49
+ fn:error(fn:QName('http://www.loc.gov/MARC21/error', 'marcerr:CF001001'), 'No 001 found.')
50
+
51
+ else if ( fn:count($marcxml/marcxml:controlfield[@tag eq "001"]) > 1 ) then
52
+ fn:error(fn:QName('http://www.loc.gov/MARC21/error', 'marcerr:CF001002'), 'Multiple 001s found.')
53
+
54
+ else
55
+ ()
56
+ };
@@ -0,0 +1,1702 @@
1
+ xquery version "1.0";
2
+
3
+ (:
4
+ : Module Name: MARCXML to 2MADSRDF
5
+ :
6
+ : Module Version: 1.0
7
+ :
8
+ : Date: 2010 Oct 18
9
+ :
10
+ : Copyright: Public Domain
11
+ :
12
+ : Proprietary XQuery Extensions Used: None
13
+ :
14
+ : Xquery Specification: January 2007
15
+ :
16
+ : Module Overview: Primary purpose is to transform MARCXML
17
+ : authority to MADSRDF. This will result in a verbose
18
+ : MADS/RDF record, and one without any linked relationships.
19
+ :
20
+ : Change Log:
21
+ 2012 Aug 28 Nate Trail added collection for undifferentiated names (008/32='b')
22
+ 2012 Sep 12 Nate Trail added collection for FRBR Work and FRBR Expression, and changed the "may subdivide Geographically" label and name
23
+ 2012 Sep 20 Nate Trail added collection for FRBR Expression for musical arrangements
24
+ 2012 Oct 16 Nate Trail suppressed $6 from labels (880 mapping)
25
+ :)
26
+
27
+ (:~
28
+ : This module transforms a MARCXML authority to MADSRDF. This
29
+ : will result in a verbose MADS/RDF record, and one without any
30
+ : linked relationships.
31
+ :
32
+ : @author Kevin Ford (kefo@loc.gov)
33
+ : @since October 18, 2010
34
+ : @version 1.0
35
+ :)
36
+ module namespace marcxml2madsrdf = "info:lc/id-modules/marcxml2madsrdf#";
37
+
38
+
39
+ (: MODULES :)
40
+ import module namespace marcxml2recordinfo = "info:lc/id-modules/recordInfoRDF#" at "module.MARCXML-2-RecordInfoRDF.xqy";
41
+
42
+
43
+ (: NAMESPACES :)
44
+ declare namespace marcxml = "http://www.loc.gov/MARC21/slim";
45
+ declare namespace madsrdf = "http://www.loc.gov/mads/rdf/v1#";
46
+ declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
47
+ declare namespace owl = "http://www.w3.org/2002/07/owl#";
48
+ declare namespace identifiers = "http://id.loc.gov/vocabulary/identifiers/";
49
+ (:declare namespace xdmp = "http://marklogic.com/xdmp";:)
50
+
51
+
52
+ (: VARIABLES :)
53
+ declare variable $marcxml2madsrdf:authSchemeMap := (
54
+ <authSchemeMaps>
55
+ <authScheme abbrev="subjects">authorities/subjects/</authScheme>
56
+ <authScheme abbrev="childrensSubjects">authorities/childrensSubjects/</authScheme>
57
+ <authScheme abbrev="genreForms">authorities/genreForms/</authScheme>
58
+ <authScheme abbrev="names">authorities/names/</authScheme>
59
+ <authScheme abbrev="empty">authorities/empty/</authScheme>
60
+ </authSchemeMaps>
61
+ );
62
+ (:http://id.loc.gov/authorities/names/no2007025470.marcxml.xml:)
63
+ declare variable $marcxml2madsrdf:authTypeMap := (<authTypeMaps>
64
+ <type tag="100" count="1" code="a" variant="madsrdf:PersonalName">madsrdf:PersonalName</type>
65
+ <type tag="100" count="2" code="cdgq" variant="madsrdf:PersonalName">madsrdf:PersonalName</type>
66
+ <type tag="100" count="2" code="t" variant="madsrdf:NameTitle">madsrdf:NameTitle</type> (: Would title ever not be in the second position? Is it still an NT when there is a third term, a form subdivision? :)
67
+ <type tag="100" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
68
+
69
+ <type tag="110" count="1" code="a" variant="madsrdf:CorporateName">madsrdf:CorporateName</type>
70
+ <type tag="110" count="2" code="bcdg" variant="madsrdf:CorporateName">madsrdf:CorporateName</type>
71
+ <type tag="110" count="2" code="t" variant="madsrdf:NameTitle">madsrdf:NameTitle</type> (: this implies that t is the second component :)
72
+ <type tag="110" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
73
+
74
+ <type tag="111" count="1" code="a" variant="madsrdf:ConferenceName">madsrdf:ConferenceName</type>
75
+ <type tag="111" count="2" code="cdgq" variant="madsrdf:ConferenceName">madsrdf:ConferenceName</type>
76
+ <type tag="111" count="2" code="t" variant="madsrdf:NameTitle">madsrdf:NameTitle</type>
77
+ <type tag="111" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
78
+
79
+ <type tag="130" equivalent="t" count="1" code="a" variant="madsrdf:Title">madsrdf:Title</type> (: UniformTitle - this could have any number of code fields in it :)
80
+ <type tag="130" count="2" code="d" variant="madsrdf:Title">madsrdf:Title</type> (: UniformTitle - this could have any number of code fields in it :)
81
+ <type tag="130" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type> (: UniformTitle - this could have any number of code fields in it :)
82
+
83
+ <type tag="148" equivalent="y" count="1" code="a" variant="madsrdf:Temporal">madsrdf:Temporal</type>
84
+ <type tag="148" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type> (: loads of codes :)
85
+
86
+ <type tag="150" equivalent="x" count="1" code="a" variant="madsrdf:Topic">madsrdf:Topic</type>
87
+ <type tag="150" count="2" code="bvxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
88
+
89
+ <type tag="151" equivalent="z" count="1" code="a" variant="madsrdf:Geographic">madsrdf:Geographic</type>
90
+ <type tag="151" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
91
+
92
+ <type tag="155" equivalent="v" count="1" code="a" variant="madsrdf:GenreForm">madsrdf:GenreForm</type>
93
+ <type tag="155" equivalent="p" count="1" variant="madsrdf:GenreForm">madsrdf:GenreForm</type>
94
+ <type tag="155" count="2" code="vxyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
95
+
96
+ <type tag="180" count="1" code="x" variant="madsrdf:Topic">madsrdf:Topic</type>
97
+ <type tag="180" count="2" code="vyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
98
+
99
+ <type tag="181" count="1" code="z" variant="madsrdf:Geographic">madsrdf:Geographic</type>
100
+ <type tag="181" count="2" code="vxy" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
101
+
102
+ <type tag="182" count="1" code="y" variant="madsrdf:Temporal">madsrdf:Temporal</type>
103
+ <type tag="182" count="2" code="vxz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
104
+
105
+ <type tag="185" count="1" code="v" variant="madsrdf:GenreForm">madsrdf:GenreForm</type>
106
+ <type tag="185" count="2" code="xyz" variant="madsrdf:ComplexSubject">madsrdf:ComplexSubject</type>
107
+ </authTypeMaps>);
108
+
109
+ declare variable $marcxml2madsrdf:elementTypeMap := (
110
+ <elementTypeMaps>
111
+ <elementType tag_suffix="00" code="a">madsrdf:FullNameElement</elementType>
112
+ <elementType tag_suffix="00" code="a" ancillary="d">madsrdf:DateNameElement</elementType>
113
+ <elementType tag_suffix="00" code="a" ancillary="c">madsrdf:TermsOfAddressNameElement</elementType>
114
+ <elementType tag_suffix="00" code="a" ancillary="q">madsrdf:FullNameElement</elementType>
115
+ <elementType tag_suffix="00" code="k">madsrdf:GenreFormElement</elementType>
116
+ <elementType tag_suffix="00" code="t">madsrdf:TitleElement</elementType>
117
+ <elementType tag_suffix="00" code="t" ancillary="k">madsrdf:GenreFormElement</elementType>
118
+ <elementType tag_suffix="00" code="t" ancillary="r">madsrdf:TitleElement</elementType>
119
+ <elementType tag_suffix="00" code="t" ancillary="g">madsrdf:GeographicElement</elementType>
120
+ <elementType tag_suffix="00" code="t" ancillary="d">madsrdf:TemporalElement</elementType>
121
+ <elementType tag_suffix="00" code="t" ancillary="f">madsrdf:TemporalElement</elementType>
122
+ <elementType tag_suffix="00" code="t" ancillary="l">madsrdf:LanguageElement</elementType>
123
+ <elementType tag_suffix="00" code="t" ancillary="m">madsrdf:TitleElement</elementType>
124
+ <elementType tag_suffix="00" code="t" ancillary="n">madsrdf:PartNumberElement</elementType>
125
+ <elementType tag_suffix="00" code="t" ancillary="o">madsrdf:TitleElement</elementType>
126
+ <elementType tag_suffix="00" code="t" ancillary="p">madsrdf:PartNameElement</elementType>
127
+ <elementType tag_suffix="00" code="p">madsrdf:GenreFormElement</elementType>
128
+ <elementType tag_suffix="00" code="v">madsrdf:GenreFormElement</elementType>
129
+ <elementType tag_suffix="00" code="x">madsrdf:TopicElement</elementType>
130
+ <elementType tag_suffix="00" code="y">madsrdf:TemporalElement</elementType>
131
+ <elementType tag_suffix="00" code="z">madsrdf:GeographicElement</elementType>
132
+
133
+ <elementType tag_suffix="10" code="a">madsrdf:NameElement</elementType>
134
+ <elementType tag_suffix="10" code="a" ancillary="b">madsrdf:NameElement</elementType>
135
+ <elementType tag_suffix="10" code="a" ancillary="d">madsrdf:DateNameElement</elementType>
136
+ <elementType tag_suffix="10" code="a" ancillary="k">madsrdf:NamePartElement</elementType>
137
+ <elementType tag_suffix="10" code="t">madsrdf:TitleElement</elementType>
138
+ <elementType tag_suffix="10" code="t" ancillary="r">madsrdf:TitleElement</elementType>
139
+ <elementType tag_suffix="10" code="t" ancillary="k">madsrdf:GenreFormElement</elementType>
140
+ <elementType tag_suffix="10" code="t" ancillary="g">madsrdf:GeographicElement</elementType>
141
+ <elementType tag_suffix="10" code="t" ancillary="d">madsrdf:TemporalElement</elementType>
142
+ <elementType tag_suffix="10" code="t" ancillary="l">madsrdf:LanguageElement</elementType>
143
+ <elementType tag_suffix="10" code="t" ancillary="n">madsrdf:PartNumberElement</elementType>
144
+ <elementType tag_suffix="10" code="t" ancillary="p">madsrdf:PartNameElement</elementType>
145
+ <elementType tag_suffix="10" code="p">madsrdf:GenreFormElement</elementType>
146
+ <elementType tag_suffix="10" code="v">madsrdf:GenreFormElement</elementType>
147
+ <elementType tag_suffix="10" code="x">madsrdf:TopicElement</elementType>
148
+ <elementType tag_suffix="10" code="y">madsrdf:TemporalElement</elementType>
149
+ <elementType tag_suffix="10" code="z">madsrdf:GeographicElement</elementType>
150
+
151
+ <elementType tag_suffix="11" code="a">madsrdf:NameElement</elementType>
152
+ <elementType tag_suffix="11" code="a" ancillary="c">madsrdf:GeographicElement</elementType>
153
+ <elementType tag_suffix="11" code="a" ancillary="d">madsrdf:DateNameElement</elementType>
154
+ <elementType tag_suffix="11" code="a" ancillary="e">madsrdf:NameElement</elementType>
155
+ <elementType tag_suffix="11" code="k">madsrdf:GenreFormElement</elementType>
156
+ <elementType tag_suffix="11" code="t">madsrdf:TitleElement</elementType>
157
+ <elementType tag_suffix="11" code="t" ancillary="k">madsrdf:GenreFormElement</elementType>
158
+ <elementType tag_suffix="11" code="t" ancillary="c">madsrdf:GeographicElement</elementType>
159
+ <elementType tag_suffix="11" code="t" ancillary="d">madsrdf:TemporalElement</elementType>
160
+ <elementType tag_suffix="11" code="t" ancillary="l">madsrdf:LanguageElement</elementType>
161
+ <elementType tag_suffix="11" code="p">madsrdf:GenreFormElement</elementType>
162
+ <elementType tag_suffix="11" code="v">madsrdf:GenreFormElement</elementType>
163
+ <elementType tag_suffix="11" code="x">madsrdf:TopicElement</elementType>
164
+ <elementType tag_suffix="11" code="y">madsrdf:TemporalElement</elementType>
165
+ <elementType tag_suffix="11" code="z">madsrdf:GeographicElement</elementType>
166
+
167
+ <elementType tag_suffix="30" code="a">madsrdf:MainTitleElement</elementType>
168
+ <elementType tag_suffix="30" code="a" ancillary="d">madsrdf:TemporalElement</elementType>
169
+ <elementType tag_suffix="30" code="a" ancillary="f">madsrdf:TemporalElement</elementType>
170
+ <elementType tag_suffix="30" code="a" ancillary="n">madsrdf:PartNumberElement</elementType>
171
+ <elementType tag_suffix="30" code="a" ancillary="p">madsrdf:PartNameElement</elementType>
172
+ <elementType tag_suffix="30" code="a" ancillary="t">madsrdf:TitleElement</elementType>
173
+ <elementType tag_suffix="30" code="a" ancillary="l">madsrdf:LanguageElement</elementType>
174
+ <elementType tag_suffix="30" code="a" ancillary="s">madsrdf:SubTitleElement</elementType>
175
+ <elementType tag_suffix="30" code="a" ancillary="k">madsrdf:GenreFormElement</elementType>
176
+ <elementType tag_suffix="30" code="v">madsrdf:GenreFormElement</elementType>
177
+ <elementType tag_suffix="30" code="x">madsrdf:TopicElement</elementType>
178
+ <elementType tag_suffix="30" code="y">madsrdf:TemporalElement</elementType>
179
+ <elementType tag_suffix="30" code="z">madsrdf:GeographicElement</elementType>
180
+
181
+ <elementType tag_suffix="48" code="a">madsrdf:TemporalElement</elementType>
182
+ <elementType tag_suffix="48" code="v">madsrdf:GenreFormElement</elementType>
183
+ <elementType tag_suffix="48" code="x">madsrdf:TopicElement</elementType>
184
+ <elementType tag_suffix="48" code="y">madsrdf:TemporalElement</elementType>
185
+ <elementType tag_suffix="48" code="z">madsrdf:GeographicElement</elementType>
186
+
187
+ <elementType tag_suffix="50" code="a">madsrdf:TopicElement</elementType>
188
+ <elementType tag_suffix="50" code="a" ancillary="b">madsrdf:TopicElement</elementType>
189
+ <elementType tag_suffix="50" code="v">madsrdf:GenreFormElement</elementType>
190
+ <elementType tag_suffix="50" code="x">madsrdf:TopicElement</elementType>
191
+ <elementType tag_suffix="50" code="y">madsrdf:TemporalElement</elementType>
192
+ <elementType tag_suffix="50" code="z">madsrdf:GeographicElement</elementType>
193
+
194
+ <elementType tag_suffix="51" code="a">madsrdf:GeographicElement</elementType>
195
+ <elementType tag_suffix="51" code="v">madsrdf:GenreFormElement</elementType>
196
+ <elementType tag_suffix="51" code="x">madsrdf:TopicElement</elementType>
197
+ <elementType tag_suffix="51" code="y">madsrdf:TemporalElement</elementType>
198
+ <elementType tag_suffix="51" code="z">madsrdf:GeographicElement</elementType>
199
+
200
+ <elementType tag_suffix="55" code="a">madsrdf:GenreFormElement</elementType>
201
+ <elementType tag_suffix="55" code="v">madsrdf:GenreFormElement</elementType>
202
+ <elementType tag_suffix="55" code="x">madsrdf:TopicElement</elementType>
203
+ <elementType tag_suffix="55" code="y">madsrdf:TemporalElement</elementType>
204
+ <elementType tag_suffix="55" code="z">madsrdf:GeographicElement</elementType>
205
+
206
+ <elementType tag_suffix="80" code="x">madsrdf:TopicElement</elementType>
207
+ <elementType tag_suffix="80" code="v">madsrdf:GenreFormElement</elementType>
208
+ <elementType tag_suffix="80" code="y">madsrdf:TemporalElement</elementType>
209
+ <elementType tag_suffix="80" code="z">madsrdf:GeographicElement</elementType>
210
+
211
+ <elementType tag_suffix="81" code="x">madsrdf:TopicElement</elementType>
212
+ <elementType tag_suffix="81" code="v">madsrdf:GenreFormElement</elementType>
213
+ <elementType tag_suffix="81" code="y">madsrdf:TemporalElement</elementType>
214
+ <elementType tag_suffix="81" code="z">madsrdf:GeographicElement</elementType>
215
+
216
+ <elementType tag_suffix="82" code="x">madsrdf:TopicElement</elementType>
217
+ <elementType tag_suffix="82" code="v">madsrdf:GenreFormElement</elementType>
218
+ <elementType tag_suffix="82" code="y">madsrdf:TemporalElement</elementType>
219
+ <elementType tag_suffix="82" code="z">madsrdf:GeographicElement</elementType>
220
+
221
+ <elementType tag_suffix="85" code="x">madsrdf:TopicElement</elementType>
222
+ <elementType tag_suffix="85" code="v">madsrdf:GenreFormElement</elementType>
223
+ <elementType tag_suffix="85" code="y">madsrdf:TemporalElement</elementType>
224
+ <elementType tag_suffix="85" code="z">madsrdf:GeographicElement</elementType>
225
+ </elementTypeMaps>);
226
+
227
+ declare variable $marcxml2madsrdf:marc2madsMap := (<marc2madsMap>
228
+ <map tag_suffix="00" count="1" subfield="a">
229
+ <authority>madsrdf:PersonalName</authority>
230
+ <variant>madsrdf:PersonalName</variant>
231
+ </map>
232
+ <map tag_suffix="00" count="2" subfield="cdgq">
233
+ <authority>madsrdf:PersonalName</authority>
234
+ <variant>madsrdf:PersonalName</variant>
235
+ </map>
236
+ <map tag_suffix="00" count="2" subfield="t">
237
+ <authority>madsrdf:NameTitle</authority>
238
+ <variant>madsrdf:NameTitle</variant>
239
+ </map>
240
+ <map tag_suffix="00" count="2" subfield="vxyz">
241
+ <authority>madsrdf:ComplexSubject</authority>
242
+ <variant>madsrdf:ComplexSubject</variant>
243
+ </map>
244
+
245
+ <map tag_suffix="10" count="1" subfield="a">
246
+ <authority>madsrdf:CorporateName</authority>
247
+ <variant>madsrdf:CorporateName</variant>
248
+ </map>
249
+ <map tag_suffix="10" count="2" subfield="bcdg">
250
+ <authority>madsrdf:CorporateName</authority>
251
+ <variant>madsrdf:CorporateName</variant>
252
+ </map>
253
+ <map tag_suffix="10" count="2" subfield="t">
254
+ <authority>madsrdf:NameTitle</authority>
255
+ <variant>madsrdf:NameTitle</variant>
256
+ </map>
257
+ <map tag_suffix="10" count="2" subfield="vxyz">
258
+ <authority>madsrdf:ComplexSubject</authority>
259
+ <variant>madsrdf:ComplexSubject</variant>
260
+ </map>
261
+
262
+ <map tag_suffix="11" count="1" subfield="a">
263
+ <authority>madsrdf:ConferenceName</authority>
264
+ <variant>madsrdf:ConferenceName</variant>
265
+ </map>
266
+ <map tag_suffix="11" count="2" subfield="cdgq">
267
+ <authority>madsrdf:ConferenceName</authority>
268
+ <variant>madsrdf:ConferenceName</variant>
269
+ </map>
270
+ <map tag_suffix="11" count="2" subfield="t">
271
+ <authority>madsrdf:NameTitle</authority>
272
+ <variant>madsrdf:NameTitle</variant>
273
+ </map>
274
+ <map tag_suffix="11" count="2" subfield="vxyz">
275
+ <authority>madsrdf:ComplexSubject</authority>
276
+ <variant>madsrdf:ComplexSubject</variant>
277
+ </map>
278
+
279
+ <map tag_suffix="30" count="1" subfield="a" variant_subfield="t"> (: UniformTitle - this could have any number of code fields in it :)
280
+ <authority>madsrdf:Title</authority>
281
+ <variant>madsrdf:Title</variant>
282
+ </map>
283
+ <map tag_suffix="30" count="2" subfield="d"> (: UniformTitle - this could have any number of code fields in it :)
284
+ <authority>madsrdf:Title</authority>
285
+ <variant>madsrdf:Title</variant>
286
+ </map>
287
+ <map tag_suffix="30" count="2" subfield="vxyz"> (: UniformTitle - this could have any number of code fields in it :)
288
+ <authority>madsrdf:ComplexSubject</authority>
289
+ <variant>madsrdf:ComplexSubject</variant>
290
+ </map>
291
+
292
+ <map tag_suffix="48" count="1" subfield="a" variant_subfield="y">
293
+ <authority>madsrdf:Temporal</authority>
294
+ <variant>madsrdf:Temporal</variant>
295
+ </map>
296
+ <map tag_suffix="48" count="2" subfield="vxyz">
297
+ <authority>madsrdf:ComplexSubject</authority>
298
+ <variant>madsrdf:ComplexSubject</variant>
299
+ </map>
300
+
301
+ <map tag_suffix="50" count="1" subfield="a" variant_subfield="x">
302
+ <authority>madsrdf:Topic</authority>
303
+ <variant>madsrdf:Topic</variant>
304
+ </map>
305
+ <map tag_suffix="50" count="2" subfield="bvxyz">
306
+ <authority>madsrdf:ComplexSubject</authority>
307
+ <variant>madsrdf:ComplexSubject</variant>
308
+ </map>
309
+
310
+ <map tag_suffix="51" count="1" subfield="a" variant_subfield="z">
311
+ <authority>madsrdf:Geographic</authority>
312
+ <variant>madsrdf:Geographic</variant>
313
+ </map>
314
+ <map tag_suffix="51" count="2" subfield="vxyz">
315
+ <authority>madsrdf:ComplexSubject</authority>
316
+ <variant>madsrdf:ComplexSubject</variant>
317
+ </map>
318
+
319
+ <map tag_suffix="55" count="1" subfield="a" variant_subfield="vpk">
320
+ <authority>madsrdf:GenreForm</authority>
321
+ <variant>madsrdf:GenreForm</variant>
322
+ </map>
323
+ <map tag_suffix="55" count="2" subfield="vxyz">
324
+ <authority>madsrdf:ComplexSubject</authority>
325
+ <variant>madsrdf:ComplexSubject</variant>
326
+ </map>
327
+
328
+ <map tag_suffix="80" count="1" subfield="x">
329
+ <authority>madsrdf:Topic</authority>
330
+ <variant>madsrdf:Topic</variant>
331
+ </map>
332
+ <map tag_suffix="80" count="2" subfield="vyz">
333
+ <authority>madsrdf:ComplexSubject</authority>
334
+ <variant>madsrdf:ComplexSubject</variant>
335
+ </map>
336
+
337
+ <map tag_suffix="81" count="1" subfield="z">
338
+ <authority>madsrdf:Geographic</authority>
339
+ <variant>madsrdf:Geographical</variant>
340
+ </map>
341
+ <map tag_suffix="81" count="2" subfield="vxy">
342
+ <authority>madsrdf:ComplexSubject</authority>
343
+ <variant>madsrdf:ComplexSubject</variant>
344
+ </map>
345
+
346
+ <map tag_suffix="82" count="1" subfield="y">
347
+ <authority>madsrdf:Temporal</authority>
348
+ <variant>madsrdf:Temporal</variant>
349
+ </map>
350
+ <map tag_suffix="82" count="2" subfield="vxz">
351
+ <authority>madsrdf:ComplexSubject</authority>
352
+ <variant>madsrdf:ComplexSubject</variant>
353
+ </map>
354
+
355
+ <map tag_suffix="85" count="1" subfield="v">
356
+ <authority>madsrdf:GenreForm</authority>
357
+ <variant>madsrdf:GenreForm</variant>
358
+ </map>
359
+ <map tag_suffix="85" count="2" subfield="yxz">
360
+ <authority>madsrdf:ComplexSubject</authority>
361
+ <variant>madsrdf:ComplexSubject</variant>
362
+ </map>
363
+
364
+ </marc2madsMap>);
365
+
366
+ declare variable $marcxml2madsrdf:noteTypeMap := (
367
+ <noteTypeMaps>
368
+ <type tag="667">madsrdf:editorialNote</type>
369
+ <type tag="678">madsrdf:note</type>
370
+ <type tag="680">madsrdf:note</type>
371
+ <type tag="681">madsrdf:exampleNote</type>
372
+ <type tag="682">madsrdf:changeNote</type>
373
+ <type tag="688">madsrdf:historyNote</type>
374
+ </noteTypeMaps>);
375
+
376
+
377
+ declare variable $marcxml2madsrdf:relationTypeMap := (
378
+ <relationTypeMaps>
379
+ <type tag_prefix="5" pos="1" w="a">madsrdf:hasEarlierEstablishedForm</type>
380
+ <type tag_prefix="5" pos="1" w="b">madsrdf:hasLaterEstablishedForm</type>
381
+ <type tag_prefix="5" pos="1" w="d">madsrdf:hasAcronymVariant</type>
382
+ <type tag_suffix="5" pos="1" w="g">madsrdf:hasBroaderAuthority</type>
383
+ <type tag_suffix="5" pos="1" w="h">madsrdf:hasNarrowerAuthority</type>
384
+ <type tag_prefix="5" pos="1" w="_">madsrdf:hasRelation</type>
385
+
386
+ <type tag_prefix="5" pos="2" w="a">madsrdf:hasRelatedAuthority</type>
387
+ <type tag_prefix="5" pos="2" w="b">madsrdf:hasRelatedAuthority</type>
388
+ <type tag_prefix="5" pos="2" w="c">madsrdf:hasRelatedAuthority</type>
389
+ <type tag_prefix="5" pos="2" w="d">madsrdf:hasRelatedAuthority</type>
390
+ <type tag_prefix="5" pos="2" w="e">madsrdf:hasRelatedAuthority</type>
391
+ <type tag_prefix="5" pos="2" w="f">madsrdf:hasRelatedAuthority</type>
392
+ <type tag_suffix="5" pos="2" w="g">madsrdf:hasRelatedAuthority</type>
393
+ <type tag_suffix="5" pos="2" w="h">madsrdf:hasRelatedAuthority</type>
394
+ <type tag_prefix="5" pos="1" w="_">madsrdf:hasRelatedAuthority</type>
395
+
396
+ <type tag_suffix="5" pos="3" w="a">madsrdf:hasEarlierEstablishedForm</type>
397
+ <type tag_suffix="5" pos="3" w="e">madsrdf:hasEarlierEstablishedForm</type>
398
+ <type tag_suffix="5" pos="3" w="o">madsrdf:hasEarlierEstablishedForm</type>
399
+
400
+ <type tag_suffix="5" pos="3" w="b">INVALID</type>
401
+
402
+ <type tag_prefix="5" pos="4" w="b">madsrdf:see</type>
403
+ <type tag_prefix="5" pos="4" w="c">madsrdf:see</type>
404
+ <type tag_prefix="5" pos="4" w="d">madsrdf:see</type>
405
+
406
+ </relationTypeMaps>);
407
+
408
+ declare variable $marcxml2madsrdf:variantTypeMap := (
409
+ <variantTypeMaps>
410
+ <type tag="400" count="1">madsrdf:PersonalName</type>
411
+ <type tag="400" count="2" code="cdgq">madsrdf:PersonalName</type>
412
+ <type tag="400" count="2" code="t">madsrdf:NameTitle</type> (: Would title ever not be in the second position? Is it still an NT when there is a third term, a form subdivision? :) :)
413
+ <type tag="400" count="2" code="vxyz">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
414
+
415
+ <type tag="410" count="1">madsrdf:CorporateName</type>
416
+ <type tag="410" count="2" code="t">madsrdf:NameTitle</type> (: this implies that t is the second component :)
417
+ <type tag="410" count="2" code="vxyz">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
418
+
419
+ <type tag="411" count="1">madsrdf:ConferenceName</type>
420
+ <type tag="411" count="2" code="t">madsrdf:NameTitle</type>
421
+ <type tag="411" count="2" code="vxyz">madsrdf:ComplexSubject</type> (: Name Could be a name followed by a general, form, etc subdivision :)
422
+
423
+ <type tag="430" count="2" code="vxyz">madsrdf:ComplexSubject</type> (: UniformTitle - this could have any number of code fields in it :)
424
+
425
+ <type tag="448" equivalent="y" count="1" code="a">madsrdf:Temporal</type>
426
+ <type tag="448" count="2" code="vxyz">madsrdf:ComplexSubject</type> (: loads of codes :)
427
+
428
+ <type tag="450" equivalent="x" count="1" code="a">madsrdf:Topic</type>
429
+ <type tag="450" count="2" code="vxyz">madsrdf:ComplexSubject</type>
430
+
431
+ <type tag="451" equivalent="z" count="1" code="a">madsrdf:Geographic</type>
432
+ <type tag="451" count="2" code="vxyz">madsrdf:ComplexSubject</type>
433
+
434
+ <type tag="455" equivalent="v" count="1" code="a">madsrdf:GenreForm</type>
435
+ <type tag="455" count="2" code="vxyz">madsrdf:ComplexSubject</type>
436
+
437
+ <type tag="480" count="1" code="a">madsrdf:Topic</type>
438
+ <type tag="480" count="2" code="vxyz">madsrdf:ComplexSubject</type>
439
+ </variantTypeMaps>);
440
+
441
+
442
+ (:~
443
+ : This is the main function. It converts MARCXML to MADSRDF.
444
+ : It takes the MARCXML as the first argument.
445
+ :
446
+ : @param $marcxml node() is the MARC XML
447
+ : @return rdf:RDF element of MADS RDF/XML
448
+ :)
449
+ declare function marcxml2madsrdf:marcxml2madsrdf($marcxml)
450
+ as element(rdf:RDF)
451
+ {
452
+ let $marc001 := fn:replace( $marcxml/marcxml:controlfield[@tag='001'] , ' ', '')
453
+ (: LC Specific :)
454
+ let $scheme :=
455
+ if (fn:substring($marc001, 1, 1) eq 's') then
456
+ "subjects"
457
+ else if (fn:substring($marc001, 1, 1) eq 'n') then
458
+ "names"
459
+ else if (fn:substring($marc001, 1, 1) eq 'g') then
460
+ "genreForms"
461
+ else
462
+ "empty"
463
+ let $owlSameAs :=
464
+ if ($scheme eq "subjects") then
465
+ (
466
+ element owl:sameAs {
467
+ attribute rdf:resource { fn:concat("info:lc/authorities/" , $marc001) }
468
+ },
469
+ element owl:sameAs {
470
+ attribute rdf:resource { fn:concat("http://id.loc.gov/authorities/" , $marc001 , "#concept") }
471
+ }
472
+ )
473
+ else ()
474
+ (: LC Specific :)
475
+ let $df682 := $marcxml/marcxml:datafield[@tag='682'][1] (: can there every be more than one? :)
476
+ let $leader_pos05 := fn:substring($marcxml/marcxml:leader, 6 ,1)
477
+ let $deleted :=
478
+ if ($leader_pos05 eq "d") then
479
+ fn:true()
480
+ else
481
+ fn:false()
482
+ let $df1xx := $marcxml/marcxml:datafield[fn:starts-with(@tag,'1')] (: should only be one? :)
483
+ let $df1xx_suffix := fn:substring($df1xx/@tag, 2, 2)
484
+ let $df1xx_sf_counts := fn:count($df1xx/marcxml:subfield)
485
+ let $df1xx_sf_two_code := $df1xx/marcxml:subfield[2]/@code
486
+ let $authoritativeLabel := marcxml2madsrdf:generate-label($df1xx,$df1xx_suffix)
487
+
488
+ let $authorityType := marcxml2madsrdf:get-authority-type($df1xx, fn:true())
489
+
490
+ let $components :=
491
+ if ($deleted) then
492
+ marcxml2madsrdf:create-components-from-DFxx($df1xx, fn:false())
493
+ else
494
+ marcxml2madsrdf:create-components-from-DFxx($df1xx, fn:true())
495
+ let $componentList :=
496
+ if ($components and $deleted) then marcxml2madsrdf:create-component-list($components, fn:false())
497
+ else if ($components) then marcxml2madsrdf:create-component-list($components, fn:true())
498
+ else ()
499
+
500
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($df1xx)
501
+ let $elementList :=
502
+ if ($elements and fn:not($componentList)) then marcxml2madsrdf:create-element-list($elements)
503
+ else ()
504
+
505
+ let $marc053 := $marcxml/marcxml:datafield[@tag='053']
506
+ let $classification :=
507
+ if ($marc053) then
508
+ for $df in $marc053
509
+ return marcxml2madsrdf:create-classifications($df)
510
+ else ()
511
+
512
+ let $df4xx := $marcxml/marcxml:datafield[fn:starts-with(@tag,'4')]
513
+ let $variants :=
514
+ if ($df4xx) then
515
+ for $df in $df4xx
516
+ return
517
+ element madsrdf:hasVariant { marcxml2madsrdf:create-variant($df) }
518
+ else ()
519
+
520
+ let $df4xx_w := $marcxml/marcxml:datafield[fn:starts-with(@tag,'4') and marcxml:subfield[1]/@code="w"]
521
+ let $relations_df4xx :=
522
+ if ($df4xx_w) then
523
+ for $df in $df4xx_w
524
+ return marcxml2madsrdf:create-relation($df)
525
+ else ()
526
+
527
+ let $df5xx := $marcxml/marcxml:datafield[fn:starts-with(@tag,'5')]
528
+ let $relations :=
529
+ if ($df5xx) then
530
+ for $df in $df5xx
531
+ return marcxml2madsrdf:create-relation($df)
532
+ else ()
533
+
534
+ let $hasLater_relation :=
535
+ if ($deleted and $df682) then
536
+ marcxml2madsrdf:create-hasLaterForm-relation($df682, $authorityType)
537
+ else ()
538
+
539
+ let $dfSources := $marcxml/marcxml:datafield[fn:matches(@tag , '670|675')]
540
+ let $sources :=
541
+ if ($dfSources) then
542
+ for $df in $dfSources
543
+ return element madsrdf:hasSource { marcxml2madsrdf:create-source($df) }
544
+ else ()
545
+
546
+ let $dfNotes := $marcxml/marcxml:datafield[fn:matches(@tag , '667|678|680|681|688')]
547
+ let $notes :=
548
+ if ($dfNotes) then
549
+ for $df in $dfNotes
550
+ return marcxml2madsrdf:create-notes($df)
551
+ else ()
552
+
553
+ let $delNote :=
554
+ if ($deleted and $df682) then
555
+ marcxml2madsrdf:create-deletion-note($df682)
556
+ else ()
557
+
558
+ let $rwoClass := marcxml2madsrdf:create-rwoClass( $marcxml )
559
+
560
+ let $identifiers :=
561
+ (
562
+ element identifiers:lccn { fn:normalize-space($marcxml/marcxml:datafield[@tag eq "010"]/marcxml:subfield[@code eq "a"]) },
563
+
564
+ for $i in $marcxml/marcxml:datafield[@tag eq "020"]
565
+ let $code := fn:normalize-space($i/marcxml:subfield[@code eq "2"])
566
+ let $iStr := fn:normalize-space(xs:string($i/marcxml:subfield[@code eq "a"]))
567
+ where $iStr ne ""
568
+ return
569
+ if ( $code ne "" ) then
570
+ element { fn:concat("identifiers:" , $code) } { $iStr }
571
+ else
572
+ element identifiers:id { $iStr },
573
+
574
+ for $i in $marcxml/marcxml:datafield[@tag eq "035"]/marcxml:subfield[@code eq "a"][fn:not( fn:contains(. , "DLC") )]
575
+ let $iStr := xs:string($i)
576
+ return
577
+ if ( fn:contains($iStr, "(OCoLC)" ) ) then
578
+ element identifiers:oclcnum { fn:normalize-space(fn:replace($iStr, "\(OCoLC\)", "")) }
579
+ else
580
+ element identifiers:id { fn:normalize-space($iStr) }
581
+ )
582
+
583
+ let $ri := marcxml2recordinfo:recordInfoFromMARCXML($marcxml)
584
+ let $adminMetadata :=
585
+ for $r in $ri
586
+ return element madsrdf:adminMetadata { $r }
587
+
588
+ let $marc008_pos6 := fn:substring($marcxml/marcxml:controlfield[@tag='008'], 7 ,1)
589
+ let $geo_sub :=
590
+ if ($marc008_pos6 eq "d" or $marc008_pos6 eq "i") then
591
+ element madsrdf:isMemberOfMADSCollection {
592
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_SubdivideGeographically'}
593
+
594
+ }
595
+ else ()
596
+
597
+ let $marc008_pos9 := fn:substring($marcxml/marcxml:controlfield[@tag='008'], 10 ,1)
598
+ let $kind_of_record :=
599
+ if ($marc008_pos9 eq 'a' and $scheme eq "names") then
600
+ element madsrdf:isMemberOfMADSCollection {
601
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_NamesAuthorizedHeadings'}
602
+ }
603
+ else if ($marc008_pos9 eq 'a' and $scheme eq "subjects") then
604
+ element madsrdf:isMemberOfMADSCollection {
605
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_LCSHAuthorizedHeadings'}
606
+ }
607
+ else if ($marc008_pos9 eq 'a' and $scheme eq "names") then
608
+ element madsrdf:isMemberOfMADSCollection {
609
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_NamesAuthorizedHeadings'}
610
+ }
611
+ else if ($marc008_pos9 eq 'd') then
612
+ element madsrdf:isMemberOfMADSCollection {
613
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_Subdivisions'}
614
+ }
615
+ else if ($marc008_pos9 eq 'f') then
616
+ (: this does not seem to apply to names :)
617
+ (
618
+ element madsrdf:isMemberOfMADSCollection {
619
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_LCSHAuthorizedHeadings'}
620
+ },
621
+ element madsrdf:isMemberOfMADSCollection {
622
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_Subdivisions'}
623
+ }
624
+ )
625
+ else ()
626
+
627
+ let $marc008_pos17 := fn:substring($marcxml/marcxml:controlfield[@tag='008'], 18 ,1)
628
+ let $subdivision_type :=
629
+ if ($marc008_pos17 eq 'a') then
630
+ element madsrdf:isMemberOfMADSCollection {
631
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_TopicSubdivisions'}
632
+ }
633
+ else if ($marc008_pos17 eq 'b') then
634
+ element madsrdf:isMemberOfMADSCollection {
635
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_GenreFormSubdivisions'}
636
+ }
637
+ else if ($marc008_pos17 eq 'c') then
638
+ element madsrdf:isMemberOfMADSCollection {
639
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_TemporalSubdivisions'}
640
+ }
641
+ else if ($marc008_pos17 eq 'd') then
642
+ element madsrdf:isMemberOfMADSCollection {
643
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_GeographicSubdivisions'}
644
+ }
645
+ else if ($marc008_pos17 eq 'e') then
646
+ element madsrdf:isMemberOfMADSCollection {
647
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_LanguageSubdivisions'}
648
+ }
649
+ else ()
650
+
651
+ let $frbr_kind:= (:100, 110, 100 with $t is a title or nametitle 130 with anything is a title. if it has a language or arrangement, it's an expression, otherwise, it's a work:)
652
+ if ($authorityType="madsrdf:Title" or $authorityType="madsrdf:NameTitle") then (:its at least a work:)
653
+ ( (:$l=language, $o=arrangment for music:)
654
+ if ($df1xx/marcxml:subfield[@code="l" or @code="o"]) then (:expression:)
655
+ element madsrdf:isMemberOfMADSCollection {
656
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_FRBRExpression'}
657
+ }
658
+ else
659
+ element madsrdf:isMemberOfMADSCollection {
660
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_FRBRWork'}
661
+ }
662
+ )
663
+ else ()
664
+ (: commenting out for the time being :)
665
+ (:
666
+ let $df100_subdivision_type :=
667
+ if ($df1xx_suffix='80') then
668
+ element madsrdf:isMemberOf {
669
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_TopicalSubdivisions'}
670
+ }
671
+ else if ($df1xx_suffix='85') then
672
+ element madsrdf:isMemberOf {
673
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_GenreSubdivisions'}
674
+ }
675
+ else if ($df1xx_suffix='82') then
676
+ element madsrdf:isMemberOf {
677
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_ChronologicalSubdivisions'}
678
+ }
679
+ else if ($df1xx_suffix='81') then
680
+ element madsrdf:isMemberOf {
681
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_GeographicSubdivisions'}
682
+ }
683
+ else ()
684
+ :)
685
+ let $undiff :=
686
+ if ( fn:substring($marcxml/marcxml:controlfield[@tag='008'], 33 ,1) eq 'b' and $scheme eq "names") then
687
+ element madsrdf:isMemberOfMADSCollection {
688
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_NamesUndifferentiated'}
689
+ }
690
+ else ()
691
+
692
+ let $marc001_prefix := fn:substring( $marc001 , 1 , 2 )
693
+ let $marc001_prefix_type :=
694
+ if ($marc001_prefix='sh') then
695
+ (
696
+ element madsrdf:isMemberOfMADSScheme {
697
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects'}
698
+ },
699
+ element madsrdf:isMemberOfMADSCollection {
700
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_LCSH_General'}
701
+ }
702
+ )
703
+ else if ($marc001_prefix='sj') then
704
+ (
705
+ element madsrdf:isMemberOfMADSScheme {
706
+ attribute rdf:resource {'http://id.loc.gov/authorities/childrensSubjects'}
707
+ },
708
+ element madsrdf:isMemberOfMADSScheme {
709
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects'}
710
+ },
711
+ element madsrdf:isMemberOfMADSCollection {
712
+ attribute rdf:resource {'http://id.loc.gov/authorities/subjects/collection_LCSH_Childrens'}
713
+ }
714
+ )
715
+ else if ( fn:contains($marc001_prefix, "n") ) then
716
+ (
717
+ element madsrdf:isMemberOfMADSScheme {
718
+ attribute rdf:resource {'http://id.loc.gov/authorities/names'}
719
+ },
720
+ element madsrdf:isMemberOfMADSCollection {
721
+ attribute rdf:resource {'http://id.loc.gov/authorities/names/collection_LCNAF'}
722
+ }
723
+ )
724
+ else if ( fn:contains($marc001_prefix, "g") ) then
725
+ (: should this also be a part of genreForm concept scheme. Yes. But it will break something. :)
726
+ (
727
+ element madsrdf:isMemberOfMADSScheme {
728
+ attribute rdf:resource {'http://id.loc.gov/authorities/genreForms'}
729
+ },
730
+ element madsrdf:isMemberOfMADSCollection {
731
+ attribute rdf:resource {'http://id.loc.gov/authorities/genreForms/collection_LCGFT_General'}
732
+ }
733
+ )
734
+ else ()
735
+
736
+ let $pattern_headings :=
737
+ for $ph in $marcxml/marcxml:datafield[@tag='073' and marcxml:subfield[@code='z']='lcsh']/marcxml:subfield[@code='a']
738
+ return
739
+ element madsrdf:isMemberOfMADSCollection {
740
+ attribute rdf:resource {fn:concat('http://id.loc.gov/authorities/subjects/collection_PatternHeading' , fn:replace($ph , ' ' , ''))}
741
+ }
742
+
743
+ let $scheme :=
744
+ if ($marc001_prefix='sj') then
745
+ "childrensSubjects"
746
+ else
747
+ $scheme
748
+
749
+ let $rdf :=
750
+ if ($deleted) then
751
+ let $variant :=
752
+ element {$authorityType} {
753
+ attribute rdf:about { fn:concat("http://id.loc.gov/" , $marcxml2madsrdf:authSchemeMap/authScheme[@abbrev=$scheme] , $marc001) },
754
+ element rdf:type {
755
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , "Variant") }
756
+ },
757
+ (: all "deleted" or "cancelled" records are Variants AND DeprecatedAuthorities :)
758
+ element rdf:type {
759
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , "DeprecatedAuthority") }
760
+ },
761
+ (:
762
+ This makes Variant the root element, and the MADSType part of rdf:type
763
+ element {"Variant"} {
764
+ attribute rdf:about { fn:concat("http://id.loc.gov/" , $authSchemeMap/authScheme[@abbrev=$scheme] , $marc001) },
765
+ element rdf:type {
766
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , fn:replace($authorityType, "madsrdf:", "") ) }
767
+ },
768
+ :)
769
+ element madsrdf:variantLabel {
770
+ text {$authoritativeLabel}
771
+ },
772
+ $componentList,
773
+ $elementList,
774
+ $hasLater_relation,
775
+ $delNote,
776
+ $notes,
777
+ (: $marc001_prefix_type, :) (: Scheme and membership associations. Not desirable for "cancelled" authorities :)
778
+ $owlSameAs,
779
+
780
+ $adminMetadata
781
+ }
782
+ return $variant
783
+ else
784
+ let $authority :=
785
+ element {$authorityType} {
786
+ attribute rdf:about { fn:concat("http://id.loc.gov/" , $marcxml2madsrdf:authSchemeMap/authScheme[@abbrev=$scheme] , $marc001) },
787
+ element rdf:type {
788
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , "Authority" ) }
789
+ },
790
+ (:
791
+ This makes Authority the root element, and the MADSType part of rdf:type
792
+ attribute rdf:about { fn:concat("http://id.loc.gov/" , $authSchemeMap/authScheme[@abbrev=$scheme] , $marc001) },
793
+ element rdf:type {
794
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , fn:replace($authorityType, "madsrdf:", "") ) }
795
+ },
796
+ :)
797
+ element madsrdf:authoritativeLabel {
798
+ text {$authoritativeLabel}
799
+ },
800
+ $componentList,
801
+ $elementList,
802
+ $classification,
803
+ $kind_of_record,
804
+ $subdivision_type,
805
+ (: $df100_subdivision_type, :)
806
+ $marc001_prefix_type,
807
+ $geo_sub,
808
+ $pattern_headings,
809
+ $undiff,
810
+ $frbr_kind,
811
+ $rwoClass,
812
+ $variants,
813
+ $relations_df4xx,
814
+ $relations,
815
+ $sources,
816
+ $notes,
817
+ $identifiers,
818
+ $owlSameAs,
819
+ $adminMetadata
820
+ }
821
+ return $authority
822
+
823
+ return <rdf:RDF>{$rdf}</rdf:RDF>
824
+
825
+ };
826
+
827
+
828
+
829
+
830
+ (:
831
+ -------------------------
832
+
833
+ Creates Classification Properties:
834
+
835
+ $marc053 as element() is the marc 053 datafield
836
+
837
+ -------------------------
838
+ :)
839
+ declare function marcxml2madsrdf:create-classifications($marc053 as element()) as element() {
840
+ let $lc :=
841
+ if ($marc053/@ind2 eq '0') then
842
+ (: LC assigned means LC Classification :)
843
+ xs:boolean(1)
844
+ else xs:boolean(0)
845
+
846
+ let $textparts :=
847
+ for $sf at $pos in $marc053/marcxml:subfield
848
+ let $class_str :=
849
+ if ($sf/@code eq 'a') then
850
+ $sf
851
+ else if ($sf/@code eq 'b') then
852
+ fn:concat('- ',$sf)
853
+ else ""
854
+ return $class_str
855
+ let $text := fn:replace( fn:string-join($textparts , '') , ' ' , '' )
856
+
857
+ let $classifications :=
858
+ element madsrdf:classification {
859
+ text { $text }
860
+ }
861
+
862
+ return $classifications
863
+ };
864
+
865
+
866
+
867
+ (:~
868
+ : Creates a Component, aka an Authority.
869
+ :
870
+ : @param $sf element() is the subfield
871
+ : @param $pos as xs:integer is the position in the loop
872
+ : @param $authority as xs:boolean denotes whether this is an Authority or Variant
873
+ : @return component Authority record/element
874
+ :)
875
+ declare function marcxml2madsrdf:create-component(
876
+ $sf as element(),
877
+ $pos as xs:integer,
878
+ $authority as xs:boolean) as element()*
879
+ {
880
+ let $c := $sf/@code
881
+ let $df_suffix := fn:substring($sf/../@tag , 2 , 2)
882
+ let $aORv :=
883
+ if ($authority) then
884
+ "Authority"
885
+ else
886
+ "Variant"
887
+ let $type :=
888
+ if ($authority) then
889
+ if ($pos lt 2) then
890
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='1']/authority
891
+ else
892
+ $marcxml2madsrdf:marc2madsMap/map[fn:contains(@variant_subfield , $c) and @count='1']/authority
893
+ else
894
+ if ($pos lt 2) then
895
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='1']/variant
896
+ else
897
+ $marcxml2madsrdf:marc2madsMap/map[fn:contains(@variant_subfield , $c) and @count='1']/variant
898
+ (: let $label := $sf/text() :)
899
+
900
+ let $labelProperty :=
901
+ if ($authority) then
902
+ "madsrdf:authoritativeLabel"
903
+ else
904
+ "madsrdf:variantLabel"
905
+
906
+ let $elements := marcxml2madsrdf:create-element($sf, 1)
907
+ let $elementList :=
908
+ if ($elements) then marcxml2madsrdf:create-element-list($elements)
909
+ else ()
910
+
911
+ let $label := fn:string-join($elements, ' ')
912
+ let $label :=
913
+ if ( fn:ends-with($label, ".") and fn:not(fn:contains($type, "Name")) ) then
914
+ fn:substring($label, 1, (fn:string-length($label) - 1))
915
+ else
916
+ $label
917
+ (: let $nodeID := marcxml2madsrdf:generate-nodeID($label,$authority) :)
918
+
919
+
920
+ (:
921
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($sf/parent::node()[1])
922
+ let $elementList :=
923
+ if ($elements) then marcxml2madsrdf:create-element-list($elements)
924
+ else ()
925
+ :)
926
+
927
+ (: fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , fn:replace($type, "madsrdf:", "") ) :)
928
+
929
+ let $component :=
930
+ if ($type ne "") then
931
+ element {$type} {
932
+ (: attribute rdf:nodeID {$nodeID}, :)
933
+ element rdf:type {
934
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , $aORv ) }
935
+ },
936
+ element {$labelProperty} {
937
+ text {$label}
938
+ },
939
+ $elementList
940
+ }
941
+ else ()
942
+ return $component
943
+ };
944
+
945
+
946
+ (:~
947
+ : Creates a componentList
948
+ :
949
+ : @param $component_elementlist as element() holds the component
950
+ : @param $counts as xs:integer is the number of subfields
951
+ : @param $authority as xs:boolean denotes whether this is an Authority or Variant
952
+ : @return component Authority record/element
953
+ :)
954
+ declare function marcxml2madsrdf:create-component-list($component_elementlist, $authority as xs:boolean) {
955
+ let $component_list :=
956
+ element {"madsrdf:componentList"} {
957
+ attribute rdf:parseType {"Collection"},
958
+ $component_elementlist
959
+ }
960
+ return $component_list
961
+ };
962
+
963
+
964
+
965
+ (:
966
+ -------------------------
967
+
968
+ Returns Component from a 1xx or 4xx marcxml:datafield
969
+
970
+ $df as element() is the relevant marcxml:datafield
971
+ $counts as is the number of subfields
972
+ $authority as xs:boolean denotes whether this is an Authority or Variant
973
+
974
+ -------------------------
975
+ :)
976
+ declare function marcxml2madsrdf:create-components-from-DFxx($df as element(), $authority as xs:boolean) {
977
+ let $df_suffix := fn:substring($df/@tag, 2, 2)
978
+ let $components :=
979
+ if (
980
+ ( $df/marcxml:subfield[@code eq 'a']
981
+ and ($df/marcxml:subfield[fn:matches(@code , "t|v|x|y|z")]) )
982
+ or
983
+ ( fn:matches($df/@tag , '80|81|82|85') and
984
+ fn:count($df/marcxml:subfield[@code ne "w"]) gt 1 )
985
+ ) then
986
+ for $f at $pos in $df/marcxml:subfield[fn:matches(@code , "a|t|v|x|y|z")]
987
+ let $component := marcxml2madsrdf:create-component($f, $pos, $authority)
988
+ return $component
989
+ else ()
990
+ return $components
991
+ };
992
+
993
+
994
+
995
+
996
+ (:
997
+ -------------------------
998
+
999
+ Creates MADS Deletion Note:
1000
+
1001
+ $df as element() is the relevant marcxml:datafield
1002
+
1003
+ -------------------------
1004
+ :)
1005
+ declare function marcxml2madsrdf:create-deletion-note($df as element()) as element() {
1006
+
1007
+ let $textparts :=
1008
+ for $sf in $df/marcxml:subfield
1009
+ let $str :=
1010
+ if ($sf/@code eq 'a') then
1011
+ fn:concat('{' , $sf/text() , '}')
1012
+ else
1013
+ $sf/text()
1014
+ return $str
1015
+ let $text := fn:string-join($textparts, ' ')
1016
+
1017
+ let $note := element madsrdf:deletionNote {
1018
+ text {$text}
1019
+ }
1020
+
1021
+ return $note
1022
+ };
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+ (:
1029
+ -------------------------
1030
+
1031
+ Creates Element:
1032
+
1033
+ $sf as element() is the subfield
1034
+ $pos as xs:integer is the position in the loop
1035
+
1036
+ -------------------------
1037
+ :)
1038
+ declare function marcxml2madsrdf:create-element($sf, $pos) {
1039
+ let $tag_suffix := fn:substring($sf/../@tag , 2 , 2)
1040
+ let $tag_prefix := fn:substring($sf/../@tag , 1 , 1)
1041
+ let $label := $sf/../text()
1042
+ let $code := xs:string($sf/@code)
1043
+ let $element :=
1044
+ if ($sf/@code ne 'w') then
1045
+ let $el := $marcxml2madsrdf:elementTypeMap/elementType[@tag_suffix=$tag_suffix and @code=$sf/@code and fn:not(@ancillary)]/text()
1046
+ let $label := xs:string($sf)
1047
+ return
1048
+ element {$el} {
1049
+ element madsrdf:elementValue {
1050
+ $label
1051
+ }
1052
+ }
1053
+ else ()
1054
+ let $extras :=
1055
+ if ($pos=1) then
1056
+ for $dfc in $sf/following-sibling::node()
1057
+ let $el := $marcxml2madsrdf:elementTypeMap/elementType[@tag_suffix=$tag_suffix and @code=$sf/@code and @ancillary=$dfc/@code]/text()
1058
+ return
1059
+ if ($el and ($sf/@code="t" or ($dfc/@code!="t" and fn:not($dfc/preceding-sibling::node()[@code="t"])))) then
1060
+ (: this seems a little forced, but we need to seperate the the name and title parts :)
1061
+ element {$el} {
1062
+ element madsrdf:elementValue {
1063
+ text {$dfc}
1064
+ }
1065
+ }
1066
+ else ()
1067
+ else ()
1068
+
1069
+ return ($element , $extras)
1070
+ };
1071
+
1072
+
1073
+
1074
+ (:
1075
+ -------------------------
1076
+
1077
+ Creates ElementList:
1078
+
1079
+ $component_elementlist as element() holds the component
1080
+ $counts as is the number of subfields
1081
+ $authority as xs:boolean denotes whether this is an Authority or Variant
1082
+
1083
+ -------------------------
1084
+ :)
1085
+ declare function marcxml2madsrdf:create-element-list($elementlist) {
1086
+ let $e_list :=
1087
+ element madsrdf:elementList {
1088
+ attribute rdf:parseType {"Collection"},
1089
+ $elementlist
1090
+ }
1091
+ return $e_list
1092
+ };
1093
+
1094
+
1095
+
1096
+ (:
1097
+ -------------------------
1098
+
1099
+ Returns Element from a 1xx or 5xx marcxml:datafield
1100
+
1101
+ $df as element() is the relevant marcxml:datafield
1102
+ $counts as is the number of subfields
1103
+ $authority as xs:boolean denotes whether this is an Authority or Variant
1104
+
1105
+ -------------------------
1106
+ :)
1107
+ declare function marcxml2madsrdf:create-elements-from-DFxx($df as element()) {
1108
+ let $df_suffix := fn:substring($df/@tag, 2, 2)
1109
+ let $elements :=
1110
+ if (
1111
+ ($df/marcxml:subfield[@code eq 'a'] or fn:matches($df_suffix , '80|81|82|85'))
1112
+ ) then
1113
+ for $f at $pos in $df/marcxml:subfield[fn:matches(@code , "a|v|x|y|z")]
1114
+ let $element := marcxml2madsrdf:create-element($f, $pos)
1115
+ return $element
1116
+ else ()
1117
+ return $elements
1118
+ };
1119
+
1120
+
1121
+ (:~
1122
+ : Returns Elements for hasLaterEstablishedForm relationships
1123
+ : This, rightly or wrongly, assumes that the later Authority
1124
+ : is of the same MADSType as this Variant
1125
+ :
1126
+ : @param $df element() is the 682 datafield for parsing
1127
+ : @param $authorityType xs:string of MADSType
1128
+ : @return zero or more madsrdf:hasLaterEstablishedForm elements
1129
+ :)
1130
+ declare function marcxml2madsrdf:create-hasLaterForm-relation(
1131
+ $df as element(),
1132
+ $authorityType as xs:string
1133
+ ) as element()*
1134
+ {
1135
+ let $elements :=
1136
+ for $s at $pos in $df/marcxml:subfield
1137
+ return
1138
+ if ($s/@code eq "a") then
1139
+ (: if code eq "a" then it is a replacement heading, but
1140
+ what type of replacement is it?
1141
+ :)
1142
+ let $objprop :=
1143
+ if ( fn:matches( xs:string($df) , 'covered by' ) ) then
1144
+ "madsrdf:useInstead"
1145
+ else
1146
+ "madsrdf:hasLaterEstablishedForm"
1147
+ return
1148
+ element {$objprop} {
1149
+ element {$authorityType} {
1150
+ if ($s/following-sibling::node()[@code!=""][1]/@code eq "i") then
1151
+ (: this will require a little massaging, how do we know it is "lcsh" :)
1152
+ (: Answer, from the LCCN prefix :)
1153
+ let $relatedlccn := fn:replace( $s/following-sibling::node()[@code!=""][1]/text(), "\(|\)| |\.|and|,", "")
1154
+ let $relatedscheme :=
1155
+ if ( fn:starts-with($relatedlccn, "sh") ) then
1156
+ (: presume this is LCSH :)
1157
+ "subjects"
1158
+ else if ( fn:starts-with($relatedlccn, "sj") ) then
1159
+ (: presume this is LCSH :)
1160
+ "childrensSubjects"
1161
+ else if ( fn:starts-with($relatedlccn, "n") ) then
1162
+ "names"
1163
+ else
1164
+ "empty"
1165
+ return
1166
+ attribute rdf:about {
1167
+ fn:concat( "http://id.loc.gov/authorities/" , $relatedscheme , "/" , $relatedlccn )
1168
+ }
1169
+ else (),
1170
+ element rdf:type {
1171
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , "Authority" ) }
1172
+ },
1173
+ element madsrdf:authoritativeLabel {
1174
+ $s/text()
1175
+ }
1176
+ }
1177
+ }
1178
+ else ()
1179
+ return $elements
1180
+ };
1181
+
1182
+
1183
+ (:
1184
+ -------------------------
1185
+
1186
+ Creates MADS Notes:
1187
+
1188
+ $df as element() is the relevant marcxml:datafield
1189
+
1190
+ -------------------------
1191
+ :)
1192
+ declare function marcxml2madsrdf:create-notes($df as element()) as element() {
1193
+
1194
+ let $tag := $df/@tag
1195
+ let $type := $marcxml2madsrdf:noteTypeMap/type[@tag=$tag]/text()
1196
+
1197
+ let $textparts :=
1198
+ for $sf in $df/marcxml:subfield
1199
+ let $str :=
1200
+ if ($sf/@code eq 'a') then
1201
+ (: must have had a spectacularly good reason for this :)
1202
+ (: too bad I cannot remember :)
1203
+ fn:concat('[' , $sf/text() , ']')
1204
+ else
1205
+ $sf/text()
1206
+ return $str
1207
+ let $text := fn:string-join($textparts, ' ')
1208
+
1209
+ let $note := element {$type} {$text}
1210
+
1211
+ return $note
1212
+ };
1213
+
1214
+
1215
+
1216
+ (:~
1217
+ : Creates MADS Relation
1218
+ :
1219
+ : @param $df element() the relevant marcxml:datafield
1220
+ : @return relation as element()
1221
+ :)
1222
+ declare function marcxml2madsrdf:create-relation($df as element()) as element()* {
1223
+
1224
+ let $tag := $df/@tag
1225
+ let $df_suffix := fn:substring($df/@tag, 2, 2)
1226
+ let $df_sf_counts := fn:count($df/marcxml:subfield[@code ne 'w'])
1227
+ let $df_sf_two_code := $df/marcxml:subfield[2]/@code
1228
+ let $label := marcxml2madsrdf:generate-label($df,$df_suffix)
1229
+
1230
+ let $wstr := xs:string($df/marcxml:subfield[@code='w']/text())
1231
+ let $ws := fn:tokenize($wstr , "[a-z]")
1232
+ return
1233
+ if (fn:normalize-space($wstr) eq "" and $df/marcxml:subfield[@code='a']) then
1234
+ (: reciprocal relations :)
1235
+ let $type := "madsrdf:hasReciprocalAuthority"
1236
+ let $auth := fn:true()
1237
+ let $aORv := "Authority"
1238
+ let $authorityType := marcxml2madsrdf:get-authority-type($df,$auth)
1239
+ let $labelProp := "madsrdf:authoritativeLabel"
1240
+ let $nodeID := marcxml2madsrdf:generate-nodeID($label,$auth)
1241
+ let $components := marcxml2madsrdf:create-components-from-DFxx($df, $auth)
1242
+ let $componentList :=
1243
+ if ($components) then marcxml2madsrdf:create-component-list($components, $auth)
1244
+ else ()
1245
+
1246
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($df)
1247
+ let $elementList :=
1248
+ if ($elements and fn:not($componentList)) then marcxml2madsrdf:create-element-list($elements)
1249
+ else ()
1250
+
1251
+ let $relation :=
1252
+ element {$type} {
1253
+ element {$authorityType} {
1254
+ (: attribute rdf:nodeID {$nodeID}, :)
1255
+ element rdf:type {
1256
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , $aORv ) }
1257
+ },
1258
+ element {$labelProp} {
1259
+ text {$label}
1260
+ },
1261
+ $componentList,
1262
+ $elementList
1263
+ }
1264
+ }
1265
+ return $relation
1266
+ else
1267
+ for $c at $pos in fn:string-to-codepoints($wstr)
1268
+ let $w := fn:codepoints-to-string($c)
1269
+ return
1270
+ if ($w ne "n" and $pos != 4) then
1271
+ let $type := $marcxml2madsrdf:relationTypeMap/type[@pos eq xs:string($pos) and @w eq $w]/text()
1272
+ return
1273
+ if ($type ne "INVALID") then
1274
+ let $auth :=
1275
+ if ($type eq "madsrdf:hasEarlierEstablishedForm" or
1276
+ $type eq "madsrdf:hasAcronymVariant") then
1277
+ fn:false()
1278
+ else
1279
+ fn:true()
1280
+ let $aORv :=
1281
+ if ($auth) then
1282
+ "Authority"
1283
+ else
1284
+ "Variant"
1285
+
1286
+ let $authorityType := marcxml2madsrdf:get-authority-type($df,$auth)
1287
+ let $labelProp :=
1288
+ if ($auth) then
1289
+ "madsrdf:authoritativeLabel"
1290
+ else
1291
+ "madsrdf:variantLabel"
1292
+
1293
+ let $nodeID := marcxml2madsrdf:generate-nodeID($label,$auth)
1294
+
1295
+ let $components := marcxml2madsrdf:create-components-from-DFxx($df, $auth)
1296
+ let $componentList :=
1297
+ if ($components) then marcxml2madsrdf:create-component-list($components, $auth)
1298
+ else ()
1299
+
1300
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($df)
1301
+ let $elementList :=
1302
+ if ($elements and fn:not($componentList)) then marcxml2madsrdf:create-element-list($elements)
1303
+ else ()
1304
+
1305
+ let $relation :=
1306
+ element {$type} {
1307
+ element {$authorityType} {
1308
+ (: attribute rdf:nodeID {$nodeID}, :)
1309
+ element rdf:type {
1310
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , $aORv ) }
1311
+ },
1312
+ element {$labelProp} {
1313
+ text {$label}
1314
+ },
1315
+ $componentList,
1316
+ $elementList
1317
+ }
1318
+ }
1319
+ return $relation
1320
+ else
1321
+ ()
1322
+ else if ($w ne "n" and $pos = 4) then
1323
+ let $type := $marcxml2madsrdf:relationTypeMap/type[@pos eq xs:string($pos) and @w eq $w]/text()
1324
+ return
1325
+ if ($type ne "INVALID") then
1326
+ let $auth :=
1327
+ if ($type eq "madsrdf:hasEarlierEstablishedForm" or
1328
+ $type eq "madsrdf:hasAcronymVariant") then
1329
+ fn:false()
1330
+ else
1331
+ fn:true()
1332
+ let $aORv :=
1333
+ if ($auth) then
1334
+ "Authority"
1335
+ else
1336
+ "Variant"
1337
+
1338
+ let $authorityType := marcxml2madsrdf:get-authority-type($df,$auth)
1339
+ let $labelProp :=
1340
+ if ($auth) then
1341
+ "madsrdf:authoritativeLabel"
1342
+ else
1343
+ "madsrdf:variantLabel"
1344
+
1345
+ let $nodeID := marcxml2madsrdf:generate-nodeID($label,$auth)
1346
+
1347
+ let $components := marcxml2madsrdf:create-components-from-DFxx($df, $auth)
1348
+ let $componentList :=
1349
+ if ($components) then marcxml2madsrdf:create-component-list($components, $auth)
1350
+ else ()
1351
+
1352
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($df)
1353
+ let $elementList :=
1354
+ if ($elements and fn:not($componentList)) then marcxml2madsrdf:create-element-list($elements)
1355
+ else ()
1356
+
1357
+ let $relation :=
1358
+ element {$type} {
1359
+ element {$authorityType} {
1360
+ (: attribute rdf:nodeID {$nodeID}, :)
1361
+ element rdf:type {
1362
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , $aORv ) }
1363
+ },
1364
+ element {$labelProp} {
1365
+ text {$label}
1366
+ },
1367
+ $componentList,
1368
+ $elementList
1369
+ }
1370
+ }
1371
+ return $relation
1372
+ else
1373
+ ()
1374
+ else ()
1375
+ };
1376
+
1377
+ (:~
1378
+ : Creates MADS RWO Class
1379
+ :
1380
+ : @param $df element() the relevant marcxml:datafield
1381
+ : @return relation as element()
1382
+ :)
1383
+ declare function marcxml2madsrdf:create-rwoClass($record as element()) as element()* {
1384
+ let $df046 := $record/marcxml:datafield[@tag='046']
1385
+ let $df371 := $record/marcxml:datafield[@tag='371']
1386
+ let $df372 := $record/marcxml:datafield[@tag='372']
1387
+ let $df373 := $record/marcxml:datafield[@tag='373']
1388
+ let $df374 := $record/marcxml:datafield[@tag='374']
1389
+ let $df375 := $record/marcxml:datafield[@tag='375']
1390
+ let $types := (
1391
+ if ($record/marcxml:datafield[@tag='100'] and
1392
+ fn:not($record/marcxml:datafield[@tag='100']/marcxml:subfield[fn:matches(@code , '[efhklmnoprstvxyz]')])
1393
+ ) then
1394
+ <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
1395
+ else (),
1396
+ if ($record/marcxml:datafield[@tag='110'] and
1397
+ fn:not($record/marcxml:datafield[@tag='110']/marcxml:subfield[fn:matches(@code , '[efhklmnoprstvxyz]')])
1398
+ ) then
1399
+ <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Organization"/>
1400
+ else ()
1401
+ )
1402
+ let $properties :=
1403
+ (
1404
+ if ($df046) then
1405
+ (
1406
+ if ($df046/marcxml:subfield[@code='f']) then
1407
+ <madsrdf:birthdate>{$df046/marcxml:subfield[@code='f']/text()}</madsrdf:birthdate>
1408
+ else (),
1409
+ if ($df046/marcxml:subfield[@code='g']) then
1410
+ <madsrdf:deathdate>{$df046/marcxml:subfield[@code='g']/text()}</madsrdf:deathdate>
1411
+ else ()
1412
+ )
1413
+ else (),
1414
+ for $df in $df373
1415
+ return
1416
+ element madsrdf:hasAffiliation {
1417
+ element madsrdf:Affiliation {
1418
+ for $a in $df/marcxml:subfield[@code='a']
1419
+ return
1420
+ element madsrdf:affiliatedWith {$a/text()},
1421
+ if ($df/marcxml:subfield[@code='s']) then
1422
+ element madsrdf:affiliationBegan {$df/marcxml:subfield[@code='s']/text()}
1423
+ else (),
1424
+ if ($df/marcxml:subfield[@code='t']) then
1425
+ element madsrdf:affiliationEnded {$df/marcxml:subfield[@code='t']/text()}
1426
+ else (),
1427
+ if ($df/marcxml:subfield[@code='v']) then
1428
+ element madsrdf:informationSource {$df/marcxml:subfield[@code='v']/text()}
1429
+ else (),
1430
+ if ($df371) then
1431
+ element madsrdf:hasAffiliationAddress {
1432
+ element madsrdf:AffiliationAddress {
1433
+ if ($df371/marcxml:subfield[@code='a'][1]) then
1434
+ element madsrdf:streetAddress {$df371/marcxml:subfield[@code='a'][1]/text()}
1435
+ else (),
1436
+ (: this should probably be a for loop :)
1437
+ if ($df371/marcxml:subfield[@code='a'][2]) then
1438
+ element madsrdf:extendedAddress {$df371/marcxml:subfield[@code='a'][2]/text()}
1439
+ else (),
1440
+ if ($df371/marcxml:subfield[@code='b']) then
1441
+ element madsrdf:city {$df371/marcxml:subfield[@code='b']/text()}
1442
+ else (),
1443
+ if ($df371/marcxml:subfield[@code='d']) then
1444
+ element madsrdf:country {$df371/marcxml:subfield[@code='d']/text()}
1445
+ else (),
1446
+ if ($df371/marcxml:subfield[@code='e']) then
1447
+ element madsrdf:postcode {$df371/marcxml:subfield[@code='e']/text()}
1448
+ else (),
1449
+ if ($df371/marcxml:subfield[@code='m']) then
1450
+ element madsrdf:email {$df371/marcxml:subfield[@code='m']/text()}
1451
+ else ()
1452
+ }
1453
+ }
1454
+ else ()
1455
+ }
1456
+ },
1457
+ for $df in $df372
1458
+ return
1459
+ for $sf in $df/marcxml:subfield[@code='a']
1460
+ return element madsrdf:fieldOfActivity {$sf/text()},
1461
+ for $df in $df374
1462
+ return ()
1463
+ (:
1464
+ element madsrdf:hasOccupation {
1465
+ element madsrdf:Occupation {
1466
+ for $a in $df/marcxml:subfield[@code='a']
1467
+ return
1468
+ element madsrdf:positionTitle {$a/text()},
1469
+ if ($df/marcxml:subfield[@code='s']) then
1470
+ element madsrdf:positionBegan {$df/marcxml:subfield[@code='s']/text()}
1471
+ else (),
1472
+ if ($df/marcxml:subfield[@code='t']) then
1473
+ element madsrdf:positionEnded {$df/marcxml:subfield[@code='t']/text()}
1474
+ else (),
1475
+ if ($df/marcxml:subfield[@code='v']) then
1476
+ element madsrdf:informationSource {$df/marcxml:subfield[@code='v']/text()}
1477
+ else ()
1478
+ }
1479
+ }
1480
+ :)
1481
+ )
1482
+ let $rwo :=
1483
+ if ($types) then
1484
+ element madsrdf:identifiesRWO {
1485
+ element madsrdf:RWO {$types,$properties}
1486
+ }
1487
+ else ()
1488
+ return $rwo
1489
+ };
1490
+
1491
+
1492
+
1493
+ (:
1494
+ -------------------------
1495
+
1496
+ Creates MADS Sources:
1497
+
1498
+ $df as element() is the relevant marcxml:datafield
1499
+
1500
+ -------------------------
1501
+ :)
1502
+ declare function marcxml2madsrdf:create-source($df as element()) as element() {
1503
+
1504
+ let $tag := $df/@tag
1505
+
1506
+ let $citation_source_element :=
1507
+ if ($df/marcxml:subfield[@code eq 'a']/text()) then
1508
+ <madsrdf:citation-source>{$df/marcxml:subfield[@code eq 'a']/text()}</madsrdf:citation-source>
1509
+ else ()
1510
+ let $status_element :=
1511
+ if ($tag eq '670') then
1512
+ <madsrdf:citation-status>found</madsrdf:citation-status>
1513
+ else
1514
+ <madsrdf:citation-status>notfound</madsrdf:citation-status>
1515
+ let $textparts :=
1516
+ for $sf in $df/marcxml:subfield[@code ne 'a']
1517
+ let $str :=
1518
+ if ($sf/@code eq 'u') then
1519
+ fn:concat('{' , $sf/text() , '}')
1520
+ else
1521
+ $sf/text()
1522
+ return $str
1523
+ let $text := fn:string-join($textparts, ' ')
1524
+ let $text_element :=
1525
+ if (fn:normalize-space($text)) then
1526
+ <madsrdf:citation-note>{$text}</madsrdf:citation-note>
1527
+ else ()
1528
+
1529
+ let $source :=
1530
+ element madsrdf:Source {
1531
+ $citation_source_element,
1532
+ $text_element,
1533
+ $status_element
1534
+ }
1535
+ return $source
1536
+ };
1537
+
1538
+
1539
+ (:~
1540
+ : Creates a Variant.
1541
+ :
1542
+ : @param $df element() is the subfield
1543
+ : @return madsrdf:hasVariant/child::node()[1] as element()
1544
+ :)
1545
+ declare function marcxml2madsrdf:create-variant($df as element()) as element() {
1546
+
1547
+ let $tag := $df/@tag
1548
+ let $df_suffix := fn:substring($df/@tag, 2, 2)
1549
+ let $df_sf_counts := fn:count($df/marcxml:subfield[@code ne 'w'])
1550
+ let $df_sf_two_code := $df/marcxml:subfield[2]/@code
1551
+ let $label := marcxml2madsrdf:generate-label($df,$df_suffix)
1552
+
1553
+ let $type := marcxml2madsrdf:get-authority-type($df, fn:false())
1554
+
1555
+ let $components := marcxml2madsrdf:create-components-from-DFxx($df, fn:false())
1556
+ let $componentList :=
1557
+ if ($components) then marcxml2madsrdf:create-component-list($components, fn:false())
1558
+ else ()
1559
+
1560
+ let $elements := marcxml2madsrdf:create-elements-from-DFxx($df)
1561
+ let $elementList :=
1562
+ if ($elements and fn:not($componentList)) then marcxml2madsrdf:create-element-list($elements)
1563
+ else ()
1564
+
1565
+ let $nodeID := marcxml2madsrdf:generate-nodeID($label,fn:false())
1566
+
1567
+ let $variant :=
1568
+ element {$type} {
1569
+ (: attribute rdf:nodeID {$nodeID}, :)
1570
+ element rdf:type {
1571
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , "Variant" ) }
1572
+ },
1573
+ (:
1574
+ This makes the MADSType the parent element; Variant is part of rdf:type
1575
+ element {"Variant"} {
1576
+ attribute rdf:nodeID {$nodeID},
1577
+ element rdf:type {
1578
+ attribute rdf:resource { fn:concat( xs:string( fn:namespace-uri-for-prefix("madsrdf", <madsrdf:blah/>) ) , fn:replace($type, "madsrdf:", "") ) }
1579
+ },
1580
+ :)
1581
+ element madsrdf:variantLabel {
1582
+ text {$label}
1583
+ },
1584
+ $componentList,
1585
+ $elementList
1586
+ }
1587
+
1588
+ return $variant
1589
+ };
1590
+
1591
+
1592
+ (:
1593
+ -------------------------
1594
+
1595
+ Determines, and returns, the appropriate MADS Authority or Variant type:
1596
+
1597
+ $df as element() is the relevant marcxml:datafield
1598
+
1599
+ -------------------------
1600
+ :)
1601
+ declare function marcxml2madsrdf:get-authority-type($df as element(), $authority as xs:boolean) as xs:string {
1602
+ let $df_suffix := fn:substring($df/@tag, 2, 2)
1603
+ let $df_sf_two_code := $df/marcxml:subfield[fn:matches(@code , "[tvxyz]")][1]/@code
1604
+ let $df682 := $df/parent::node()/marcxml:datafield[@tag='682'][1] (: only one, no? :)
1605
+ let $authority_test :=
1606
+ if ($df682) then
1607
+ fn:false()
1608
+ else
1609
+ $authority
1610
+
1611
+ let $union :=
1612
+ if (
1613
+ $df/marcxml:subfield[@code='a'] and
1614
+ fn:matches( fn:string-join($df/marcxml:subfield[@code!="a"]/@code, ''), '[tvxyz]')
1615
+ ) then
1616
+ fn:true()
1617
+ else if (
1618
+ fn:matches($df_suffix , '80|81|82|85') and
1619
+ $df/marcxml:subfield[1][fn:matches(@code, 'v|x|y|z')] and
1620
+ $df/marcxml:subfield[2][fn:matches(@code, 'v|x|y|z')]
1621
+ ) then
1622
+ fn:true()
1623
+ else
1624
+ fn:false()
1625
+
1626
+ let $t := $df/marcxml:subfield[@code="t"]
1627
+ let $not_hg := fn:matches( fn:string-join($df/marcxml:subfield/@code , ''), '[a-f|h-z]')
1628
+ let $type_element :=
1629
+ if ($union) then
1630
+ if (fn:matches($df_suffix , '00|10|11') and $t) then
1631
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='2' and fn:contains(@subfield , 't') ]
1632
+ else if (
1633
+ fn:matches($df_suffix , '80|81|82|85') and
1634
+ $df/marcxml:subfield[2][fn:matches(@code, 'v|x|y|z')]
1635
+ ) then
1636
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='2']
1637
+ else
1638
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='2' and fn:contains(@subfield , $df_sf_two_code) ]
1639
+ else
1640
+ $marcxml2madsrdf:marc2madsMap/map[@tag_suffix=$df_suffix and @count='1']
1641
+
1642
+ let $type :=
1643
+ if ($authority_test) then
1644
+ $type_element/authority/text()
1645
+ else
1646
+ $type_element/variant/text()
1647
+
1648
+ return $type
1649
+
1650
+ };
1651
+
1652
+ (:~
1653
+ : This function creates a proper nodeID value
1654
+ :
1655
+ : @param $df marcxml datafield element
1656
+ : @param $df_suffix last two characters of marc/datafield tag value
1657
+ : @return specially formatted string for use as lexical label
1658
+ :)
1659
+ declare function marcxml2madsrdf:generate-label($df as element(), $df_suffix as xs:string) as xs:string {
1660
+ let $label :=
1661
+ if (fn:matches($df_suffix, ("00|10|11|30"))) then
1662
+ fn:concat(
1663
+ fn:string-join($df/marcxml:subfield[@code ne 'w' and @code!='v' and @code!='x' and @code!='y' and @code!='z' and @code!='6'] , ' '),
1664
+ if ( $df/marcxml:subfield[@code='v' or @code='x' or @code='y' or @code='z'] ) then
1665
+ fn:concat("--",fn:string-join($df/marcxml:subfield[@code='v' or @code='x' or @code='y' or @code='z'] , '--'))
1666
+ else ""
1667
+ )
1668
+ else
1669
+ let $label := fn:string-join($df/marcxml:subfield[@code ne 'w' and @code ne '6'] , '--')
1670
+ let $label :=
1671
+ if ( fn:ends-with($label, ".") ) then
1672
+ fn:substring($label, 1, (fn:string-length($label) - 1))
1673
+ else
1674
+ $label
1675
+ return $label
1676
+
1677
+ return fn:normalize-space($label)
1678
+ };
1679
+
1680
+ (:~
1681
+ : This function creates a proper nodeID value
1682
+ :
1683
+ : @param $label lexical authority or variant label
1684
+ : @param $authority boolean, true if authority, false if variant
1685
+ : @return specially formatted string for use as an RDF/XML nodeID/bnode
1686
+ :)
1687
+ declare function marcxml2madsrdf:generate-nodeID($label as xs:string,
1688
+ $authority as xs:boolean)
1689
+ as xs:string
1690
+ {
1691
+ let $firstLetter := if ($authority) then "a" else "v"
1692
+ let $str := fn:replace( $label ,' ','-')
1693
+ let $str := fn:replace( $str ,'(,|\.|\s|\(|\)|"|&apos;|&amp;|;|:)','')
1694
+ let $str_codepoints := fn:string-to-codepoints($str)
1695
+ let $str := fn:string-join(
1696
+ for $x in $str_codepoints
1697
+ return
1698
+ if ($x gt 122) then "X" else fn:codepoints-to-string($x),
1699
+ '')
1700
+ let $nodeID := fn:concat($firstLetter,$str)
1701
+ return $nodeID
1702
+ };