Class: Krikri::Enrichments::DcmiTypeMap

Inherits:
Object
  • Object
show all
Includes:
Audumbla::FieldEnrichment
Defined in:
lib/krikri/enrichments/dcmi_type_map.rb

Overview

Maps string values to DCMI Type vocabulary terms.

Mapping is performed by comparing a hash of string keys to the pre-enriched value, using White Similarity comparisons to determine the closest match. If a suitable match is found, a DLPA::MAP::Controlled::DCMIType object is built from the appropriate hash value and set as the new value.

This enrichment ignores strings without a DCMI Type match.

Examples:


type_mapper = DcmiTypeMap.new
type_mapper.enrich_value('image') # finds RDF::DCMITYPE.Image
type_mapper.enrich_value('a book') # finds RDF::DCMITYPE.Text
type_mapper.enrich_value('a really cool book') # => 'a really cool book'

type_mapper = DcmiTypeMap.new('poloriod' => RDF::DCMIType.Image)
type_mapper.enrich_value('poloroid.') # finds RDF::DCMITYPE.Image

Constant Summary collapse

DEFAULT_MAP =
{ 'image' => RDF::DCMITYPE.Image,
  'photograph' => RDF::DCMITYPE.Image,
  'sample book' => RDF::DCMITYPE.Image,
  'specimen' => RDF::DCMITYPE.Image,
  'textile' => RDF::DCMITYPE.Image,
  'frame' => RDF::DCMITYPE.Image,
  'costume' => RDF::DCMITYPE.Image,
  'statue' => RDF::DCMITYPE.Image,
  'sculpture' => RDF::DCMITYPE.Image,
  'container' => RDF::DCMITYPE.Image,
  'jewelry' => RDF::DCMITYPE.Image,
  'furnishing' => RDF::DCMITYPE.Image,
  'furniture' => RDF::DCMITYPE.Image,
  'drawing' => RDF::DCMITYPE.Image,
  'print' => RDF::DCMITYPE.Image,
  'painting' => RDF::DCMITYPE.Image,
  'illumination' => RDF::DCMITYPE.Image,
  'poster' => RDF::DCMITYPE.Image,
  'appliance' => RDF::DCMITYPE.Image,
  'tool' => RDF::DCMITYPE.Image,
  'electronic component' => RDF::DCMITYPE.Image,
  'postcard' => RDF::DCMITYPE.Image,
  'equipment' => RDF::DCMITYPE.Image,
  'cartographic' => RDF::DCMITYPE.Image,
  'notated music' => RDF::DCMITYPE.Image,
  'mixed material' => RDF::DCMITYPE.Image,
  'text' => RDF::DCMITYPE.Text,
  'book' => RDF::DCMITYPE.Text,
  'publication' => RDF::DCMITYPE.Text,
  'magazine' => RDF::DCMITYPE.Text,
  'journal' => RDF::DCMITYPE.Text,
  'correspondence' => RDF::DCMITYPE.Text,
  'writing' => RDF::DCMITYPE.Text,
  'written' => RDF::DCMITYPE.Text,
  'manuscript' => RDF::DCMITYPE.Text,
  'online text' => RDF::DCMITYPE.Text,
  'audio' => RDF::DCMITYPE.Sound,
  'sound' => RDF::DCMITYPE.Sound,
  'oral history recording' => RDF::DCMITYPE.Sound,
  'finding aid' => RDF::DCMITYPE.Collection,
  'online collection' => RDF::DCMITYPE.Collection,
  'electronic resource' => RDF::DCMITYPE.InteractiveResource,
  'video game' => RDF::DCMITYPE.InteractiveResource,
  'online exhibit' => RDF::DCMITYPE.InteractiveResource,
  'moving image' => RDF::DCMITYPE.MovingImage,
  'movingimage' => RDF::DCMITYPE.MovingImage,
  'motion picture' => RDF::DCMITYPE.MovingImage,
  'film' => RDF::DCMITYPE.MovingImage,
  'video' => RDF::DCMITYPE.MovingImage,
  'object' => RDF::DCMITYPE.PhysicalObject
}

Instance Method Summary collapse

Constructor Details

#initialize(map = nil) ⇒ DcmiTypeMap

Returns a new instance of DcmiTypeMap.

Parameters:

  • map (Hash<String, RDF::Vocabulary::Term>) (defaults to: nil)


82
83
84
# File 'lib/krikri/enrichments/dcmi_type_map.rb', line 82

def initialize(map = nil)
  @map = map || DEFAULT_MAP
end

Instance Method Details

#enrich_value(value) ⇒ DPLA::MAP::Controlled::DCMIType?

Returns the matching DCMI Type term. ‘nil` if no matches are found.

Parameters:

  • value (Object)

    the value to enrich

Returns:

  • (DPLA::MAP::Controlled::DCMIType, nil)

    the matching DCMI Type term. ‘nil` if no matches are found.



91
92
93
94
95
96
97
98
99
# File 'lib/krikri/enrichments/dcmi_type_map.rb', line 91

def enrich_value(value)
  return value unless value.is_a? String

  match = @map.fetch(value.downcase) { most_similar(value) }
  return value if match.nil?
  dcmi = DPLA::MAP::Controlled::DCMIType.new(match)
  dcmi.prefLabel = match.label
  dcmi
end