-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassign_placenames.rb
54 lines (45 loc) · 1.41 KB
/
assign_placenames.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
module Robots
module DorRepo
module GisAssembly
class AssignPlacenames < Base
def initialize
super('gisAssemblyWF', 'assign-placenames')
end
def perform_work
logger.debug "assign-placenames working on #{bare_druid}"
resolve_placenames
object_client.update(params: cocina_object.new(description: description_props))
end
private
def description_props
@description_props ||= cocina_object.description.to_h
end
def gazetteer
@gazetteer ||= GisRobotSuite::Gazetteer.new
end
def resolve_placenames
place_subjects.each do |subject|
value = subject[:value]
uri = gazetteer.find_placename_uri(value)
if uri.nil?
logger.warn "assign-placenames: #{bare_druid} is missing gazetteer entry for '#{value}'" unless gazetteer.blank?(value)
next
end
add_uri_to_subject(subject, uri)
end
end
def place_subjects
description_props[:subject].select { |subject| subject[:type] == 'place' }
end
def add_uri_to_subject(subject, uri)
subject[:uri] = uri
subject[:source] = {
code: 'geonames',
uri: 'http://www.geonames.org/ontology#'
}
end
end
end
end
end