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,45 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetMetadataFromVivoModel
4
+
5
+ ##
6
+ # Get standard display metadata from an vivo model
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ # @param [Model] an vivo model
10
+ #
11
+ # @returns an instance of LD4L::WorksRDF::WorkMetadata
12
+ def self.call( uri, model )
13
+ raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
14
+ uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
15
+
16
+ uri = uri.to_s if uri.kind_of?(RDF::URI)
17
+
18
+ # TODO: Determine type of work from the model. Right now, only processing books.
19
+ metadata = self.populate_with_vivo_book( model ) if
20
+ model.type.include?(RDFVocabularies::BIBO.Book.to_s) || model.type.include?(RDFVocabularies::BIBO.Document.to_s)
21
+ metadata.uri = uri
22
+ metadata.local_id = URI.parse(uri).path.split('/').last
23
+ metadata
24
+ end
25
+
26
+ def self.populate_with_vivo_book( model )
27
+ # TODO: Could reach out to OCLC and get more info OR could make multiple calls to VIVO to get more info
28
+ metadata = LD4L::WorksRDF::WorkMetadata.new(model)
29
+ metadata.set_type_to_book
30
+ if model.title && model.title.size > 0
31
+ metadata.title = model.title.first
32
+ elsif model.label && model.label.size > 0
33
+ metadata.title = model.label.first
34
+ end
35
+ metadata.pub_info = "#{model.place_of_publication.first} : #{model.publisher.first.label.first}" if
36
+ model.place_of_publication && model.place_of_publication.size > 0 &&
37
+ model.publisher && model.publisher.size > 0 && model.publisher.first.label
38
+ metadata.oclc_id = model.oclcnum.first if model.oclcnum && model.oclcnum.size > 0
39
+ metadata.source = "VIVO"
40
+ metadata.set_source_to_cornell_vivo
41
+ metadata
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class SetErrorInMetadata
4
+
5
+ ##
6
+ # Set an error message and basic metadata for an error state
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ # @param [String] error message
10
+ #
11
+ # @returns an instance of LD4L::WorksRDF::WorkMetadata with error state set
12
+ def self.call( uri, error_message )
13
+ raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
14
+ uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
15
+
16
+ # TODO it may make more sense for handling of error messages to be in the WorkMessage model itself instead of here
17
+ metadata = LD4L::WorksRDF::WorkMetadata.new(nil)
18
+ metadata.uri = uri
19
+ metadata.title = uri
20
+ metadata.error = true
21
+ metadata.error_message = error_message
22
+ metadata
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateBibframeModelsFromRepository
4
+
5
+ ##
6
+ # Create a Bibframe model and populate it with metadata from the repository.
7
+ #
8
+ # @param [RDF::Repository] repository holding triples
9
+ #
10
+ # @returns an instance of one of the Bibframe work models
11
+ def self.call( bibframe_work_uri, repository )
12
+ raise ArgumentError, 'bibframe_work_uri argument must be a uri string or an instance of RDF::URI' unless
13
+ bibframe_work_uri.kind_of?(String) && bibframe_work_uri.size > 0 || bibframe_work_uri.kind_of?(RDF::URI)
14
+
15
+ raise ArgumentError, 'repository argument must be an instance of RDF::Repository' unless
16
+ repository.kind_of?(RDF::Repository)
17
+
18
+ bibframe_work_uri = RDF::URI(bibframe_work_uri) unless bibframe_work_uri.kind_of?(RDF::URI)
19
+
20
+ # TODO: Move to common place because this code is repeated in each model_from_repository file
21
+ # # Get work as a generic work
22
+ # work = LD4L::WorksRDF::GenericWork.new(uri, :data => repository)
23
+ # types = []
24
+ # work.type.each do |t|
25
+ # types << t.to_s
26
+ # end
27
+
28
+ query = RDF::Query.new({
29
+ :instance => {
30
+ RDF.type => RDFVocabularies::BF.Instance,
31
+ RDFVocabularies::BF.instanceOf => bibframe_work_uri,
32
+ }
33
+ })
34
+ instances = []
35
+ results = query.execute(repository)
36
+ results.each { |r| instances << r.to_hash[:instance] }
37
+ instances
38
+
39
+ work = LD4L::WorksRDF::BibframeWork.new(bibframe_work_uri, :data => repository)
40
+ instance = LD4L::WorksRDF::BibframeInstance.new(instances.first, :data=>repository)
41
+
42
+ { :work => work, :instance => instance }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateGenericModelFromRepository
4
+
5
+ ##
6
+ # Create a OCLC model and populate it with metadata from the repository.
7
+ #
8
+ # @param [RDF::Repository] repository holding triples
9
+ #
10
+ # @returns an instance of one of the OCLC work models
11
+ def self.call( uri, repository )
12
+
13
+ # TODO: Move to common place because this code is repeated in each model_from_repository file
14
+ # Get work as a generic work
15
+ work = LD4L::WorksRDF::GenericWork.new(uri, :data => repository)
16
+ types = []
17
+ work.type.each do |t|
18
+ types << t.to_s
19
+ end
20
+
21
+ # TODO: Need to support multiple types (e.g. book, music, video). Currently only supporting books.
22
+ work = LD4L::WorksRDF::BiboBook.new(uri, :data => repository) if types.include? RDFVocabularies::BIBO.Book.to_s
23
+ work = LD4L::WorksRDF::BiboDocument.new(uri, :data => repository) if types.include? RDFVocabularies::BIBO.Document.to_s
24
+ work = LD4L::WorksRDF::PopulateBibframeModelsFromRepository.call(uri,repository) if types.include?(RDFVocabularies::BF.Work.to_s) || types.include?(RDFVocabularies::BF.Instance.to_s)
25
+ work = LD4L::WorksRDF::SchemaBook.new(uri, :data => repository) if types.include? RDF::SCHEMA.Book.to_s
26
+ work
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateOclcModelFromRepository
4
+
5
+ ##
6
+ # Create a OCLC model and populate it with metadata from the repository.
7
+ #
8
+ # @param [RDF::Repository] repository holding triples
9
+ #
10
+ # @returns an instance of one of the OCLC work models
11
+ def self.call( uri, repository )
12
+
13
+ # TODO: Move to common place because this code is repeated in each model_from_repository file
14
+ # Get work as a generic work
15
+ work = LD4L::WorksRDF::GenericWork.new(uri, :data => repository)
16
+ types = []
17
+ work.type.each do |t|
18
+ types << t.to_s
19
+ end
20
+
21
+ # TODO: Need to support multiple types (e.g. book, music, video). Currently only supporting books.
22
+ work = LD4L::WorksRDF::OclcSchemaBook.new(uri, :data => repository) if types.include? RDF::SCHEMA.Book.to_s
23
+ work
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateVivoModelFromRepository
4
+
5
+ ##
6
+ # Create a VIVO model and populate it with metadata from the repository.
7
+ #
8
+ # @param [RDF::Repository] repository holding triples
9
+ #
10
+ # @returns an instance of one of the VIVO work models
11
+ def self.call( uri, repository )
12
+
13
+ # TODO: Move to common place because this code is repeated in each model_from_repository file
14
+ # Get work as a generic work
15
+ work = LD4L::WorksRDF::GenericWork.new(uri, :data => repository)
16
+ types = []
17
+ work.type.each do |t|
18
+ types << t.to_s
19
+ end
20
+
21
+ # TODO: Need to support multiple types (e.g. book, music, video). Currently only supporting books.
22
+ work = LD4L::WorksRDF::VivoBook.new(uri, :data => repository) if types.include? RDFVocabularies::BIBO.Book.to_s
23
+ work
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetMarcxmlFromURI
4
+
5
+ ##
6
+ # Get marcxml populated from the URI via content negotiation.
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ #
10
+ # @returns a string holding marcxml
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
+ uri = uri.to_s if uri.kind_of?(RDF::URI)
16
+
17
+ http = Curl.get(uri) do |curl|
18
+ curl.headers['Accept'] = 'application/marcxml+xml'
19
+ curl.headers['Content-Type'] = 'application/marcxml+xml'
20
+ curl.headers['Api-Version'] = '2.2'
21
+ curl.follow_location = true
22
+ curl.max_redirects = 3
23
+ curl.connect_timeout = 30
24
+ curl.useragent = "curb"
25
+ end
26
+ header = http.header_str
27
+ response_content_type = LD4L::WorksRDF::ResponseHeader.get_content_type(header)
28
+ raise EncodingError, "uri returned results of type '#{response_content_type}' instead of expected 'application/marcxml+xml'" unless response_content_type == 'application/marcxml+xml'
29
+
30
+ result = http.body_str
31
+ result
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetRdfxmlFromURI
4
+
5
+ ##
6
+ # Get triples as rdfxml populated from the URI via content negotiation.
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ #
10
+ # @returns a string holding triples as rdfxml
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
+ uri = uri.to_s if uri.kind_of?(RDF::URI)
16
+
17
+ http = Curl.get(uri) do |curl|
18
+ curl.headers['Accept'] = 'application/rdf+xml'
19
+ curl.headers['Content-Type'] = 'application/rdf+xml'
20
+ curl.headers['Api-Version'] = '2.2'
21
+ curl.follow_location = true
22
+ curl.max_redirects = 3
23
+ curl.connect_timeout = 30
24
+ curl.useragent = "curb"
25
+ end
26
+ header = http.header_str
27
+ response_content_type = LD4L::WorksRDF::ResponseHeader.get_content_type(header)
28
+ raise EncodingError, "uri returned results of type '#{response_content_type}' instead of expected 'application/rdf+xml'" unless response_content_type == 'application/rdf+xml'
29
+
30
+ result = http.body_str
31
+ result
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,35 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetSolrResultsFromSolrQuery
4
+
5
+ ##
6
+ # Get solr documents populated from the solr query url via content negotiation.
7
+ #
8
+ # @param [String] solr_query_url for the work(s)
9
+ #
10
+ # @returns a string holding solr results which may include multiple solr documents
11
+ def self.call( solr_query_url )
12
+ raise ArgumentError, 'solr_query_url argument must be a uri string' unless solr_query_url.kind_of?(String)
13
+
14
+ http = Curl.get(solr_query_url) do |curl|
15
+ curl.headers['Accept'] = 'application/xml'
16
+ curl.headers['Api-Version'] = '2.2'
17
+ curl.follow_location = true
18
+ curl.max_redirects = 3
19
+ curl.connect_timeout = 30
20
+ curl.useragent = "curb"
21
+ end
22
+ header = http.header_str
23
+
24
+ status = LD4L::WorksRDF::ResponseHeader.get_status(header)
25
+ raise EncodingError, "Status #{status} returned from query" unless status == '200'
26
+
27
+ response_content_type = LD4L::WorksRDF::ResponseHeader.get_content_type(header)
28
+ raise EncodingError, "uri returned results of type '#{response_content_type}' instead of expected 'application/xml'" unless response_content_type == 'application/xml'
29
+
30
+ results = http.body_str
31
+ results
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class GetTurtleFromURI
4
+
5
+ ##
6
+ # Get triples as turtle populated from the URI via content negotiation.
7
+ #
8
+ # @param [String, RDF::URI] uri for the work
9
+ #
10
+ # @returns a string holding triples as turtle
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
+ uri = uri.to_s if uri.kind_of?(RDF::URI)
16
+
17
+ http = Curl.get(uri) do |curl|
18
+ curl.headers['Accept'] = 'text/turtle'
19
+ curl.headers['Content-Type'] = 'text/turtle'
20
+ curl.headers['Api-Version'] = '2.2'
21
+ curl.follow_location = true
22
+ curl.max_redirects = 3
23
+ curl.connect_timeout = 30
24
+ curl.useragent = "curb"
25
+ end
26
+ header = http.header_str
27
+ response_content_type = LD4L::WorksRDF::ResponseHeader.get_content_type(header)
28
+ raise EncodingError, "uri returned results of type '#{response_content_type}' instead of expected 'text/turtle'" unless response_content_type == 'text/turtle'
29
+
30
+ result = http.body_str
31
+ result
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,51 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class ResponseHeader
4
+
5
+ def self.get_content_type( header )
6
+ parsed_header = self.parse(header)
7
+ content_type = parsed_header["Content-Type"]
8
+ content_type = content_type[0] if content_type && content_type.kind_of?(Array) && content_type.size > 0
9
+ content_type
10
+ end
11
+
12
+ def self.get_status( header )
13
+ parsed_header = self.parse(header)
14
+ parsed_header["Status"]
15
+ end
16
+
17
+ # "HTTP/1.1 400 Bad Request\r\n
18
+ # Date: Sat, 22 Aug 2015 18:49:49 GMT\r\n
19
+ # Last-Modified: Sat, 22 Aug 2015 18:49:49 GMT\r\n
20
+ # ETag: \"14f56bed06e\"\r\n
21
+ # Cache-Control: no-cache, no-store\r\n
22
+ # Pragma: no-cache\r\n
23
+ # Expires: Sat, 01 Jan 2000 01:00:00 GMT\r\n
24
+ # Content-Type: application/xml;charset=UTF-8\r\n
25
+ # Connection: close\r\n\r\n"
26
+
27
+ def self.parse(header)
28
+ parts_hash = {}
29
+ parts_array = header.split("\r\n")
30
+ parts_array.each do |p|
31
+ match_data = p.match("(.*): (.*)")
32
+ value = nil
33
+ field = "Status" if p.start_with? "HTTP/1.1"
34
+ value = p[9..11] if p.start_with? "HTTP/1.1"
35
+ field = match_data[1] if match_data && match_data.size > 1
36
+ value = match_data[2] if match_data && match_data.size > 2
37
+ semicolon_split = value.split(";") if value
38
+ comma_split = value.split(",") if value
39
+ if semicolon_split && semicolon_split.size > 1
40
+ value = semicolon_split.collect { |v| v.strip }
41
+ elsif comma_split && comma_split.size > 1
42
+ value = comma_split.collect { |v| v.strip }
43
+ end
44
+ parts_hash[field] = value if value
45
+ end
46
+ parts_hash
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateGraphFromRdfxml
4
+
5
+ ##
6
+ # Create an RDF::Graph populated rdfxml triples
7
+ #
8
+ # @param [String] triples represented in rdfxml
9
+ #
10
+ # @returns a populated graph with passed in rdfxml triples
11
+ def self.call( rdfxml )
12
+ raise ArgumentError, 'rdfxml argument must be a non-empty string' unless
13
+ rdfxml.kind_of?(String) && rdfxml.size > 0
14
+
15
+ RDF::Graph.new.from_rdfxml rdfxml
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,21 @@
1
+ module LD4L
2
+ module WorksRDF
3
+ class PopulateGraphFromTurtle
4
+
5
+ ##
6
+ # Create an RDF::Graph populated turtle triples
7
+ #
8
+ # @param [String] triples represented in turtle
9
+ #
10
+ # @returns a populated graph with passed in turtle triples
11
+ def self.call( turtle )
12
+ raise ArgumentError, 'turtle argument must be a non-empty string' unless
13
+ turtle.kind_of?(String) && turtle.size > 0
14
+
15
+ RDF::Graph.new.from_ttl turtle
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+