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



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

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

#bf_agent_type_objectObject



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

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

#bf_main_title_predicateObject



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

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

#bf_role_predicateObject



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

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

#bf_role_type_objectObject



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

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

#build_year_statements(response, type) ⇒ Array

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

Parameters:

  • the (Hash)

    http response from discogs

  • either (String)

    “Work” or “Instance”

Returns:

  • (Array)

    rdf statements



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

def build_year_statements(response, type)
  year_stmts = []
  if type == "Work" && response["year"].present?
    year_stmts = get_year_rdf(type + "1", response["year"])
  elsif response["released"].present?
    year_stmts = get_year_rdf(type + "1", response["released"])
  end
  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



22
23
24
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 22

def contruct_stmt_literal_object(subject, predicate, object)
  RDF::Statement(RDF::URI.new(subject), 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 uri as the object



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

def contruct_stmt_uri_object(subject, predicate, object)
  RDF::Statement(RDF::URI.new(subject), RDF::URI(predicate), RDF::URI.new(object))
end

#discogs_formatsObject



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

def discogs_formats
  DISCOGS_FORMATS_MAPPING
end

#discogs_genresObject



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

def discogs_genres
  DISCOGS_GENRE_MAPPING
end

#get_year_rdf(type, year) ⇒ Array

Returns rdf statements.

Parameters:

  • either (String)

    “Work1” or “Instance1”

  • 4-digit (String)

    year in string format

Returns:

  • (Array)

    rdf statements



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

def get_year_rdf(type, year)
  year_stmts = []
  year_stmts << contruct_stmt_uri_object(type, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "#{type}ProvisionActivityDate")
  year_stmts << contruct_stmt_uri_object("#{type}ProvisionActivityDate", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity")
  # Full RDF statement syntax as this one requires a datatype
  year_stmts << RDF::Statement(RDF::URI.new("#{type}ProvisionActivityDate"), RDF::URI("http://id.loc.gov/ontologies/bibframe/date"), RDF::Literal.new(year.to_s, datatype: RDF::XSD.date))
end

#rdf_type_predicateObject

frequently used predicates and objects



27
28
29
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 27

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

#rdfs_label_predicateObject



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

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