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

Instance Attribute Summary

Attributes inherited from Identifier::Global

#relation

Attributes inherited from Identifier

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

Attributes included from Shared::DualAnnotator

#is_community_annotation

Instance Method Summary collapse

Methods inherited from Identifier::Global

#permit_only_one_global_without_relation_supplied_per_type, #set_cached, #sv_resolves?

Methods included from SoftValidation

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

Methods inherited from Identifier

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 Housekeeping

#has_polymorphic_relationship?

Methods included from Shared::DualAnnotator

#is_community_annotation?

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