Class: RKD::Artist

Inherits:
Object
  • Object
show all
Includes:
Helpers::DateParsing
Defined in:
lib/r_k_d/artist.rb

Defined Under Namespace

Classes: NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_dateDate, RKD::ImpreciseDate

Returns will return date when known, otherwise imprecise date.

Returns:



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_placeRKD::Place (readonly)

Returns the place where the artist was born.

Returns:

  • (RKD::Place)

    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_descObject



105
106
107
# File 'lib/r_k_d/artist.rb', line 105

def birth_place_desc
  @birth_place_desc || birth_place&.label
end

#death_dateDate, RKD::ImpreciseDate

Returns will return date when known, otherwise imprecise date.

Returns:



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_placeRKD::Place (readonly)

Returns the place where the artist died.

Returns:

  • (RKD::Place)

    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_descObject



98
99
100
# File 'lib/r_k_d/artist.rb', line 98

def death_place_desc
  @death_place_desc || death_place&.label
end

#genderString

Returns currently just returns binary forms; ‘male’ | ‘female’.

Returns:

  • (String)

    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

#idString

Returns the full identifier of the artist; typically the uri.

Returns:

  • (String)

    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

#identifierInteger

Returns RKDid (basically the last part of the URI; which used to be the RKD Artist ID).

Returns:

  • (Integer)

    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

#nameString

Returns the name of the artist.

Returns:

  • (String)

    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_variantsObject (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

#typesArray<RKD::Type> (readonly)

Returns the types associated with the artist.

Returns:

  • (Array<RKD::Type>)

    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_atDateTime (readonly)

Returns the timestamp when the artist information was last updated.

Returns:

  • (DateTime)

    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.

Parameters:

  • identifier (Integer, String)

    the identifier of the artist to find. It will accept both artist’s RKD URI as well as RKD Artist’s numeric identifiers.

Returns:

  • (RKD::Artist)

    the artist object corresponding to the given identifier.

Raises:

  • (NotFoundError)

    if no artist is found with the given 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.

Parameters:

  • name (String)

    the name of the artist to search for.

Returns:

  • (Array<RKD::Artist>)

    an array of artist objects matching the search criteria.



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

#performancesObject



121
122
123
# File 'lib/r_k_d/artist.rb', line 121

def performances
  Performance::Collection.new(@performances)
end

#public_urlObject



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_paramObject



156
157
158
# File 'lib/r_k_d/artist.rb', line 156

def to_param
  identifier
end

#to_partial_pathObject



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