Method: Audumbla::Enrichment#enrich

Defined in:
lib/audumbla/enrichment.rb

#enrich(record, input_fields, output_fields) ⇒ ActiveTriples::Resource

The main enrichment method; passes specified input fields to #enrich_values, which must return an array of values with length equal to the number of output fields. The values of the output fields are set to the corresponding result from the enrichment.

Pass fields to ‘input_fields` and `output_fields`. Fields are formatted as symbols in nested hashes, targeting a particular field in an ActiveTriples Resource property hierarchy:

:sourceResource
{:sourceResource => :spatial}
{:sourceResource => {:creator => :name}}

The record passed in is not altered, but cloned before the enrichment is applied. A common pattern may be:

record = my_enrichment.enrich(record, input, output)
record.persist!

Input fields create an array selecting the values of all matching fields. For example:

an array of values from record.sourceResource:

:sourceResource

an array of values combining spatial fields from the values of record.sourceResource:

{:sourceResource => :spatial}

an array of values combining name fields from the creators in record.sourceResource:

{:sourceResource => {:creator => :name}}

Output fields should be specified at a high enough level that the enrichment can build a complete value set from the input values provided. An enrichment for mapping names to LCSH URIs, that alters all creator fields might be formatted:

my_enrichment.enrich(record,
  [{:sourceResource => {:creator => :providedLabel}}],
  [{:sourceResource => :creator}])

This would pass the values like the following, sourced from the providedLabel, to #enrich_value:

[['Moomintroll', 'Moomin Papa', 'Moomin Mama']]

And it would expect to receive an array of values set directly to creator, overwriting all existing creator values:

[DPLA::MAP::Agent:0x3ff(default),
 DPLA::MAP::Agent:0x9f5(default),
 DPLA::MAP::Agent:0x3a8(default)]

Parameters:

  • record (ActiveTriples::Resource)

    the record to enrich

  • input_fields (Array)

    the fields whose values to pass to the enrichment method

  • output_fields (Array)

    the fields on which to apply the enrichment

Returns:

  • (ActiveTriples::Resource)

    the enriched record



67
68
69
# File 'lib/audumbla/enrichment.rb', line 67

def enrich(record, input_fields, output_fields)
  enrich!(record.clone, input_fields, output_fields)
end