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
- #bf_agent_predicate ⇒ Object
- #bf_agent_type_object ⇒ Object
- #bf_main_title_predicate ⇒ Object
- #bf_role_predicate ⇒ Object
- #bf_role_type_object ⇒ Object
-
#build_playing_speed_stmts(label, count) ⇒ Array
Rdf statements.
-
#build_role_stmts(subject_node, role_node, label) ⇒ Array
Rdf statements.
-
#build_year_statements(response) ⇒ Array
both the work and the instance require a statement for the release year.
-
#check_for_msg_response(release_resp, master_resp) ⇒ String
Status information.
-
#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.
-
#contruct_stmt_uri_object(subject, predicate, object) ⇒ Class
Constructs an RDF statement where the subject, predicate and object are all URIs.
- #discogs_formats ⇒ Object
- #discogs_genres ⇒ Object
- #format(tc) ⇒ Object
- #graph_format?(tc) ⇒ Boolean
- #jsonld?(tc) ⇒ Boolean
- #n3?(tc) ⇒ Boolean
- #ntriples?(tc) ⇒ Boolean
-
#rdf_type_predicate ⇒ Object
frequently used predicates and objects.
- #rdfs_label_predicate ⇒ Object
Instance Method Details
#bf_agent_predicate ⇒ Object
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_object ⇒ Object
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_predicate ⇒ Object
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_predicate ⇒ Object
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_object ⇒ Object
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.
127 128 129 130 131 132 133 |
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 127 def (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.
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
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.
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
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
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_formats ⇒ Object
84 85 86 |
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 84 def discogs_formats DISCOGS_FORMATS_MAPPING end |
#discogs_genres ⇒ Object
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
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
64 65 66 |
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 64 def jsonld?(tc) format(tc).casecmp?('jsonld') end |
#n3?(tc) ⇒ 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
72 73 74 |
# File 'lib/qa/authorities/discogs/discogs_utils.rb', line 72 def ntriples?(tc) format(tc).casecmp?('ntriples') end |
#rdf_type_predicate ⇒ Object
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_predicate ⇒ Object
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 |