Skip to content

Commit

Permalink
Update display data format to accommodate multiple linked terms per r…
Browse files Browse the repository at this point in the history
…ecorded value
  • Loading branch information
mdholloway committed Jan 8, 2025
1 parent cf7638e commit d95536d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
44 changes: 23 additions & 21 deletions lib/digital_scriptorium/claim_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def self.transform(claim, export_hash, config)
authority_property_id = config['authority']

value = primary_value_from_claim(claim, export_hash)
display_data = { 'recorded_value' => value }
search_terms = [value]

solr_props['id'] = [value] if requested_fields.include? 'id'
solr_props["#{prefix}_meta"] = [value] if requested_fields.include? 'meta'

unless authority_property_id && claim.qualifiers_by_property_id?(authority_property_id)
solr_props["#{prefix}_display"] = [{ 'PV' => value }.to_json] if requested_fields.include? 'display'
solr_props["#{prefix}_search"] = [value] if requested_fields.include? 'search'
solr_props["#{prefix}_display"] = [display_data.to_json] if requested_fields.include? 'display'
solr_props["#{prefix}_search"] = search_terms if requested_fields.include? 'search'
solr_props["#{prefix}_facet"] = [value] if requested_fields.include? 'facet'

solr_props['images_facet'] = ['Yes'] if value && claim.property_id == IIIF_MANIFEST
Expand All @@ -31,37 +33,37 @@ def self.transform(claim, export_hash, config)
return solr_props
end

display_entries = []
search_entries = [value]
facets = []
linked_terms = []

claim.qualifiers_by_property_id(authority_property_id).each do |qualifier|
display_props = { 'PV' => value }

authority_id = qualifier.entity_id_value
authority = export_hash[authority_id]

if authority
label = authority.label('en')
next unless authority

term = {}
label = authority.label('en')

display_props['QL'] = label
search_entries << label
facets << label
term['label'] = label
search_terms << label
facets << label

external_uri = authority.claim_by_property_id(EXTERNAL_URI)&.data_value
wikidata_id = authority.claim_by_property_id(WIKIDATA_QID)&.data_value
wikidata_uri = wikidata_id && "https://www.wikidata.org/wiki/#{wikidata_id}"
external_uri = authority.claim_by_property_id(EXTERNAL_URI)&.data_value
wikidata_id = authority.claim_by_property_id(WIKIDATA_QID)&.data_value
wikidata_uri = wikidata_id && "https://www.wikidata.org/wiki/#{wikidata_id}"

# Only one or the other of these seem to exist for a given item in practice.
display_props['QU'] = external_uri if external_uri
display_props['QU'] = wikidata_uri if wikidata_uri
end
# Only one or the other of these seem to exist for a given item in practice.
term['source_url'] = external_uri if external_uri
term['source_url'] = wikidata_uri if wikidata_uri

display_entries << display_props.to_json
linked_terms << term
end

solr_props["#{prefix}_display"] = display_entries.uniq if requested_fields.include? 'display'
solr_props["#{prefix}_search"] = search_entries.uniq if requested_fields.include? 'search'
display_data['linked_terms'] = linked_terms.uniq if linked_terms.any?

solr_props["#{prefix}_display"] = [display_data.to_json] if requested_fields.include? 'display'
solr_props["#{prefix}_search"] = search_terms.uniq if requested_fields.include? 'search'
solr_props["#{prefix}_facet"] = facets.uniq if requested_fields.include? 'facet'

solr_props
Expand Down
31 changes: 16 additions & 15 deletions lib/digital_scriptorium/name_claim_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,47 @@ def self.transform(claim, export_hash)
prefix = role_label.downcase.split.last

recorded_name = claim.data_value
display_names = { 'PV' => recorded_name }
search_names = [recorded_name]
display_data = { 'recorded_value' => recorded_name }
search_terms = [recorded_name]

name_in_original_script = claim.qualifier_by_property_id(IN_ORIGINAL_SCRIPT)&.data_value&.value
display_names['AGR'] = name_in_original_script if name_in_original_script
search_names << name_in_original_script if name_in_original_script
display_data['AGR'] = name_in_original_script if name_in_original_script
search_terms << name_in_original_script if name_in_original_script

unless claim.qualifiers_by_property_id? NAME_IN_AUTHORITY_FILE
return {
"#{prefix}_display" => [display_names.to_json],
"#{prefix}_search" => search_names,
"#{prefix}_display" => [display_data.to_json],
"#{prefix}_search" => search_terms,
"#{prefix}_facet" => [recorded_name]
}
end

display_entries = []
facets = []
linked_terms = []

claim.qualifiers_by_property_id(NAME_IN_AUTHORITY_FILE).each do |qualifier|
display_names_for_qualifier = { 'PV' => recorded_name }
display_names_for_qualifier['AGR'] = name_in_original_script if name_in_original_script
term = {}

name_entity_id = qualifier.entity_id_value
name_item = export_hash[name_entity_id]
name_label = name_item.label('en')

display_names_for_qualifier['QL'] = name_label
search_names << name_label
term['label'] = name_label
search_terms << name_label
facets << name_label

