Class: Krikri::Enrichments::CreatePrefLabelFromProvided

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

Overview

Given an field that accepts both providedLabel and prefLabel, copies the first providedLabel into prefLabel unless one is already present.

Only the first providedLabel is copied, avoiding conflicts with SKOS's limit of one skos:prefLabel per language tag.

Fields are ignored and returned as-is if:

- they are not `ActiveTriples::Resource`
- they do not respond to `#providedLabel`
- they already have a `prefLabel`
- there are no `providedLabel`s present

Examples:

enriching a resource with a providedLabel

label_enricher = CreatePrefLabelFromProvided.new

resource.providedLabel = 'moomin'
label_enricher.enrich_value(resource)
resource.dump :ttl
# [
#   a <http://www.europeana.eu/schemas/edm/Agent>;
#   <http://dp.la/about/map/providedLabel> "moomin";
#   <http://www.w3.org/2004/02/skos/core#prefLabel> "moomin"
# ] .

See Also:

Instance Method Summary collapse

Instance Method Details

#enrich_value(value) ⇒ Object

Parameters:

  • value (Object)

    the value to split

See Also:

  • Audumbla::FieldEnrichment#enrich_value


36
37
38
39
40
# File 'lib/krikri/enrichments/create_pref_label_from_provided.rb', line 36

def enrich_value(value)
  return value unless value.is_a?(ActiveTriples::Resource) &&
                      value.respond_to?(:providedLabel)
  add_pref_label(value)
end