qa 4.2.2 → 4.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 486f518740d8c668bdc6afee57d80ae3fa312438
4
- data.tar.gz: 43960d9fac51284870ac108c6184117f08afbbf0
3
+ metadata.gz: eba5e21a3c6692b86e9974f53a642c22fe4b15e6
4
+ data.tar.gz: 5d62930818fc514a4e685f5480a15592f5c7c1d3
5
5
  SHA512:
6
- metadata.gz: ef00b17700e1aa0e218706286ef517cbef97331ef7f6a6127917bd54d9cc66074e55de974a64eb98b3c42ba38927a10d435b53d4537bd98afffa207e917ae16a
7
- data.tar.gz: 7600248d02674fc92750496ea9a2cb82dd771d0a52d2a7f7ae3992dd663eb2fef577c368cd1e4d50c92bc514dcfb06029655ef9a8e8bb4305859d84c8683b4a0
6
+ metadata.gz: c24bd0c98bb86cca3dbeb5d0889f017af4c97911bbaab33e2a413562f9ce954d6128042b3dd09647483990517d90ec0f6ac493a0fcae3277b215cc75613e4e21
7
+ data.tar.gz: c81ee4a69c029942069d39a4b0cb5e3cb3b199abf65b94a7a57e29e5bf3eb9f999e67584a65b6b26d5ebed3790550e2870a7bce38087bd5409f13c2cb5f3abce
@@ -222,9 +222,14 @@ class Qa::LinkedDataTermsController < ::ApplicationController
222
222
  format.casecmp?('n3')
223
223
  end
224
224
 
225
+ def ntriples?
226
+ format.casecmp?('ntriples')
227
+ end
228
+
225
229
  def content_type_for_format
226
230
  return 'application/ld+json' if jsonld?
227
231
  return 'text/n3' if n3?
232
+ return 'application/n-triples' if ntriples?
228
233
  'application/json'
229
234
  end
230
235
 
@@ -95,9 +95,14 @@ class Qa::TermsController < ::ApplicationController
95
95
  format.casecmp?('n3')
96
96
  end
97
97
 
98
+ def ntriples?
99
+ format.casecmp?('ntriples')
100
+ end
101
+
98
102
  def content_type_for_format
99
103
  return 'application/ld+json' if jsonld?
100
104
  return 'text/n3' if n3?
105
+ return 'application/n-triples' if ntriples?
101
106
  'application/json'
102
107
  end
103
108
  end
@@ -44,11 +44,12 @@ module Qa::Authorities
44
44
  count = 1
45
45
  return stmts unless response["identifiers"].present?
46
46
  response["identifiers"].each do |activity|
47
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/identifiedBy", "Identifier#{count}")
48
- stmts << contruct_stmt_uri_object("Identifier#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier")
49
- stmts << contruct_stmt_literal_object("Identifier#{count}", rdfs_label_predicate, activity["value"])
47
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/identifiedBy", "iidn#{count}")
48
+ stmts << contruct_stmt_uri_object("iidn#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier")
49
+ stmts << contruct_stmt_literal_object("iidn#{count}", rdfs_label_predicate, activity["value"])
50
50
  count += 1
51
51
  end
52
+ stmts.concat(build_year_statements(response)) if response["released"].present?
52
53
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
53
54
  end
54
55
 
@@ -64,7 +65,7 @@ module Qa::Authorities
64
65
  if df.present?
65
66
  stmts += build_format_characteristics(df, count)
66
67
  else
67
- stmts << contruct_stmt_literal_object("Instance1", "http://id.loc.gov/ontologies/bibframe/editionStatement", desc)
68
+ stmts << contruct_stmt_literal_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/editionStatement", desc)
68
69
  end
69
70
  end
70
71
  stmts
@@ -77,15 +78,13 @@ module Qa::Authorities
77
78
  stmts = []
78
79
  case df["type"]
79
80
  when "playbackChannel"