wikidata_id = name_item.claim_by_property_id(WIKIDATA_QID).data_value
wikidata_url = "https://www.wikidata.org/wiki/#{wikidata_id}"
display_names_for_qualifier['QU'] = wikidata_url if wikidata_url
term['source_url'] = wikidata_url if wikidata_url

display_entries << display_names_for_qualifier.to_json
linked_terms << term
end

display_data['linked_terms'] = linked_terms.uniq if linked_terms.any?

{
"#{prefix}_display" => display_entries.uniq,
"#{prefix}_search" => search_names.uniq,
"#{prefix}_display" => [display_data.to_json],
"#{prefix}_search" => search_terms.uniq,
"#{prefix}_facet" => facets.uniq
}
end
Expand Down
19 changes: 9 additions & 10 deletions spec/digital_scriptorium/claim_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module DigitalScriptorium
solr_item = described_class.transform(id_claim, export_hash, config[PropertyId::DS_ID])
expected = {
'id' => ['DS121'],
'id_display' => ['{"PV":"DS121"}'],
'id_display' => ['{"recorded_value":"DS121"}'],
'id_search' => ['DS121']
}
expect(solr_item).to eq(expected)
Expand All @@ -57,7 +57,7 @@ module DigitalScriptorium
institution_claim = StatementRepresenter.new(Statement.new).from_json(institution_json)
solr_item = described_class.transform(institution_claim, export_hash, config[PropertyId::HOLDING_INSTITUTION_AS_RECORDED])
expected = {
'institution_display' => ['{"PV":"University of Pennsylvania","QL":"University of Pennsylvania","QU":"https://www.wikidata.org/wiki/Q49117"}'],
'institution_display' => ['{"recorded_value":"University of Pennsylvania","linked_terms":[{"label":"University of Pennsylvania","source_url":"https://www.wikidata.org/wiki/Q49117"}]}'],
'institution_search' => ['University of Pennsylvania'],
'institution_facet' => ['University of Pennsylvania']
}
Expand All @@ -67,15 +67,15 @@ module DigitalScriptorium
it 'transforms a holding status claim' do
status_claim = StatementRepresenter.new(Statement.new).from_json(status_json)
solr_item = described_class.transform(status_claim, export_hash, config[PropertyId::HOLDING_STATUS])
expected = { 'holding_status_display' => ['{"PV":"Current"}'] }
expected = { 'holding_status_display' => ['{"recorded_value":"Current"}'] }
expect(solr_item).to eq(expected)
end

