Class: LD4L::WorksRDF::GetMetadataFromSolrDoc
- Inherits:
-
Object
- Object
- LD4L::WorksRDF::GetMetadataFromSolrDoc
- Defined in:
- lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb
Class Method Summary collapse
-
.call(solr_doc, solr_field_translations) ⇒ Object
TODO This is Cornell specific.
- .flatten(solr_doc) ⇒ Object
- .interpret_str(str_field) ⇒ Object
- .populate_with_solr_values(solr_doc, solr_field_translations) ⇒ Object
Class Method Details
.call(solr_doc, solr_field_translations) ⇒ Object
TODO This is Cornell specific. Need a general processor of solr OR a callback to an institution specific processor.
Get metadata from solr document.
13 14 15 16 17 18 |
# File 'lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb', line 13 def self.call( solr_doc, solr_field_translations ) flat_doc = flatten(solr_doc["arr"]) flat_doc.merge! interpret_str(solr_doc["str"]) = self.populate_with_solr_values(flat_doc, solr_field_translations) end |
.flatten(solr_doc) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb', line 47 def self.flatten( solr_doc ) flat_hash = {} solr_doc.each do |h| name = h["name"] value = h["str"] flat_hash[name] = value end flat_hash end |
.interpret_str(str_field) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb', line 57 def self.interpret_str( str_field ) flat_hash = {} flat_hash["id"] = str_field.first flat_hash["author"] = str_field[1] if str_field.size > 3 flat_hash["title"] = str_field.last flat_hash end |
.populate_with_solr_values(solr_doc, solr_field_translations) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb', line 20 def self.populate_with_solr_values( solr_doc, solr_field_translations ) = LD4L::WorksRDF::WorkMetadata.new() .source = "Cornell Library" .set_source_to_cornell_library # metadata.format = solr_doc["format"].upcase.to_sym .set_type(solr_doc["format"]) .local_id = solr_doc["id"] .uri = "https://newcatalog.library.cornell.edu/catalog/"+.local_id .title = solr_doc["title"] . = solr_doc["author"] .pub_date = solr_doc["pub_date_display"] .pub_info = solr_doc["pub_info_display"] .language = solr_doc["language_display"] .edition = solr_doc["edition_display"] other_ids = solr_doc["other_id_display"] oclc_id = nil oclc_id = other_ids.select { |id| id.start_with? "(OCoLC)" } if other_ids.is_a? Array oclc_id = oclc_id.first if (oclc_id.is_a? Array) && (oclc_id.size > 0) oclc_id = other_ids if (other_ids.is_a? String) && (other_ids.start_with? "(OCoLC)") .oclc_id = oclc_id[7..-1] unless (oclc_id.nil?) || (!oclc_id.is_a? String) end |