Module: Qa::Authorities::Discogs::DiscogsWorksBuilder
- Includes:
- DiscogsUtils
- Included in:
- DiscogsTranslation
- Defined in:
- lib/qa/authorities/discogs/discogs_works_builder.rb
Overview
rubocop:disable Metrics/ModuleLength
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_artist_array(artists) ⇒ Array
If the tracklist does not include the primary artists, use the ones defined at the master or release level.
-
#build_artist_role_stmts(artist, count) ⇒ Array
Rdf statements.
-
#build_genres(genre) ⇒ Array
map discogs genre to LOC genreForm.
-
#build_genres_and_styles(uri, dg_label) ⇒ Array
Rdf statements.
-
#build_secondary_works(track, w_count) ⇒ Array
Rdf statements.
-
#build_track_artists(artists, w_count) ⇒ Array
Rdf statements.
-
#build_track_extraartists(extraartists, w_count) ⇒ Array
Rdf statements.
-
#get_extra_artists_stmts(response) ⇒ Array
Rdf statements.
-
#get_genres_stmts(response) ⇒ Array
Rdf statements.
-
#get_tracklist_artists_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_artist_array(artists) ⇒ Array
If the tracklist does not include the primary artists, use the ones defined at the master or release level
97 98 99 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 97 def build_artist_array(artists) artists.present? ? artists : primary_artists end |
#build_artist_role_stmts(artist, count) ⇒ Array
Returns rdf statements.
28 29 30 31 32 33 34 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 28 def build_artist_role_stmts(artist, count) stmts = [] stmts << contruct_stmt_uri_object(artist["name"], bf_role_predicate, "Work1SecondaryContributor_Role#{count}") stmts << contruct_stmt_uri_object("Work1SecondaryContributor_Role#{count}", rdf_type_predicate, bf_role_type_object) stmts << contruct_stmt_literal_object("Work1SecondaryContributor_Role#{count}", rdfs_label_predicate, artist["role"]) stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_genres(genre) ⇒ Array
map discogs genre to LOC genreForm
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 53 def build_genres(genre) stmts = [] dg = discogs_genres[genre.gsub(/\s+/, "")] if dg.present? stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/genreForm", dg["uri"]) stmts << contruct_stmt_uri_object(dg["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/GenreForm") stmts << contruct_stmt_literal_object(dg["uri"], rdfs_label_predicate, dg["label"]) end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_genres_and_styles(uri, dg_label) ⇒ Array
Returns rdf statements.
67 68 69 70 71 72 73 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 67 def build_genres_and_styles(uri, dg_label) stmts = [] stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/genreForm", uri) stmts << contruct_stmt_uri_object(uri, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/GenreForm") stmts << contruct_stmt_literal_object(uri, rdfs_label_predicate, dg_label) stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_secondary_works(track, w_count) ⇒ Array
Returns rdf statements.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 104 def build_secondary_works(track, w_count) stmts = [] stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/hasPart", "Work#{w_count}") stmts << contruct_stmt_uri_object("Work#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work") stmts << contruct_stmt_uri_object("Work#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio") stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/title", "Work#{w_count}Title") stmts << contruct_stmt_uri_object("Work#{w_count}Title", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title") stmts << contruct_stmt_literal_object("Work#{w_count}Title", bf_main_title_predicate, track["title"]) stmts << contruct_stmt_literal_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/duration", track["duration"]) if track["duration"].present? stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_track_artists(artists, w_count) ⇒ Array
Returns rdf statements.
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 119 def build_track_artists(artists, w_count) stmts = [] count = 1 artists.each do |artist| stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "Work#{w_count}PrimaryContribution#{count}") stmts << contruct_stmt_uri_object("Work#{w_count}PrimaryContribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution") stmts << contruct_stmt_uri_object("Work#{w_count}PrimaryContribution#{count}", bf_agent_predicate, artist["name"]) stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#build_track_extraartists(extraartists, w_count) ⇒ Array
Returns rdf statements.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 135 def build_track_extraartists(extraartists, w_count) stmts = [] # to distinguish among contributors to a track/work and their roles count = 1 extraartists.each do |artist| stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "Work#{w_count}Contribution#{count}") stmts << contruct_stmt_uri_object("Work#{w_count}Contribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution") stmts << contruct_stmt_uri_object("Work#{w_count}Contribution#{count}", bf_agent_predicate, artist["name"]) stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object) stmts << contruct_stmt_uri_object(artist["name"], bf_role_predicate, "Work#{w_count}ContributorRole#{count}") stmts << contruct_stmt_uri_object("Work#{w_count}ContributorRole#{count}", rdf_type_predicate, bf_role_type_object) stmts << contruct_stmt_literal_object("Work#{w_count}ContributorRole#{count}", rdfs_label_predicate, artist["role"]) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_extra_artists_stmts(response) ⇒ Array
Returns rdf statements.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 9 def get_extra_artists_stmts(response) stmts = [] # can have multiple artists as primary contributors to the work; need to distinguish among them count = 1 return stmts unless response["extraartists"].present? response["extraartists"].each do |artist| stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/contribution", "Work1SecondaryContribution#{count}") stmts << contruct_stmt_uri_object("Work1SecondaryContribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution") stmts << contruct_stmt_uri_object("Work1SecondaryContribution#{count}", bf_agent_predicate, artist["name"]) stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object) stmts += build_artist_role_stmts(artist, count) count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_genres_stmts(response) ⇒ Array
Returns rdf statements.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 38 def get_genres_stmts(response) stmts = [] all_genres = [] all_genres += response["genres"] if response["genres"].present? all_genres += response["styles"] if response["styles"].present? return stmts unless all_genres.any? all_genres.each do |genre| stmts.concat(build_genres(genre)) end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |
#get_tracklist_artists_stmts(response) ⇒ Array
Returns rdf statements.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 77 def get_tracklist_artists_stmts(response) stmts = [] # individual tracks become secondary works; need to distinguish among them w_count = 2 return stmts unless response["tracklist"].present? response["tracklist"].each do |track| stmts.concat(build_secondary_works(track, w_count)) # If the Discogs data includes the primary artists for each track, use those. If not, # use the primary artists that are associated with the main work artist_array = build_artist_array(track["artists"]) stmts.concat(build_track_artists(artist_array, w_count)) stmts.concat(build_track_extraartists(track["extraartists"], w_count)) if track["extraartists"].present? w_count += 1 end stmts # w/out this line, building the graph throws an undefined method `graph_name=' error end |