Module: Qa::Authorities::Discogs::DiscogsWorksBuilder

Includes:
DiscogsUtils
Included in:
DiscogsTranslation
Defined in:
lib/qa/authorities/discogs/discogs_works_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

Methods included from DiscogsUtils

#bf_agent_predicate, #bf_agent_type_object, #bf_main_title_predicate, #bf_role_predicate, #bf_role_type_object, #build_playing_speed_stmts, #build_role_stmts, #build_year_statements, #check_for_msg_response, #contruct_stmt_literal_object, #contruct_stmt_uri_object, #discogs_formats, #discogs_genres, #format, #graph_format?, #jsonld?, #n3?, #ntriples?, #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

Parameters:

  • artists (Array)

    from discogs

Returns:

  • (Array)

    either the tracklist “artists” or the primary artists



76
77
78
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 76

def build_artist_array(artists)
  artists.present? ? artists : primary_artists
end

#build_genres(genre) ⇒ Array

map discogs genre to LOC genreForm

Parameters:

  • the (String)

    name of a discogs style or genre

Returns:

  • (Array)

    rdf statements



43
44
45
46
47
48
49
50
51
52
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 43

def build_genres(genre)
  stmts = []
  dg = discogs_genres[genre.gsub(/\s+/, "")]
  if dg.present?
    stmts << contruct_stmt_uri_object(work_uri, "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_secondary_works(track, w_count) ⇒ Array

Returns rdf statements.

Parameters:

  • discogs (Hash)

    artists associated with the main work (master or release)

  • used (Integer)

    to give unique URIS for works

Returns:

  • (Array)

    rdf statements



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 83

def build_secondary_works(track, w_count)
  stmts = []
  stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/hasPart", "workn#{w_count}")
  stmts << contruct_stmt_uri_object("workn#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work")
  stmts << contruct_stmt_uri_object("workn#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio")
  stmts << contruct_stmt_uri_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/title", "titlen3#{w_count}")
  stmts << contruct_stmt_uri_object("titlen3#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title")
  stmts << contruct_stmt_literal_object("titlen3#{w_count}", bf_main_title_predicate, track["title"])
  stmts << contruct_stmt_literal_object("workn#{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.

Parameters:

  • discogs (Array)

    artists associated with the main work (master or release)

  • used (Integer)

    to give unique URIS for works and primary contributions

Returns:

  • (Array)

    rdf statements



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 98

def build_track_artists(artists, w_count)
  stmts = []
  count = 1
  artists.each do |artist|
    stmts << contruct_stmt_uri_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn#{w_count}#{count}")
    stmts << contruct_stmt_uri_object("contrbn#{w_count}#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution")
    stmts << contruct_stmt_uri_object("contrbn#{w_count}#{count}", bf_agent_predicate, "agentn#{w_count}#{count}")
    stmts << contruct_stmt_uri_object("agentn#{w_count}#{count}", rdf_type_predicate, bf_agent_type_object)
    stmts << contruct_stmt_literal_object("agentn#{w_count}#{count}", rdfs_label_predicate, artist["name"])
    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.

Parameters:

  • discogs (Array)

    extraartists associated with a track

  • used (Integer)

    to give unique URIS for works, contributions and roles

Returns:

  • (Array)

    rdf statements



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 115

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("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn#{w_count}2#{count}")
    stmts << contruct_stmt_uri_object("contrbn#{w_count}2#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
    stmts << contruct_stmt_uri_object("contrbn#{w_count}2#{count}", bf_agent_predicate, "agentn#{w_count}2#{count}")
    stmts << contruct_stmt_uri_object("agentn#{w_count}2#{count}", rdf_type_predicate, bf_agent_type_object)
    stmts << contruct_stmt_literal_object("agentn#{w_count}2#{count}", rdfs_label_predicate, artist["name"])
    stmts += build_role_stmts("agentn#{w_count}2#{count}", "role2#{w_count}#{count}", 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.

Parameters:

  • the (Hash)

    http response from discogs

Returns:

  • (Array)

    rdf statements



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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(work_uri, "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn1#{count}")
    stmts << contruct_stmt_uri_object("contrbn1#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
    stmts << contruct_stmt_uri_object("contrbn1#{count}", bf_agent_predicate, "agentn1#{count}")
    stmts << contruct_stmt_uri_object("agentn1#{count}", rdf_type_predicate, bf_agent_type_object)
    stmts << contruct_stmt_literal_object("agentn1#{count}", rdfs_label_predicate, artist["name"])
    stmts += build_role_stmts("agentn1#{count}", "rolen1#{count}", artist["role"])
    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.

Parameters:

  • the (Hash)

    http response from discogs

Returns:

  • (Array)

    rdf statements



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 28

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.

Parameters:

  • the (Hash)

    http response from discogs

Returns:

  • (Array)

    rdf statements



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/qa/authorities/discogs/discogs_works_builder.rb', line 56

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