80
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", df["uri"])
81
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", df["uri"])
81
82
  stmts << contruct_stmt_uri_object(df["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlaybackChannel")
82
83
  stmts << contruct_stmt_literal_object(df["uri"], rdfs_label_predicate, df["label"])
83
84
  when "dimension"
84
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/dimensions", df["label"])
85
+ stmts << contruct_stmt_literal_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/dimensions", df["label"])
85
86
  when "playingSpeed"
86
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", "PlayingSpeed#{count}")
87
- stmts << contruct_stmt_uri_object("PlayingSpeed#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlayingSpeed")
88
- stmts << contruct_stmt_literal_object("PlayingSpeed#{count}", rdfs_label_predicate, df["label"])
87
+ stmts.concat(build_playing_speed_stmts(df["label"], count))
89
88
  end
90
89
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
91
90
  end
@@ -98,13 +97,13 @@ module Qa::Authorities
98
97
  return stmts unless name.present?
99
98
  dc = discogs_formats[name.gsub(/\s+/, "")]
100
99
  if dc.present?
101
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/carrier", dc["uri"])
100
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/carrier", dc["uri"])
102
101
  stmts << contruct_stmt_uri_object(dc["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Carrier")
103
102
  stmts << contruct_stmt_literal_object(dc["uri"], rdfs_label_predicate, dc["label"])
104
103
  stmts.concat(build_base_materials(name))
105
104
  else
106
105
  # if it's not a carrier, it's an edition statement
107
- stmts << contruct_stmt_literal_object("Instance1", "http://id.loc.gov/ontologies/bibframe/editionStatement", name)
106
+ stmts << contruct_stmt_literal_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/editionStatement", name)
108
107
  end
109
108
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
110
109
  end
@@ -116,7 +115,7 @@ module Qa::Authorities
116
115
  return stmts unless name == "Vinyl" || name == "Shellac"
117
116
  id = name == "Vinyl" ? "300014502" : "300014918"
118
117
 
119
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/baseMaterial", "http://vocab.getty.edu/aat/" + id)
118
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/baseMaterial", "http://vocab.getty.edu/aat/" + id)
120
119
  stmts << contruct_stmt_uri_object("http://vocab.getty.edu/aat/" + id, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/BaseMaterial")
121
120
  stmts << contruct_stmt_literal_object("http://vocab.getty.edu/aat/" + id, rdfs_label_predicate, name)
122
121
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
@@ -129,13 +128,12 @@ module Qa::Authorities
129
128
  # need to distinguish among different provision activities and roles
130
129
  count = 1
131
130
  activities.each do |activity|
132
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/provisionActivity", "ProvisionActivity#{count}")
133
- stmts << contruct_stmt_uri_object("ProvisionActivity#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity")
134
- stmts << contruct_stmt_uri_object("ProvisionActivity#{count}", bf_agent_predicate, activity["name"])
135
- stmts << contruct_stmt_uri_object(activity["name"], rdf_type_predicate, bf_agent_type_object)
136
- stmts << contruct_stmt_uri_object(activity["name"], bf_role_predicate, "PA_Role#{count}")
137
- stmts << contruct_stmt_uri_object("PA_Role#{count}", rdf_type_predicate, bf_role_type_object)
138
- stmts << contruct_stmt_literal_object("PA_Role#{count}", rdfs_label_predicate, activity["entity_type_name"])
131
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "proact#{count}")
132
+ stmts << contruct_stmt_uri_object("proact#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity")
133
+ stmts << contruct_stmt_uri_object("proact#{count}", bf_agent_predicate, "agentn3#{count}")
134
+ stmts << contruct_stmt_uri_object("agentn3#{count}", rdf_type_predicate, bf_agent_type_object)
135
+ stmts << contruct_stmt_literal_object("agentn3#{count}", rdfs_label_predicate, activity["name"])
136
+ stmts += build_role_stmts("agentn3#{count}", "role3#{count}", activity["entity_type_name"])
139
137
  count += 1
140
138
  end
141
139
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
@@ -11,7 +11,7 @@ module Qa::Authorities
11
11
  # to the URIs of corresponding objects in the Library of Congress vocabulary.
12
12
  # @param [Hash] the http response from discogs
13
13
  # @param [String] the subauthority
14
- # @return [Array, String] requested RDF serialzation (supports: jsonld Array, n3 String)
14
+ # @return [Array, String] requested RDF serialzation (supports: jsonld Array, n3 String, n-triples String)
15
15
  def build_graph(response, subauthority = "", format: :jsonld)
16
16
  graph = RDF::Graph.new
17
17
 
@@ -30,14 +30,17 @@ module Qa::Authorities
30
30
  # all we need is a work and not an instance. If there's no subauthority, we can determine
31
31
  # if the discogs record is a master because it will have a main_release field.
32
32
  if master_only(response, subauthority)
33
+ self.work_uri = response["uri"]
33
34
  complete_rdf_stmts.concat(build_master_statements(response))
34
35
  else
35
36
  # If the subauthority is not "master," we need to define an instance as well as a
36
37
  # work. If the discogs record has a master_id, fetch that and use the results to
37
38
  # build the statements for the work.
38
39
  master_resp = response["master_id"].present? ? json("https://api.discogs.com/masters/#{response['master_id']}") : response
40
+ self.work_uri = master_resp["uri"] if master_resp["uri"].present? && master_resp["uri"].include?("master")
39
41
  complete_rdf_stmts.concat(build_master_statements(master_resp))
40
42
  # Now do the statements for the instance.
43
+ self.instance_uri = response["uri"] if response["uri"].present?
41
44
  complete_rdf_stmts.concat(build_instance_statements(response))
42
45
  end
43
46
  end
@@ -77,11 +80,12 @@ module Qa::Authorities
77
80
  # @return [Array] rdf statements
78
81
  def get_primary_work_definition(response)
79
82
  stmts = []
80
- stmts << contruct_stmt_uri_object("Work1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work")
81
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/title", "Work1Title")
82
- stmts << contruct_stmt_literal_object("Work1Title", bf_main_title_predicate, response["title"])
83
- stmts << contruct_stmt_uri_object("Work1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio")
84
- stmts.concat(build_year_statements(response, "Work"))
83
+ stmts << contruct_stmt_uri_object(work_uri, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work")
84
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/title", "titlen1")
85
+ stmts << contruct_stmt_literal_object("titlen1", bf_main_title_predicate, response["title"])
86
+ stmts << contruct_stmt_uri_object("titlen1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title")
87
+ stmts << contruct_stmt_uri_object(work_uri, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio")
88
+ stmts << contruct_stmt_literal_object(work_uri, "http://id.loc.gov/ontologies/bibframe/originDate", response["year"].to_s) if response["year"].present?
85
89
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
86
90
  end
87
91
 
@@ -89,14 +93,14 @@ module Qa::Authorities
89
93
  # @return [Array] rdf statements
90
94
  def get_primary_instance_definition(response)
91
95
  stmts = []
92
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/hasInstance", "Instance1")
93
- stmts << contruct_stmt_uri_object("Instance1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Instance")
94
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/title", "Instance1Title")
95
- stmts << contruct_stmt_literal_object("Instance1Title", bf_main_title_predicate, response["title"])
96
- stmts << contruct_stmt_uri_object("Instance1", "http://id.loc.gov/ontologies/bibframe/identifiedBy", "IdentifierPrimary")
97
- stmts << contruct_stmt_uri_object("IdentifierPrimary", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier")
98
- stmts << contruct_stmt_literal_object("IdentifierPrimary", "http://www.w3.org/1999/02/22-rdf-syntax-ns#value", response["id"])
99
- stmts.concat(build_year_statements(response, "Instance"))
96
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/hasInstance", instance_uri)
97
+ stmts << contruct_stmt_uri_object(instance_uri, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Instance")
98
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/title", "titlen2")
99
+ stmts << contruct_stmt_literal_object("titlen2", bf_main_title_predicate, response["title"])
100
+ stmts << contruct_stmt_uri_object("titlen2", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title")
101
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/identifiedBy", "widn1")
102
+ stmts << contruct_stmt_uri_object("widn1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Identifier")
103
+ stmts << contruct_stmt_literal_object("widn1", "http://www.w3.org/1999/02/22-rdf-syntax-ns#value", response["id"])
100
104
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
101
105
  end
102
106
 
@@ -112,10 +116,11 @@ module Qa::Authorities
112
116
  # we need the primary artists later when we loop through the track list, so build this array
113
117
  primary_artists << artist
114
118
 
115
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/contribution", "Work1PrimaryContribution#{count}")
116
- stmts << contruct_stmt_uri_object("Work1PrimaryContribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution")
117
- stmts << contruct_stmt_uri_object("Work1PrimaryContribution#{count}", bf_agent_predicate, artist["name"])
118
- stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object)
119
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn#{count}")
120
+ stmts << contruct_stmt_uri_object("contrbn#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution")
121
+ stmts << contruct_stmt_uri_object("contrbn#{count}", bf_agent_predicate, "agentn#{count}")
122
+ stmts << contruct_stmt_uri_object("agentn#{count}", rdf_type_predicate, bf_agent_type_object)
123
+ stmts << contruct_stmt_literal_object("agentn#{count}", rdfs_label_predicate, artist["name"])
119
124
  count += 1
120
125
  end
121
126
  end
@@ -9,9 +9,11 @@ module Qa::Authorities
9
9
  # @param [String] either a string used to create a unique URI or an LOC uri in string format
10
10
  # @param [String] or [Class] either a BIBFRAME property uri in string format or an RDF::URI
11
11
  # @param [String] or [Class] strings can be a label or BIBFRAME class uri; class is always RDF::URI
12
- # @return [Class] RDF::Statement with uri as the object
12
+ # @return [Class] RDF::Statement with either a uri or a bnode as the object
13
13
  def contruct_stmt_uri_object(subject, predicate, object)
14
- RDF::Statement(RDF::URI.new(subject), RDF::URI(predicate), RDF::URI.new(object))
14
+ s = subject.include?("http") ? RDF::URI.new(subject) : subject.to_sym
15
+ o = object.to_s.include?("http") ? RDF::URI.new(object) : object.to_sym
16
+ RDF::Statement(s, RDF::URI(predicate), o)
15
17
  end
16
18
 
17
19
  # Constructs an RDF statement where the subject and predicate are URIs and the object is a literal
@@ -20,7 +22,8 @@ module Qa::Authorities
20
22
  # @param [String] or [Class] strings can be a label or BIBFRAME class uri; class is always RDF::URI
21
23
  # @return [Class] RDF::Statement with a literal as the object
22
24
  def contruct_stmt_literal_object(subject, predicate, object)
23
- RDF::Statement(RDF::URI.new(subject), RDF::URI(predicate), RDF::Literal.new(object))
25
+ s = subject.include?("http") ? RDF::URI.new(subject) : subject.to_sym
26
+ RDF::Statement(s, RDF::URI(predicate), RDF::Literal.new(object))
24
27
  end
25
28
 
26
29
  # frequently used predicates and objects
@@ -41,7 +44,7 @@ module Qa::Authorities
41
44
  end
42
45
 
43
46
  def bf_agent_type_object
44
- RDF::URI("http://id.loc.gov/ontologies/bibframe/Agent")
47
+ "http://id.loc.gov/ontologies/bibframe/Agent"
45
48
  end
46
49
 
47
50
  def bf_role_predicate
@@ -49,7 +52,7 @@ module Qa::Authorities
49
52
  end
50
53
 
51
54
  def bf_role_type_object
52
- RDF::URI("http://id.loc.gov/ontologies/bibframe/Role")
55
+ "http://id.loc.gov/ontologies/bibframe/Role"
53
56
  end
54
57
 
55
58
  def discogs_genres
@@ -62,27 +65,36 @@ module Qa::Authorities
62
65
 
63
66
  # both the work and the instance require a statement for the release year
64
67
  # @param [Hash] the http response from discogs
65
- # @param [String] either "Work" or "Instance"
66
68
  # @return [Array] rdf statements
67
- def build_year_statements(response, type)
69
+ def build_year_statements(response)
68
70
  year_stmts = []
69
- if type == "Work" && response["year"].present?
70
- year_stmts = get_year_rdf(type + "1", response["year"])
71
- elsif response["released"].present?
72
- year_stmts = get_year_rdf(type + "1", response["released"])
73
- end
71
+ year_stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "daten1")
72
+ year_stmts << contruct_stmt_uri_object("daten1", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Publication")
73
+ year_stmts << contruct_stmt_literal_object("daten1", RDF::URI("http://id.loc.gov/ontologies/bibframe/date"), response["released"].to_s)
74
74
  year_stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
75
75
  end
76
76
 
77
- # @param [String] either "Work1" or "Instance1"
78
- # @param [String] 4-digit year in string format
77
+ # @param [Hash] the extraartists defined at the release level, not the track level
78
+ # @param [Integer] gives the role a unique uri
79
+ # @param [String] the entity type name
79
80
  # @return [Array] rdf statements
80
- def get_year_rdf(type, year)
81
- year_stmts = []
82
- year_stmts << contruct_stmt_uri_object(type, "http://id.loc.gov/ontologies/bibframe/provisionActivity", "#{type}ProvisionActivityDate")
83
- year_stmts << contruct_stmt_uri_object("#{type}ProvisionActivityDate", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/ProvisionActivity")
84
- # Full RDF statement syntax as this one requires a datatype
85
- 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))
81
+ def build_role_stmts(subject_node, role_node, label)
82
+ stmts = []
83
+ stmts << contruct_stmt_uri_object(subject_node, bf_role_predicate, role_node)
84
+ stmts << contruct_stmt_uri_object(role_node, rdf_type_predicate, bf_role_type_object)
85
+ stmts << contruct_stmt_literal_object(role_node, rdfs_label_predicate, label)
86
+ stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
87
+ end
88
+
89
+ # @param [String] the playing speed in string format
90
+ # @param [Integer] gives the playing speed a unique uri
91
+ # @return [Array] rdf statements
92
+ def build_playing_speed_stmts(label, count)
93
+ stmts = []
94
+ stmts << contruct_stmt_uri_object(instance_uri, "http://id.loc.gov/ontologies/bibframe/soundCharacteristic", "speed#{count}")
95
+ stmts << contruct_stmt_uri_object("speed#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/PlayingSpeed")
96
+ stmts << contruct_stmt_literal_object("speed#{count}", rdfs_label_predicate, label)
97
+ stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
86
98
  end
87
99
  end
88
100
  end
@@ -1,7 +1,7 @@
1
1
  require 'rdf'
2
2
  module Qa::Authorities
3
3
  module Discogs
4
- module DiscogsWorksBuilder # rubocop:disable Metrics/ModuleLength
4
+ module DiscogsWorksBuilder
5
5
  include Discogs::DiscogsUtils
6
6
 
7
7
  # @param [Hash] the http response from discogs
@@ -12,27 +12,17 @@ module Qa::Authorities
12
12
  count = 1
13
13
  return stmts unless response["extraartists"].present?
14
14
  response["extraartists"].each do |artist|
15
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/contribution", "Work1SecondaryContribution#{count}")
16
- stmts << contruct_stmt_uri_object("Work1SecondaryContribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
17
- stmts << contruct_stmt_uri_object("Work1SecondaryContribution#{count}", bf_agent_predicate, artist["name"])
18
- stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object)
19
- stmts += build_artist_role_stmts(artist, count)
15
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn1#{count}")
16
+ stmts << contruct_stmt_uri_object("contrbn1#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
17
+ stmts << contruct_stmt_uri_object("contrbn1#{count}", bf_agent_predicate, "agentn1#{count}")
18
+ stmts << contruct_stmt_uri_object("agentn1#{count}", rdf_type_predicate, bf_agent_type_object)
19
+ stmts << contruct_stmt_literal_object("agentn1#{count}", rdfs_label_predicate, artist["name"])
20
+ stmts += build_role_stmts("agentn1#{count}", "rolen1#{count}", artist["role"])
20
21
  count += 1
21
22
  end
22
23
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
23
24
  end
24
25
 
25
- # @param [Hash] the extraartists defined at the release level, not the track level
26
- # @param [Integer] gives the role a unique uri
27
- # @return [Array] rdf statements
28
- def build_artist_role_stmts(artist, count)
29
- stmts = []
30
- stmts << contruct_stmt_uri_object(artist["name"], bf_role_predicate, "Work1SecondaryContributor_Role#{count}")
31
- stmts << contruct_stmt_uri_object("Work1SecondaryContributor_Role#{count}", rdf_type_predicate, bf_role_type_object)
32
- stmts << contruct_stmt_literal_object("Work1SecondaryContributor_Role#{count}", rdfs_label_predicate, artist["role"])
33
- stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
34
- end
35
-
36
26
  # @param [Hash] the http response from discogs
37
27
  # @return [Array] rdf statements
38
28
  def get_genres_stmts(response)
@@ -54,24 +44,13 @@ module Qa::Authorities
54
44
  stmts = []
55
45
  dg = discogs_genres[genre.gsub(/\s+/, "")]
56
46
  if dg.present?
57
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/genreForm", dg["uri"])
47
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/genreForm", dg["uri"])
58
48
  stmts << contruct_stmt_uri_object(dg["uri"], rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/GenreForm")
59
49
  stmts << contruct_stmt_literal_object(dg["uri"], rdfs_label_predicate, dg["label"])
60
50
  end
61
51
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
62
52
  end
63
53
 
64
- # @param [String] the uri of the genreForm
65
- # @param [String] the genreForm label
66
- # @return [Array] rdf statements
67
- def build_genres_and_styles(uri, dg_label)
68
- stmts = []
69
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/genreForm", uri)
70
- stmts << contruct_stmt_uri_object(uri, rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/GenreForm")
71
- stmts << contruct_stmt_literal_object(uri, rdfs_label_predicate, dg_label)
72
- stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
73
- end
74
-
75
54
  # @param [Hash] the http response from discogs
76
55
  # @return [Array] rdf statements
77
56
  def get_tracklist_artists_stmts(response)
@@ -103,13 +82,13 @@ module Qa::Authorities
103
82
  # @return [Array] rdf statements
104
83
  def build_secondary_works(track, w_count)
105
84
  stmts = []
106
- stmts << contruct_stmt_uri_object("Work1", "http://id.loc.gov/ontologies/bibframe/hasPart", "Work#{w_count}")
107
- stmts << contruct_stmt_uri_object("Work#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work")
108
- stmts << contruct_stmt_uri_object("Work#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio")
109
- stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/title", "Work#{w_count}Title")
110
- stmts << contruct_stmt_uri_object("Work#{w_count}Title", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title")
111
- stmts << contruct_stmt_literal_object("Work#{w_count}Title", bf_main_title_predicate, track["title"])
112
- stmts << contruct_stmt_literal_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/duration", track["duration"]) if track["duration"].present?
85
+ stmts << contruct_stmt_uri_object(work_uri, "http://id.loc.gov/ontologies/bibframe/hasPart", "workn#{w_count}")
86
+ stmts << contruct_stmt_uri_object("workn#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Work")
87
+ stmts << contruct_stmt_uri_object("workn#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Audio")
88
+ stmts << contruct_stmt_uri_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/title", "titlen3#{w_count}")
89
+ stmts << contruct_stmt_uri_object("titlen3#{w_count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Title")
90
+ stmts << contruct_stmt_literal_object("titlen3#{w_count}", bf_main_title_predicate, track["title"])
91
+ stmts << contruct_stmt_literal_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/duration", track["duration"]) if track["duration"].present?
113
92
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
114
93
  end
115
94
 
@@ -120,10 +99,11 @@ module Qa::Authorities
120
99
  stmts = []
121
100
  count = 1
122
101
  artists.each do |artist|
123
- stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "Work#{w_count}PrimaryContribution#{count}")
124
- stmts << contruct_stmt_uri_object("Work#{w_count}PrimaryContribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution")
125
- stmts << contruct_stmt_uri_object("Work#{w_count}PrimaryContribution#{count}", bf_agent_predicate, artist["name"])
126
- stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object)
102
+ stmts << contruct_stmt_uri_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn#{w_count}#{count}")
103
+ stmts << contruct_stmt_uri_object("contrbn#{w_count}#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bflc/PrimaryContribution")
104
+ stmts << contruct_stmt_uri_object("contrbn#{w_count}#{count}", bf_agent_predicate, "agentn#{w_count}#{count}")
105
+ stmts << contruct_stmt_uri_object("agentn#{w_count}#{count}", rdf_type_predicate, bf_agent_type_object)
106
+ stmts << contruct_stmt_literal_object("agentn#{w_count}#{count}", rdfs_label_predicate, artist["name"])
127
107
  count += 1
128
108
  end
129
109
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
@@ -137,13 +117,12 @@ module Qa::Authorities
137
117
  # to distinguish among contributors to a track/work and their roles
138
118
  count = 1
139
119
  extraartists.each do |artist|
140
- stmts << contruct_stmt_uri_object("Work#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "Work#{w_count}Contribution#{count}")
141
- stmts << contruct_stmt_uri_object("Work#{w_count}Contribution#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
142
- stmts << contruct_stmt_uri_object("Work#{w_count}Contribution#{count}", bf_agent_predicate, artist["name"])
143
- stmts << contruct_stmt_uri_object(artist["name"], rdf_type_predicate, bf_agent_type_object)
144
- stmts << contruct_stmt_uri_object(artist["name"], bf_role_predicate, "Work#{w_count}ContributorRole#{count}")
145
- stmts << contruct_stmt_uri_object("Work#{w_count}ContributorRole#{count}", rdf_type_predicate, bf_role_type_object)
146
- stmts << contruct_stmt_literal_object("Work#{w_count}ContributorRole#{count}", rdfs_label_predicate, artist["role"])
120
+ stmts << contruct_stmt_uri_object("workn#{w_count}", "http://id.loc.gov/ontologies/bibframe/contribution", "contrbn#{w_count}2#{count}")
121
+ stmts << contruct_stmt_uri_object("contrbn#{w_count}2#{count}", rdf_type_predicate, "http://id.loc.gov/ontologies/bibframe/Contribution")
122
+ stmts << contruct_stmt_uri_object("contrbn#{w_count}2#{count}", bf_agent_predicate, "agentn#{w_count}2#{count}")
123
+ stmts << contruct_stmt_uri_object("agentn#{w_count}2#{count}", rdf_type_predicate, bf_agent_type_object)
124
+ stmts << contruct_stmt_literal_object("agentn#{w_count}2#{count}", rdfs_label_predicate, artist["name"])
125
+ stmts += build_role_stmts("agentn#{w_count}2#{count}", "role2#{w_count}#{count}", artist["role"])
147
126
  count += 1
148
127
  end
149
128
  stmts # w/out this line, building the graph throws an undefined method `graph_name=' error
@@ -1,16 +1,19 @@
1
1
  require 'rdf'
2
+ require 'rdf/ntriples'
2
3
  module Qa::Authorities
3
4
  class Discogs::GenericAuthority < Base
4
5
  include WebServiceBase
5
6
  include Discogs::DiscogsTranslation
6
7
 
7
8
  class_attribute :discogs_secret, :discogs_key
8
- attr_accessor :primary_artists
9
+ attr_accessor :primary_artists, :selected_format, :work_uri, :instance_uri
9
10
 
10
11
  # @param [String] subauthority to use
11
12
  def initialize(subauthority)
12
13
  @subauthority = subauthority
13
14
  self.primary_artists = []
15
+ self.work_uri = "http://generic.uri/workn1"
16
+ self.instance_uri = "http://generic.uri/instn1"
14
17
  end
15
18
 
16
19
  # @param [String] the query
@@ -35,12 +38,14 @@ module Qa::Authorities
35
38
  #
36
39
  # @param [String] the Discogs id of the selected item
37
40
  # @param [Class] QA::TermsController
38
- # @return results in requested format (supports: json, jsonld, n3)
41
+ # @return results in requested format (supports: json, jsonld, n3, ntriples)
39
42
  def find(id, tc)
40
43
  response = tc.params["subauthority"].include?("all") ? fetch_discogs_results(id) : json(find_url(id, tc.params["subauthority"]))
44
+ self.selected_format = tc.params["format"]
41
45
  return response if response["message"].present?
42
46
  return build_graph(response, format: :jsonld) if jsonld?(tc)
43
47
  return build_graph(response, format: :n3) if n3?(tc)
48
+ return build_graph(response, format: :ntriples) if ntriples?(tc)
44
49
  response
45
50
  end
46
51
 
@@ -164,8 +169,12 @@ module Qa::Authorities
164
169
  format(tc).casecmp?('n3')
165
170
  end
166
171
 
172
+ def ntriples?(tc)
173
+ format(tc).casecmp?('ntriples')
174
+ end
175
+
167
176
  def graph_format?(tc)
168
- jsonld?(tc) || n3?(tc)
177
+ jsonld?(tc) || n3?(tc) || ntriples?(tc)
169
178
  end
170
179
  end
171
180
  end
@@ -74,10 +74,10 @@ module Qa::Authorities
74
74
 
75
75
  def normalize_results
76
76
  normalize_start_dt = Time.now.utc
77
- normalize_end_dt = Time.now.utc
78
77
 
79
78
  json = perform_normalization
80
79
 
80
+ normalize_end_dt = Time.now.utc
81
81
  @normalize_time_s = normalize_end_dt - normalize_start_dt
82
82
  @normalized_size = json.to_s.size if performance_data?
83
83
  Rails.logger.info("Time to convert data to json: #{normalize_time_s}s")
@@ -89,6 +89,7 @@ module Qa::Authorities
89
89
  return "{}" unless full_graph.size.positive?
90
90
  return full_graph.dump(:jsonld, standard_prefixes: true) if jsonld?
91
91
  return full_graph.dump(:n3, standard_prefixes: true) if n3?
92
+ return full_graph.dump(:ntriples, standard_prefixes: true) if ntriples?
92
93
 
93
94
  filter_graph
94
95
  extract_uri
@@ -201,6 +202,10 @@ module Qa::Authorities
201
202
  @format && @format.casecmp?('n3')
202
203
  end
203
204
 
205
+ def ntriples?
206
+ @format && @format.casecmp?('ntriples')
207
+ end
208
+
204
209
  def performance_data?
205
210
  @performance_data == true && !jsonld?
206
211
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "4.2.2".freeze
2
+ VERSION = "4.2.3".freeze
3
3
  end
@@ -434,6 +434,15 @@ describe Qa::LinkedDataTermsController, type: :controller do
434
434
  expect(response.body).to start_with "@prefix"
435
435
  end
436
436
  end
437
+
438
+ context 'and it was requested as ntriples' do
439
+ it 'succeeds and returns term data as ntriples content type' do
440
+ get :show, params: { id: '530369', vocab: 'OCLC_FAST', format: 'ntriples' }
441
+ expect(response).to be_successful
442
+ expect(response.content_type).to eq 'application/n-triples'
443
+ expect(response.body).to include('<http://id.worldcat.org/fast/530369> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University"')
444
+ end
445
+ end
437
446
  end
438
447
 
439
448
  context 'when cors headers are enabled' do
@@ -605,6 +614,15 @@ describe Qa::LinkedDataTermsController, type: :controller do
605
614
  end
606
615
  end
607
616
 
617
+ context 'and it was requested as ntriples' do
618
+ it 'succeeds and returns term data as ntriples content type' do
619
+ get :fetch, params: { uri: 'http://id.worldcat.org/fast/530369', vocab: 'LOD_TERM_URI_PARAM_CONFIG', format: 'ntriples' }
620
+ expect(response).to be_successful
621
+ expect(response.content_type).to eq 'application/n-triples'
622
+ expect(response.body).to include('<http://id.worldcat.org/fast/530369> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University"')
623
+ end
624
+ end
625
+
608
626
  context 'blank nodes not included in predicates list' do
609
627
  before do
610
628
  stub_request(:get, 'http://localhost/test_default/term?uri=http://id.worldcat.org/fast/530369wbn')
@@ -240,5 +240,17 @@ describe Qa::TermsController, type: :controller do
240
240
  expect(response.body).to start_with "@prefix"
241
241
  end
242
242
  end
243
+ context "with request for ntriples" do
244
+ before do
245
+ stub_request(:get, "https://api.discogs.com/releases/3380671")
246
+ .to_return(status: 200, body: webmock_fixture("discogs-find-response-json.json"))
247
+ end
248
+ it 'Access-Control-Allow-Origin is not present' do
249
+ get :show, params: { vocab: "discogs", subauthority: "release", id: "3380671", format: 'ntriples' }
250
+ expect(response).to be_successful
251
+ expect(response.content_type).to eq 'application/n-triples'
252
+ expect(response.body).to include('_:agentn1 <http://www.w3.org/2000/01/rdf-schema#label> "Dexter Gordon"')
253
+ end
254
+ end
243
255
  end
244
256
  end
@@ -158,6 +158,28 @@ describe Qa::Authorities::Discogs::GenericAuthority do
158
158
  end
159
159
  end
160
160
 
161
+ context "ntriples format and subauthority master" do
162
+ let(:tc) { instance_double(Qa::TermsController) }
163
+ let :results do
164
+ authority.find("950011", tc)
165
+ end
166
+ before do
167
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
168
+ allow(tc).to receive(:params).and_return('format' => "ntriples", 'subauthority' => "master")
169
+ end
170
+
171
+ it "returns the Discogs data converted to ntriples for a given id" do
172
+ expect(results).to include("https://www.discogs.com/Billie-Holiday-And-Her-Orchestra-Blue-Moon-You-Go-To-My-Head/master/950011")
173
+ expect(results).to include("Blue Moon / You Go To My Head")
174
+ expect(results).to include("Billie Holiday And Her Orchestra")
175
+ expect(results).to include("Haven Gillespie")
176
+ expect(results).to include("1952")
177
+ expect(results).to include("Jazz")
178
+ expect(results).to include("Barney Kessel")
179
+ expect(results).to include("Guitar")
180
+ end
181
+ end
182
+
161
183
  context "json-ld format and subauthority all" do
162
184
  let(:tc) { instance_double(Qa::TermsController) }
163
185
  let :results do
@@ -208,6 +230,31 @@ describe Qa::Authorities::Discogs::GenericAuthority do
208
230
  expect(results).to include("1952")
209
231
  end
210
232
  end
233
+
234
+ context "ntriples format and subauthority all" do
235
+ let(:tc) { instance_double(Qa::TermsController) }
236
+ let :results do
237
+ authority.find("7143179", tc)
238
+ end
239
+ before do
240
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
241
+ allow(tc).to receive(:params).and_return('format' => "ntriples", 'subauthority' => "all")
242
+ end
243
+
244
+ it "returns the Discogs data converted to ntriples for a given id" do
245
+ expect(results).to include("https://www.discogs.com/Billie-Holiday-And-Her-Orchestra-Blue-Moon-You-Go-To-My-Head/release/7143179")
246
+ expect(results).to include("You Go To My Head")
247
+ expect(results).to include("Rodgers & Hart")
248
+ expect(results).to include("Ray Brown")
249
+ expect(results).to include("1952")
250
+ expect(results).to include("Single")
251
+ expect(results).to include("mono")
252
+ expect(results).to include("45 RPM")
253
+ expect(results).to include("Vinyl")
254
+ expect(results).to include("http://id.loc.gov/vocabulary/carriers/sd")
255
+ expect(results).to include("1952")
256
+ end
257
+ end
211
258
  end
212
259
  end
213
260
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 4.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Anderson
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2019-08-14 00:00:00.000000000 Z
19
+ date: 2019-10-10 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import