Class: RKD::Artist
- Inherits:
-
Object
- Object
- RKD::Artist
- Includes:
- Helpers::DateParsing
- Defined in:
- lib/r_k_d/artist.rb
Defined Under Namespace
Classes: NotFoundError
Instance Attribute Summary collapse
-
#birth_date ⇒ Date, RKD::ImpreciseDate
Will return date when known, otherwise imprecise date.
-
#birth_place ⇒ RKD::Place
readonly
The place where the artist was born.
- #birth_place_desc ⇒ Object readonly
-
#death_date ⇒ Date, RKD::ImpreciseDate
Will return date when known, otherwise imprecise date.
-
#death_place ⇒ RKD::Place
readonly
The place where the artist died.
- #death_place_desc ⇒ Object readonly
-
#gender ⇒ String
readonly
Currently just returns binary forms; ‘male’ | ‘female’.
-
#id ⇒ String
readonly
The full identifier of the artist; typically the uri.
-
#identifier ⇒ Integer
readonly
RKDid (basically the last part of the URI; which used to be the RKD Artist ID).
-
#name ⇒ String
readonly
The name of the artist.
-
#name_variants ⇒ Object
readonly
Returns the value of attribute name_variants.
-
#types ⇒ Array<RKD::Type>
readonly
The types associated with the artist.
-
#updated_at ⇒ DateTime
readonly
The timestamp when the artist information was last updated.
Class Method Summary collapse
-
.find(identifier) ⇒ RKD::Artist
Finds an artist by identifier.
-
.search(name) ⇒ Array<RKD::Artist>
Searches for artists by name.
Instance Method Summary collapse
- #enrich! ⇒ Object
-
#initialize(id: nil, name: nil, identifier: nil, gender: nil, birth_date: nil, death_date: nil, birth_place_desc: nil, death_place_desc: nil, name_variants: []) ⇒ Artist
constructor
A new instance of Artist.
- #performances ⇒ Object
- #public_url ⇒ Object
- #to_param ⇒ Object
- #to_partial_path ⇒ Object
- #update(**key_values) ⇒ Object
Constructor Details
#initialize(id: nil, name: nil, identifier: nil, gender: nil, birth_date: nil, death_date: nil, birth_place_desc: nil, death_place_desc: nil, name_variants: []) ⇒ Artist
Returns a new instance of Artist.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/r_k_d/artist.rb', line 82 def initialize(id: nil, name: nil, identifier: nil, gender: nil, birth_date: nil, death_date: nil, birth_place_desc: nil, death_place_desc: nil, name_variants: []) @id = id @name = name @identifier = identifier @gender = gender self.birth_date = birth_date self.death_date = death_date @birth_place_desc = birth_place_desc @death_place_desc = death_place_desc @name_variants = name_variants @performances = [] end |
Instance Attribute Details
#birth_date ⇒ Date, RKD::ImpreciseDate
Returns will return date when known, otherwise imprecise date.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#birth_place ⇒ RKD::Place (readonly)
Returns the place where the artist was born.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#birth_place_desc ⇒ Object
105 106 107 |
# File 'lib/r_k_d/artist.rb', line 105 def birth_place_desc @birth_place_desc || birth_place&.label end |
#death_date ⇒ Date, RKD::ImpreciseDate
Returns will return date when known, otherwise imprecise date.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#death_place ⇒ RKD::Place (readonly)
Returns the place where the artist died.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#death_place_desc ⇒ Object
98 99 100 |
# File 'lib/r_k_d/artist.rb', line 98 def death_place_desc @death_place_desc || death_place&.label end |
#gender ⇒ String
Returns currently just returns binary forms; ‘male’ | ‘female’.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#id ⇒ String
Returns the full identifier of the artist; typically the uri.
30 31 32 |
# File 'lib/r_k_d/artist.rb', line 30 def id @id end |
#identifier ⇒ Integer
Returns RKDid (basically the last part of the URI; which used to be the RKD Artist ID).
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#name ⇒ String
Returns the name of the artist.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#name_variants ⇒ Object (readonly)
Returns the value of attribute name_variants.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#types ⇒ Array<RKD::Type> (readonly)
Returns the types associated with the artist.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
#updated_at ⇒ DateTime (readonly)
Returns the timestamp when the artist information was last updated.
30 |
# File 'lib/r_k_d/artist.rb', line 30 attr_reader :id, :name, :identifier, :gender, :birth_date, :death_date, :types, :updated_at, :birth_place, :death_place, :name_variants |
Class Method Details
.find(identifier) ⇒ RKD::Artist
Finds an artist by identifier.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/r_k_d/artist.rb', line 50 def find(identifier) identifier = identifier.sub("https://data.rkd.nl/artists/", "") if identifier.is_a? String raise NotFoundError.new("No artist with id #{identifier}") if identifier.to_i == 0 identifier = identifier.to_i found_data = Query::ElasticSearch.find(identifier, dataset: "artists") raise NotFoundError.new("No artist found with id #{identifier}") if found_data.nil? artist = new_from_search_result(found_data) artist.enrich! artist end |
.search(name) ⇒ Array<RKD::Artist>
Searches for artists by name.
36 37 38 39 40 41 42 43 44 |
# File 'lib/r_k_d/artist.rb', line 36 def search(name) name = name.to_s.strip return [] if name.empty? Query::ElasticSearch.search(name, dataset: "artists").map do |artist| new_from_search_result(artist) end end |
Instance Method Details
#enrich! ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/r_k_d/artist.rb', line 163 def enrich! json = Query::Sparql.find(identifier) death_data = json.select { |a| a["property"] == "http://www.cidoc-crm.org/cidoc-crm/P100i_died_in" } birth_data = json.select { |a| a["property"] == "http://www.cidoc-crm.org/cidoc-crm/P98i_was_born" } # different placeRefs death_places_data = extract_places_data(death_data).first birth_places_data = extract_places_data(birth_data).first @death_place = Place.new(**death_places_data) if death_places_data self.death_date = [death_data.first["begin"], death_data.first["end"]].compact.max_by(&:length) if death_data.first @birth_place = Place.new(**birth_places_data) if birth_places_data self.birth_date = [birth_data.first["begin"], birth_data.first["end"]].compact.max_by(&:length) if birth_data.first @name = json.select { |row| row["property"] == "http://www.w3.org/2000/01/rdf-schema#label" }.map { |row| row["value"] }.first performances_data = json.select { |row| row["property"] == "http://www.cidoc-crm.org/cidoc-crm/P14i_performed" }.group_by { |row| row["value"] } @performances = performances_data.map do |perf_id, values| parse_performance_data(perf_id, values) end.compact type_data = json.select { |a| a["property"] == "http://www.cidoc-crm.org/cidoc-crm/P2_has_type" }.map { |row| {label: row["prefLabel"], ref: row["value"]} }.select { |a| a[:label] } @types = type_data.map { |type_datum| RKD::Type.new(**type_datum) } unlabeled_types = json.select { |a| a["property"] == "http://www.cidoc-crm.org/cidoc-crm/P2_has_type" }.map { |row| {label: row["prefLabel"], ref: row["value"]} }.select { |a| !a[:label] }.map { |row| row[:ref] } if unlabeled_types.delete("http://vocab.getty.edu/aat/300189559") @gender = "male" elsif unlabeled_types.delete("http://vocab.getty.edu/aat/300189557") @gender = "female" end type_data = json.select { |a| a["property"] == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }.map { |row| {label: row["value"].sub(/http:\/\/www\.cidoc-crm\.org\/cidoc-crm\/[A-E]\d+_/, "").sub("_", " "), ref: row["value"]} }.select { |a| a[:label] } @types += type_data.map { |type_datum| RKD::Type.new(**type_datum) } p unlabeled_types if unlabeled_types.any? @updated_at = begin DateTime.parse json.find { |a| a["property"] == "http://www.w3.org/ns/prov#generatedAtTime" }["value"] rescue Date::Error rescue NoMethodError if json == [] raise RKD::Artist::NotFoundError, "Nothing found for id #{identifier}" end end end |
#performances ⇒ Object
121 122 123 |
# File 'lib/r_k_d/artist.rb', line 121 def performances Performance::Collection.new(@performances) end |
#public_url ⇒ Object
128 129 130 |
# File 'lib/r_k_d/artist.rb', line 128 def public_url "https://research.rkd.nl/nl/detail/https%3A%2F%2Fdata.rkd.nl%2Fartists%2F#{identifier}" end |
#to_param ⇒ Object
156 157 158 |
# File 'lib/r_k_d/artist.rb', line 156 def to_param identifier end |
#to_partial_path ⇒ Object
149 150 151 |
# File 'lib/r_k_d/artist.rb', line 149 def to_partial_path "rkd/artists/artist" end |
#update(**key_values) ⇒ Object
112 113 114 115 116 |
# File 'lib/r_k_d/artist.rb', line 112 def update(**key_values) key_values.each do |key, value| send(:"#{key}=", value) end end |