Module: Qa::Authorities::Discogs::DiscogsInstanceBuilder
- Includes:
- DiscogsUtils
- Included in:
- DiscogsTranslation
- Defined in:
- lib/qa/authorities/discogs/discogs_instance_builder.rb
Constant Summary
Constants included from DiscogsUtils
Qa::Authorities::Discogs::DiscogsUtils::DISCOGS_FORMATS_MAPPING, Qa::Authorities::Discogs::DiscogsUtils::DISCOGS_GENRE_MAPPING
Instance Method Summary collapse
-
#build_base_materials(name) ⇒ Array
Rdf statements.
-
#build_format_characteristics(df, count) ⇒ Array
Rdf statements.
-
#build_format_desc_stmts(descs, count) ⇒ Array
Rdf statements.
-
#build_format_name_stmts(name) ⇒ Array
map discogs name field to the corresponding LOC carrier.
-
#build_provision_activity_stmts(activities) ⇒ Array
Rdf statements.
-
#get_format_stmts(response) ⇒ Array
Rdf statements.
-
#get_identifiers_stmts(response) ⇒ Array
Rdf statements.
-
#get_labels_stmts(response) ⇒ Array
Rdf statements.
Methods included from DiscogsUtils
#bf_agent_predicate, #bf_agent_type_object, #bf_main_title_predicate, #bf_role_predicate, #bf_role_type_object, #build_year_statements, #contruct_stmt_literal_object, #contruct_stmt_uri_object, #discogs_formats, #discogs_genres, #get_year_rdf, #rdf_type_predicate, #rdfs_label_predicate
Instance Method Details
#build_base_materials(name) ⇒ Array
Returns rdf statements.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 114 def build_base_materials(name) stmts = [] return stmts unless name == "Vinyl" || name == "Shellac" id = name == "Vinyl" ? "300014502" : "300014918" stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/baseMaterial", "http://vocab.getty.edu/aat/" + id) stmts << contruct_stmt_uri_object("http://vocab.getty.edu/aat/" + id, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/BaseMaterial") stmts << contruct_stmt_literal_object("http://vocab.getty.edu/aat/" + id, rdfs_label_predicate, name) stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_format_characteristics(df, count) ⇒ Array
Returns rdf statements.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 76 def build_format_characteristics(df, count) stmts = [] case df["type"] when "playbackChannel" stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", df["uri"]) stmts << contruct_stmt_uri_object(df["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlaybackChannel") stmts << contruct_stmt_literal_object(df["uri"], rdfs_label_predicate, df["label"]) when "dimension" stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/dimensions", df["label"]) when "playingSpeed" stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", "PlayingSpeed#{count}") stmts << contruct_stmt_uri_object("PlayingSpeed#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlayingSpeed") stmts << contruct_stmt_literal_object("PlayingSpeed#{count}", rdfs_label_predicate, df["label"]) end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_format_desc_stmts(descs, count) ⇒ Array
Returns rdf statements.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 58 def build_format_desc_stmts(descs, count) stmts = [] return stmts unless descs.present? descs.each do |desc| # map discogs description field to the corresponding LOC type df = discogs_formats[desc.gsub(/\s+/, "")] if df.present? stmts += build_format_characteristics(df, count) else stmts << contruct_stmt_literal_object("Instance1", "http://id.loc.gov/ontologies/bibframe/editionStatement", desc) end end stmts end |
#build_format_name_stmts(name) ⇒ Array
map discogs name field to the corresponding LOC carrier
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 96 def build_format_name_stmts(name) stmts = [] return stmts unless name.present? dc = discogs_formats[name.gsub(/\s+/, "")] if dc.present? stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/carrier", dc["uri"]) stmts << contruct_stmt_uri_object(dc["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Carrier") stmts << contruct_stmt_literal_object(dc["uri"], rdfs_label_predicate, dc["label"]) stmts.concat(build_base_materials(name)) else # if it's not a carrier, it's an edition statement stmts << contruct_stmt_literal_object("Instance1", "http://id.loc.gov/ontologies/bibframe/editionStatement", name) end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_provision_activity_stmts(activities) ⇒ Array
Returns rdf statements.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 127 def build_provision_activity_stmts(activities) stmts = [] # need to distinguish among different provision activities and roles count = 1 activities.each do |activity| stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/provisionActivity", "ProvisionActivity#{count}") stmts << contruct_stmt_uri_object("ProvisionActivity#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity") stmts << contruct_stmt_uri_object("ProvisionActivity#{count}", bf_agent_predicate, activity["name"]) stmts << contruct_stmt_uri_object(activity["name"], rdf_type_predicate, bf_agent_type_object) stmts << contruct_stmt_uri_object(activity["name"], bf_role_predicate, "PA_Role#{count}") stmts << contruct_stmt_uri_object("PA_Role#{count}", rdf_type_predicate, bf_role_type_object) stmts << contruct_stmt_literal_object("PA_Role#{count}", rdfs_label_predicate, activity["entity_type_name"]) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_format_stmts(response) ⇒ Array
Returns rdf statements.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 9 def get_format_stmts(response) stmts = [] # The Discogs formats array contains several types of information: the "name" field defines the type of # audio disc (e.g., CD vs vinyl), and the "descriptions" field can contain the playing speed, playback # and release information. Process the "name" field first, then the "descriptions" # In unusual cases, there can be multiple playing speeds. Need to distinguish among them. count = 1 return stmts unless response["formats"].present? response["formats"].each do |format| stmts.concat(build_format_name_stmts(format["name"])) # Now process playing speed, playback channel and release info stmts.concat(build_format_desc_stmts(format["descriptions"], count)) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_identifiers_stmts(response) ⇒ Array
Returns rdf statements.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 41 def get_identifiers_stmts(response) stmts = [] # The Discogs data includes identifiers such as side label codes and rights society codes. count = 1 return stmts unless response["identifiers"].present? response["identifiers"].each do |activity| stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/identifiedBy", "Identifier#{count}") stmts << contruct_stmt_uri_object("Identifier#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier") stmts << contruct_stmt_literal_object("Identifier#{count}", rdfs_label_predicate, activity["value"]) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_labels_stmts(response) ⇒ Array
Returns rdf statements.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 28 def get_labels_stmts(response) stmts = [] # Various roles are defined as provision activities, such as the record company (or label), # the publishing house, the recording studio, etc. These are defined separately in the Discogs # data, so combine them into a single array to be processed in one iteration. provision_activity_array = response["labels"] if response["labels"].present? provision_activity_array += response["companies"] if response["companies"].present? stmts += build_provision_activity_stmts(provision_activity_array) if provision_activity_array.present? stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |