Module: Qa::Authorities::Discogs::DiscogsUtils

Included in:
DiscogsInstanceBuilder, DiscogsTranslation, DiscogsWorksBuilder, GenericAuthority
Defined in:
lib/qa/authorities/discogs/discogs_utils.rb

Constant Summary collapse

DISCOGS_GENRE_MAPPING =
YAML.load_file(Rails.root.join("config", "discogs-genres.yml"))
DISCOGS_FORMATS_MAPPING =
YAML.load_file(Rails.root.join("config", "discogs-formats.yml"))

Instance Method Summary collapse

Instance Method Details

#bf_agent_predicateObject



42
43
44
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 42

def bf_agent_predicate
  RDF::URI("http://id.loc.gov/ontologies/bibframe/agent")
end

#bf_agent_type_objectObject



46
47
48
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 46

def bf_agent_type_object
  "http://id.loc.gov/ontologies/bibframe/Agent"
end

#bf_main_title_predicateObject



38
39
40
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 38

def bf_main_title_predicate
  RDF::URI("http://id.loc.gov/ontologies/bibframe/mainTitle")
end

#bf_role_predicateObject



50
51
52
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 50

def bf_role_predicate
  RDF::URI("http://id.loc.gov/ontologies/bibframe/role")
end

#bf_role_type_objectObject



54
55
56
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 54

def bf_role_type_object
  "http://id.loc.gov/ontologies/bibframe/Role"
end

#build_playing_speed_stmts(label, count) ⇒ Array

Returns rdf statements.

Parameters:

  • the (String)

    playing speed in string format

  • gives (Integer)

    the playing speed a unique uri

Returns:

  • (Array)

    rdf statements



127
128
129
130
131
132
133
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 127

def build_playing_speed_stmts(label, count)
  stmts = []
  stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", "speed#{count}")
  stmts << contruct_stmt_uri_object("speed#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlayingSpeed")
  stmts << contruct_stmt_literal_object("speed#{count}", rdfs_label_predicate, label)
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
end

#build_role_stmts(subject_node, role_node, label) ⇒ Array

Returns rdf statements.

Parameters:

  • the (Hash)

    extraartists defined at the release level, not the track level

  • gives (Integer)

    the role a unique uri

  • the (String)

    entity type name

Returns:

  • (Array)

    rdf statements



116
117
118
119
120
121
122
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 116

def build_role_stmts(subject_node, role_node, label)
  stmts = []
  stmts << contruct_stmt_uri_object(subject_node, bf_role_predicate, role_node)
  stmts << contruct_stmt_uri_object(role_node, rdf_type_predicate, bf_role_type_object)
  stmts << contruct_stmt_literal_object(role_node, rdfs_label_predicate, label)
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
end

#build_year_statements(response) ⇒ Array

both the work and the instance require a statement for the release year

Parameters:

  • the (Hash)

    http response from discogs

Returns:

  • (Array)

    rdf statements



104
105
106
107
108
109
110
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 104

def build_year_statements(response)
  year_stmts = []
  year_stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "daten1")
  year_stmts << contruct_stmt_uri_object("daten1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Publication")
  year_stmts << contruct_stmt_literal_object("daten1", RDF::URI("http://id.loc.gov/ontologies/bibframe/date"), response["released"].to_s)
  year_stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
end

#check_for_msg_response(release_resp, master_resp) ⇒ String

Returns status information.

Parameters:

  • json

    results

  • json

    results

Returns:

  • (String)

    status information



91
92
93
94
95
96
97
98
99
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 91

def check_for_msg_response(release_resp, master_resp)
  if release_resp.key?("message") && master_resp.key?("message")
    "no responses"
  elsif !release_resp.key?("message") && !master_resp.key?("message")
    "two responses"
  else
    "mixed"
  end
end

#contruct_stmt_literal_object(subject, predicate, object) ⇒ Class

Constructs an RDF statement where the subject and predicate are URIs and the object is a literal

Parameters:

  • either (String)

    a string used to create a unique URI or an LOC uri in string format

  • or (String)
    Class

    either a BIBFRAME property uri in string format or an RDF::URI

  • or (String)
    Class

    strings can be a label or BIBFRAME class uri; class is always RDF::URI

Returns:

  • (Class)

    RDF::Statement with a literal as the object



24
25
26
27
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 24

def contruct_stmt_literal_object(subject, predicate, object)
  s = subject.include?("http") ? RDF::URI.new(subject) : subject.to_sym
  RDF::Statement(s, RDF::URI(predicate), RDF::Literal.new(object))
end

#contruct_stmt_uri_object(subject, predicate, object) ⇒ Class

Constructs an RDF statement where the subject, predicate and object are all URIs

Parameters:

  • either (String)

    a string used to create a unique URI or an LOC uri in string format

  • or (String)
    Class

    either a BIBFRAME property uri in string format or an RDF::URI

  • or (String)
    Class

    strings can be a label or BIBFRAME class uri; class is always RDF::URI

Returns:

  • (Class)

    RDF::Statement with either a uri or a bnode as the object



13
14
15
16
17
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 13

def contruct_stmt_uri_object(subject, predicate, object)
  s = subject.include?("http") ? RDF::URI.new(subject) : subject.to_sym
  o = object.to_s.include?("http") ? RDF::URI.new(object) : object.to_sym
  RDF::Statement(s, RDF::URI(predicate), o)
end

#discogs_formatsObject



84
85
86
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 84

def discogs_formats
  DISCOGS_FORMATS_MAPPING
end

#discogs_genresObject



80
81
82
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 80

def discogs_genres
  DISCOGS_GENRE_MAPPING
end

#format(tc) ⇒ Object



58
59
60
61
62
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 58

def format(tc)
  return 'json' unless tc.params.key?('format')
  return 'json' if tc.params['format'].blank?
  tc.params['format']
end

#graph_format?(tc) ⇒ Boolean

Returns:

  • (Boolean)


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

def graph_format?(tc)
  jsonld?(tc) || n3?(tc) || ntriples?(tc)
end

#jsonld?(tc) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 64

def jsonld?(tc)
  format(tc).casecmp?('jsonld')
end

#n3?(tc) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 68

def n3?(tc)
  format(tc).casecmp?('n3')
end

#ntriples?(tc) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 72

def ntriples?(tc)
  format(tc).casecmp?('ntriples')
end

#rdf_type_predicateObject

frequently used predicates and objects



30
31
32
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 30

def rdf_type_predicate
  RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
end

#rdfs_label_predicateObject



34
35
36
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 34

def rdfs_label_predicate
  RDF::URI("http://www.w3.org/2000/01/rdf-schema#label")
end