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

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_base_materials(name) ⇒ Array

Returns rdf statements.

Parameters:

  • format (String)

    name

Returns:

  • (Array)

    rdf statements



113
114
115
116
117
118
119
120
121
122
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 113

def build_base_materials(name)
  stmts = []
  return stmts unless name == "Vinyl" || name == "Shellac"
  id = name == "Vinyl" ? "300014502" : "300014918"

  stmts << contruct_stmt_uri_object(instance_uri, "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.

Parameters:

  • discogs (Hash)

    format descriptions “translated” to BIBFRAME terms

  • incremented (Integer)

    on the call from build_format_desc_stmts

Returns:

  • (Array)

    rdf statements



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 77

def build_format_characteristics(df, count)
  stmts = []
  case df["type"]
  when "playbackChannel"
    stmts << contruct_stmt_uri_object(instance_uri, "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_literal_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/dimensions", df["label"])
  when "playingSpeed"
    stmts.concat(build_playing_speed_stmts(df["label"], count))
  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.

Parameters:

  • format (Array)

    descriptions discogs

  • incremented (Integer)

    on the call from get_format_stmts

Returns:

  • (Array)

    rdf statements



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

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(instance_uri, "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

Parameters:

  • format (String)

    name

Returns:

  • (Array)

    rdf statements



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

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(instance_uri, "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(instance_uri, "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.

Parameters:

  • discogs (Array)

    roles “translated” into BIBFRAME provisional activities

Returns:

  • (Array)

    rdf statements



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/qa/authorities/discogs/discogs_instance_builder.rb', line 126

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(instance_uri, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "proact#{count}")
    stmts << contruct_stmt_uri_object("proact#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity")
    stmts << contruct_stmt_uri_object("proact#{count}", bf_agent_predicate, "agentn3#{count}")
    stmts << contruct_stmt_uri_object("agentn3#{count}", rdf_type_predicate, bf_agent_type_object)
    stmts << contruct_stmt_literal_object("agentn3#{count}", rdfs_label_predicate, activity["name"])
    stmts += build_role_stmts("agentn3#{count}", "role3#{count}", 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.

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_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.

Parameters:

  • the (Hash)

    http response from discogs

Returns:

  • (Array)

    rdf statements



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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(instance_uri, "http://id.loc.gov/ontologies/bibframe/identifiedBy", "iidn#{count}")
    stmts << contruct_stmt_uri_object("iidn#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier")
    stmts << contruct_stmt_literal_object("iidn#{count}", rdfs_label_predicate, activity["value"])
    count += 1
  end
  stmts.concat(build_year_statements(response)) if response["released"].present?
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
end

#get_labels_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
# 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