Class: DigitalScriptorium::QualifiedClaimTransformer

Inherits:
BaseClaimTransformer show all
Includes:
PropertyId
Defined in:
lib/digital_scriptorium/transformers/qualified_claim_transformer.rb

Overview

Transformer for converting qualified claims of Digital Scriptorium items into Solr fields.

Constant Summary

Constants included from PropertyId

PropertyId::ACKNOWLEDGEMENTS, PropertyId::ASSOCIATED_NAME_AS_RECORDED, PropertyId::CENTURY, PropertyId::DATED, PropertyId::DATE_ADDED, PropertyId::DATE_LAST_UPDATED, PropertyId::DESCRIBED_MANUSCRIPT, PropertyId::DS_ID, PropertyId::EARLIEST_DATE, PropertyId::END_TIME, PropertyId::EQUIVALENT_PROPERTY, PropertyId::EXTERNAL_IDENTIFIER, PropertyId::EXTERNAL_URI, PropertyId::FORMATTER_URL, PropertyId::GENRE_AS_RECORDED, PropertyId::HOLDING_INSTITUTION_AS_RECORDED, PropertyId::HOLDING_INSTITUTION_IN_AUTHORITY_FILE, PropertyId::HOLDING_STATUS, PropertyId::IIIF_MANIFEST, PropertyId::INSTANCE_OF, PropertyId::INSTITUTIONAL_ID, PropertyId::IN_ORIGINAL_SCRIPT, PropertyId::LANGUAGE_AS_RECORDED, PropertyId::LANGUAGE_IN_AUTHORITY_FILE, PropertyId::LATEST_DATE, PropertyId::LINK_TO_INSTITUTIONAL_RECORD, PropertyId::MANUSCRIPT_HOLDING, PropertyId::MATERIAL_AS_RECORDED, PropertyId::MATERIAL_IN_AUTHORITY_FILE, PropertyId::NAME_IN_AUTHORITY_FILE, PropertyId::NOTE, PropertyId::PHYSICAL_DESCRIPTION, PropertyId::PLACE_IN_AUTHORITY_FILE, PropertyId::PRODUCTION_CENTURY_IN_AUTHORITY_FILE, PropertyId::PRODUCTION_DATE_AS_RECORDED, PropertyId::PRODUCTION_PLACE_AS_RECORDED, PropertyId::ROLE_IN_AUTHORITY_FILE, PropertyId::SHELFMARK, PropertyId::STANDARD_TITLE, PropertyId::START_TIME, PropertyId::SUBCLASS_OF, PropertyId::SUBJECT_AS_RECORDED, PropertyId::TERM_IN_AUTHORITY_FILE, PropertyId::TITLE_AS_RECORDED, PropertyId::UNIFORM_TITLE_AS_RECORDED, PropertyId::VIAF_ID, PropertyId::WIKIDATA_QID

Instance Attribute Summary collapse

Attributes inherited from BaseClaimTransformer

#claim, #prefix

Instance Method Summary collapse

Methods inherited from BaseClaimTransformer

#display_value, #solr_props

Constructor Details

#initialize(claim, export_hash, **kwargs) ⇒ QualifiedClaimTransformer

Returns a new instance of QualifiedClaimTransformer.



10
11
12
13
14
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 10

def initialize(claim, export_hash, **kwargs)
  super(claim, **kwargs)
  @export_hash = export_hash
  @authority_id = kwargs[:authority_id]
end

Instance Attribute Details

#authority_idObject (readonly)

Returns the value of attribute authority_id.



8
9
10
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 8

def authority_id
  @authority_id
end

#export_hashObject (readonly)

Returns the value of attribute export_hash.



8
9
10
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 8

def export_hash
  @export_hash
end

Instance Method Details

#display_valuesObject



16
17
18
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 16

def display_values
  [display_value(main_snak_value, in_original_script, linked_terms)]
end

#external_uri(authority) ⇒ Object



32
33
34
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 32

def external_uri(authority)
  authority.claims_by_property_id(EXTERNAL_URI)&.first&.data_value
end

#facet_valuesObject



24
25
26
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 24

def facet_values
  linked_term_labels
end

#in_original_scriptObject



28
29
30
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 28

def in_original_script
  claim.qualifiers_by_property_id(IN_ORIGINAL_SCRIPT)&.first&.data_value&.value
end

#linked_term_for(authority) ⇒ Object



44
45
46
47
48
49
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 44

def linked_term_for(authority)
  {
    'label' => authority.label('en'),
    'source_url' => external_uri(authority) || wikidata_uri(authority)
  }.compact
end

#linked_term_labelsObject



65
66
67
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 65

def linked_term_labels
  @linked_term_labels ||= linked_terms.map { |term| term['label'] }.uniq
end

#linked_termsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 51

def linked_terms
  @linked_terms ||= begin
    linked_terms = []

    claim.qualifiers_by_property_id(authority_id)&.each do |qualifier|
      authority_file_item_id = qualifier.entity_id_value
      authority = export_hash[authority_file_item_id]
      linked_terms << linked_term_for(authority) if authority
    end

    linked_terms.uniq
  end
end

#main_snak_valueObject



69
70
71
72
73
74
75
76
77
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 69

def main_snak_value
  if claim.value_type? WikibaseRepresentable::Model::EntityIdValue
    entity_id = claim.entity_id_value
    referenced_item = export_hash[entity_id]
    referenced_item.label('en')
  else
    claim.data_value
  end
end

#search_valuesObject



20
21
22
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 20

def search_values
  [main_snak_value, in_original_script, linked_term_labels].flatten.compact.uniq
end

#wikidata_id(authority) ⇒ Object



36
37
38
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 36

def wikidata_id(authority)
  authority.claims_by_property_id(WIKIDATA_QID)&.first&.data_value
end

#wikidata_uri(authority) ⇒ Object



40
41
42
# File 'lib/digital_scriptorium/transformers/qualified_claim_transformer.rb', line 40

def wikidata_uri(authority)
  wikidata_id(authority) && "https://www.wikidata.org/wiki/#{wikidata_id(authority)}"
end