Class: Krikri::Enricher
- Inherits:
-
Object
- Object
- Krikri::Enricher
- Includes:
- EntityConsumer, SoftwareAgent
- Defined in:
- lib/krikri/enricher.rb
Overview
A SoftwareAgent that runs enrichment processes.
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#generator_uri ⇒ Object
readonly
Returns the value of attribute generator_uri.
Attributes included from SoftwareAgent
Class Method Summary collapse
Instance Method Summary collapse
-
#chain_enrichments!(agg) ⇒ Object
Given an aggregation, take each enrichment specified by the ‘chain’ given in our instantiation, and apply that enrichment, with the given options, modifying the aggregation in-place.
-
#initialize(opts = {}) ⇒ Enricher
constructor
Create a new Enricher, given a hash of options: generator_uri: the LDP URI of the Activity that generated the mapped records that this one will enrich.
-
#run(activity_uri = nil) ⇒ Object
Run the enrichmnt.
Methods included from EntityConsumer
#assign_generator_activity!, #entities, #entity_source, #set_entity_source!
Methods included from SoftwareAgent
Constructor Details
#initialize(opts = {}) ⇒ Enricher
Create a new Enricher, given a hash of options:
generator_uri: the LDP URI of the Activity that generated the mapped
records that this one will enrich.
chain: a hash specifying the input_fields and output_fields, as
illustrated above, which will be passed to the Enrichment.
44 45 46 47 48 |
# File 'lib/krikri/enricher.rb', line 44 def initialize(opts = {}) @chain = deep_sym(opts.fetch(:chain) { {} }) @entity_behavior = self.class.entity_behavior assign_generator_activity!(opts) end |
Instance Attribute Details
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
29 30 31 |
# File 'lib/krikri/enricher.rb', line 29 def chain @chain end |
#generator_uri ⇒ Object (readonly)
Returns the value of attribute generator_uri.
29 30 31 |
# File 'lib/krikri/enricher.rb', line 29 def generator_uri @generator_uri end |
Class Method Details
.queue_name ⇒ Object
31 32 33 |
# File 'lib/krikri/enricher.rb', line 31 def self.queue_name :enrichment end |
Instance Method Details
#chain_enrichments!(agg) ⇒ Object
Given an aggregation, take each enrichment specified by the ‘chain’ given in our instantiation, and apply that enrichment, with the given options, modifying the aggregation in-place.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/krikri/enricher.rb', line 73 def chain_enrichments!(agg) chain.keys.each do |e| enrichment = enrichment_cache(e) if enrichment.is_a? Audumbla::FieldEnrichment agg = do_field_enrichment(agg, enrichment, chain[e]) else agg = do_basic_enrichment(agg, enrichment, chain[e]) end end end |
#run(activity_uri = nil) ⇒ Object
Run the enrichmnt.
Take each record that was affected by the activity defined by our instantiation, and apply each enrichment from the enrichment chain.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/krikri/enricher.rb', line 56 def run(activity_uri = nil) entities.each do |rec| begin chain_enrichments!(rec) activity_uri ? rec.save_with_provenance(activity_uri) : rec.save rescue => e Krikri::Logger.log(:error, "Enrichment error: #{e.}\n#{e.backtrace}") end end end |