Class: Identifier::Global::Wikidata

Inherits:
Identifier::Global show all
Defined in:
app/models/identifier/global/wikidata.rb

Overview

The globally unique identifier used in wikidata www.wikidata.org/wiki/Help:Namespaces www.wikidata.org/wiki/Q43649390

Constant Summary collapse

NAMESPACES =

This is not a comprehensive map of Namespaces, but rather ones envisioned of possibly being useful at some point, maybe.

As implemented we should be using ā€˜Qā€™ nearly everywhere, but perhaps also ā€˜Pā€™

%w{Q P}.freeze
URI_BASE =
'http://www.wikidata.org/wiki/'.freeze

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Constants included from Shared::DualAnnotator

Shared::DualAnnotator::ALWAYS_COMMUNITY

Instance Attribute Summary

Attributes inherited from Identifier::Global

#relation

Attributes inherited from Identifier

#cached, #cached_numeric_identifier, #identifier, #identifier_object_id, #namespace_id, #project_id, #type

Instance Method Summary collapse

Methods inherited from Identifier::Global

#build_cached, #dwc_occurrences, #is_global?, #sv_resolves?

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Methods inherited from Identifier

#build_cached, #build_cached_numeric_identifier, #is_global?, #is_local?, prototype_identifier, #set_cached, #type_name

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Labels

#labeled?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Method Details

#data_existsObject (private)



43
44
45
46
47
48
49
50
# File 'app/models/identifier/global/wikidata.rb', line 43

def data_exists
  return if errors.any?
  # wikidata-client doesn't use prepended 'Prefix:' in query
  a = ::Wikidata::Item.find(identifier)
  if a.nil?
    errors.add(:identifier, "Can not find #{identifier} in wikidata.")
  end
end

#namespace_formatObject (private)



39
40
41
# File 'app/models/identifier/global/wikidata.rb', line 39

def namespace_format
  errors.add(:identifier, 'Identifier is not prefixed with an recognized "namespace".') unless identifier =~ /\A#{NAMESPACES.join('|')}\d+/
end

#namespace_stringObject



19
20
21
22
# File 'app/models/identifier/global/wikidata.rb', line 19

def namespace_string
  identifier =~ /\A(\D+)\d+/
  $1
end

#prefixed_identifierObject



28
29
30
31
32
33
34
35
# File 'app/models/identifier/global/wikidata.rb', line 28

def prefixed_identifier
  case namespace_string
  when 'P'
    'Property:' + identifier
  else
    identifier
  end
end

#uriObject



24
25
26
# File 'app/models/identifier/global/wikidata.rb', line 24

def uri
  URI_BASE + prefixed_identifier
end