it 'transforms a shelfmark claim' do
shelfmark_claim = StatementRepresenter.new(Statement.new).from_json(shelfmark_json)
solr_item = described_class.transform(shelfmark_claim, export_hash, config[PropertyId::SHELFMARK])
expected = {
'shelfmark_display' => ['{"PV":"Oversize LJS 110"}'],
'shelfmark_display' => ['{"recorded_value":"Oversize LJS 110"}'],
'shelfmark_search' => ['Oversize LJS 110']
}
expect(solr_item).to eq(expected)
Expand All @@ -92,7 +92,7 @@ module DigitalScriptorium
title_claim = StatementRepresenter.new(Statement.new).from_json(title_json)
solr_item = described_class.transform(title_claim, export_hash, config[PropertyId::TITLE_AS_RECORDED])
expected = {
'title_display' => ['{"PV":"Kitāb al-Majisṭī","QL":"Almagest"}'],
'title_display' => ['{"recorded_value":"Kitāb al-Majisṭī","linked_terms":[{"label":"Almagest"}]}'],
'title_search' => ['Kitāb al-Majisṭī', 'Almagest'],
'title_facet' => ['Almagest']
}
Expand All @@ -103,7 +103,7 @@ module DigitalScriptorium
genre_claim = StatementRepresenter.new(Statement.new).from_json(genre_json)
solr_item = described_class.transform(genre_claim, export_hash, config[PropertyId::GENRE_AS_RECORDED])
expected = {
'term_display' => ['{"PV":"Deeds","QL":"deeds","QU":"http://vocab.getty.edu/aat/300027249"}'],
'term_display' => ['{"recorded_value":"Deeds","linked_terms":[{"label":"deeds","source_url":"http://vocab.getty.edu/aat/300027249"}]}'],
'term_search' => %w[Deeds deeds],
'term_facet' => ['deeds']
}
Expand All @@ -114,7 +114,7 @@ module DigitalScriptorium
language_claim = StatementRepresenter.new(Statement.new).from_json(language_json)
solr_item = described_class.transform(language_claim, export_hash, config[PropertyId::LANGUAGE_AS_RECORDED])
expected = {
'language_display' => ['{"PV":"In Latin","QL":"Latin","QU":"https://www.wikidata.org/wiki/Q397"}'],
'language_display' => ['{"recorded_value":"In Latin","linked_terms":[{"label":"Latin","source_url":"https://www.wikidata.org/wiki/Q397"}]}'],
'language_search' => ['In Latin', 'Latin'],
'language_facet' => ['Latin']
}
Expand All @@ -125,7 +125,7 @@ module DigitalScriptorium
physical_description_claim = StatementRepresenter.new(Statement.new).from_json(physical_description_json)
solr_item = described_class.transform(physical_description_claim, export_hash, config[PropertyId::PHYSICAL_DESCRIPTION])
expected = {
'physical_description_display' => ['{"PV":"Extent: 1 parchment ; 170 x 245 mm."}'],
'physical_description_display' => ['{"recorded_value":"Extent: 1 parchment ; 170 x 245 mm."}'],
'physical_description_search' => ['Extent: 1 parchment ; 170 x 245 mm.']
}
expect(solr_item).to eq(expected)
Expand Down Expand Up @@ -153,8 +153,7 @@ module DigitalScriptorium
solr_item = described_class.transform(place_claim, export_hash, config[PropertyId::PRODUCTION_PLACE_AS_RECORDED])
expected = {
'place_display' => [
'{"PV":"[Provence or Spain],","QL":"Provence","QU":"http://vocab.getty.edu/tgn/7012209"}',
'{"PV":"[Provence or Spain],","QL":"Spain","QU":"http://vocab.getty.edu/tgn/1000095"}'
'{"recorded_value":"[Provence or Spain],","linked_terms":[{"label":"Provence","source_url":"http://vocab.getty.edu/tgn/7012209"},{"label":"Spain","source_url":"http://vocab.getty.edu/tgn/1000095"}]}'
],
'place_search' => [
'[Provence or Spain],',
Expand Down
2 changes: 1 addition & 1 deletion spec/digital_scriptorium/date_claim_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module DigitalScriptorium
solr_item = described_class.transform(date_claim, export_hash, config[PropertyId::PRODUCTION_DATE_AS_RECORDED])
expected = {
'date_meta' => ['1358.'],
'date_display' => ['{"PV":"1358.","QL":"fourteenth century (dates CE)","QU":"http://vocab.getty.edu/aat/300404506"}'],
'date_display' => ['{"recorded_value":"1358.","linked_terms":[{"label":"fourteenth century (dates CE)","source_url":"http://vocab.getty.edu/aat/300404506"}]}'],
'date_search' => ['1358.', 'fourteenth century (dates CE)'],
'date_facet' => ['fourteenth century (dates CE)'],
'century_int' => [1301],
Expand Down
5 changes: 2 additions & 3 deletions spec/digital_scriptorium/name_claim_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module DigitalScriptorium
it 'transforms a name claim' do
solr_item = described_class.transform(name_claim, export_hash)
expected = {
'owner_display' => ['{"PV":"Schoenberg, Lawrence J","QL":"Lawrence J. Schoenberg","QU":"https://www.wikidata.org/wiki/Q107542788"}'],
'owner_display' => ['{"recorded_value":"Schoenberg, Lawrence J","linked_terms":[{"label":"Lawrence J. Schoenberg","source_url":"https://www.wikidata.org/wiki/Q107542788"}]}'],
'owner_search' => ['Schoenberg, Lawrence J', 'Lawrence J. Schoenberg'],
'owner_facet' => ['Lawrence J. Schoenberg']
}
Expand All @@ -39,8 +39,7 @@ module DigitalScriptorium
solr_item = described_class.transform(name_multiple_qualifier_values_claim, export_hash)
expected = {
'owner_display' => [
'{"PV":"From the codex made for Leonello d\'Este. Brought to Wales as war booty by 1813, already in a damaged state, by the Rolls family, later enobled as Barons Llangattock, of The Hendre, Monmouth (Llangattock sale, London, Christie\'s, 8 December 1958, lot 190);","QL":"Leonello d\'Este, Marquis of Ferrara","QU":"https://www.wikidata.org/wiki/Q1379797"}',
'{"PV":"From the codex made for Leonello d\'Este. Brought to Wales as war booty by 1813, already in a damaged state, by the Rolls family, later enobled as Barons Llangattock, of The Hendre, Monmouth (Llangattock sale, London, Christie\'s, 8 December 1958, lot 190);","QL":"Baron Llangattock","QU":"https://www.wikidata.org/wiki/Q4862572"}'
'{"recorded_value":"From the codex made for Leonello d\'Este. Brought to Wales as war booty by 1813, already in a damaged state, by the Rolls family, later enobled as Barons Llangattock, of The Hendre, Monmouth (Llangattock sale, London, Christie\'s, 8 December 1958, lot 190);","linked_terms":[{"label":"Leonello d\'Este, Marquis of Ferrara","source_url":"https://www.wikidata.org/wiki/Q1379797"},{"label":"Baron Llangattock","source_url":"https://www.wikidata.org/wiki/Q4862572"}]}'
],
'owner_search' => [
'From the codex made for Leonello d\'Este. Brought to Wales as war booty by 1813, already in a damaged state, by the Rolls family, later enobled as Barons Llangattock, of The Hendre, Monmouth (Llangattock sale, London, Christie\'s, 8 December 1958, lot 190);',
Expand Down

0 comments on commit d95536d

Please sign in to comment.