Skip to content

Commit

Permalink
Fix bugs, add logging to script
Browse files Browse the repository at this point in the history
  • Loading branch information
mdholloway committed Jan 15, 2025
1 parent 0d111dd commit 9607f74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module DigitalScriptorium
class DatedClaimTransformer < BaseClaimTransformer
PREFIX = 'dated'

def initialize(claim, _export_hash)
def initialize(claim, export_hash)
super(claim, prefix: PREFIX)
@export_hash = export_hash
end

def facet_values
[export_hash[@claim.entity_id_value]&.label('en')].compact
[@export_hash[@claim.entity_id_value]&.label('en')].compact
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def initialize(claim, export_hash)
end

def role_prefix(claim, export_hash)
role_entity_id = claim.qualifiers_by_property_id(ROLE_IN_AUTHORITY_FILE).first.entity_id_value
role_entity_id = claim.qualifiers_by_property_id(ROLE_IN_AUTHORITY_FILE)&.first&.entity_id_value
raise "Missing role qualifier for name claim" unless role_entity_id

role_item = export_hash[role_entity_id]
role_label = role_item.label('en')
role_label.split.last.downcase
rescue e
raise "Error fetching role qualifier: #{e}"
end
end
end
13 changes: 8 additions & 5 deletions wikibase_to_solr_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'digital_scriptorium'
require 'json'
require 'logging'
require 'optparse'
require 'set'
require 'time'
Expand All @@ -16,6 +17,8 @@
config_file = File.expand_path 'property_config.yml', dir
pretty_print = false

logger = Logging.logger(STDOUT)

OptionParser.new { |opts|
opts.banner = 'Usage: wikibase_to_solr.rb [options]'

Expand Down Expand Up @@ -92,11 +95,11 @@ def record?(entity)
next unless (property_config = config[property_id])

begin
transformer = property_config['transformer_class'].new claim, export_hash
solr_item = merge(solr_item, transformer.solr_props)
rescue e
# TODO: Log properly
puts "Error processing item ID #{item.id}: #{e}"
transformer_class = DigitalScriptorium.const_get(property_config['transformer_class'])
transformer = transformer_class.new claim, export_hash
solr_item = merge solr_item, transformer.solr_props
rescue => e
logger.error "Error processing claim for item #{item.id}: #{e}"
end
end
end
Expand Down

0 comments on commit 9607f74

Please sign in to comment.