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

Included in:
DiscogsInstanceBuilder, DiscogsTranslation, DiscogsWorksBuilder
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



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

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



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

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



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

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

#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



62
63
64
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 62

def discogs_formats
  DISCOGS_FORMATS_MAPPING
end

#discogs_genresObject



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

def discogs_genres
  DISCOGS_GENRE_MAPPING
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