Class: Krikri::Mapper::Agent

Inherits:
Object
  • Object
show all
Includes:
SoftwareAgent
Defined in:
lib/krikri/mapper.rb

Overview

A SoftwareAgent to run mapping processes.

@see: Krikri::SoftwareAgent, Krikri::Activity

Constant Summary

Constants included from SoftwareAgent

SoftwareAgent::Logger

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SoftwareAgent

#agent_name, #log

Constructor Details

#initialize(opts = {}) ⇒ Agent


103
104
105
106
# File 'lib/krikri/mapper.rb', line 103

def initialize(opts = {})
  @name = opts.fetch(:name).to_sym
  @generator_uri = RDF::URI(opts.fetch(:generator_uri))
end

Instance Attribute Details

#generator_uriObject (readonly)

Returns the value of attribute generator_uri


97
98
99
# File 'lib/krikri/mapper.rb', line 97

def generator_uri
  @generator_uri
end

#nameObject (readonly)

Returns the value of attribute name


97
98
99
# File 'lib/krikri/mapper.rb', line 97

def name
  @name
end

Class Method Details

.queue_nameObject


99
100
101
# File 'lib/krikri/mapper.rb', line 99

def self.queue_name
  :mapping
end

Instance Method Details

#recordsObject


122
123
124
125
126
127
# File 'lib/krikri/mapper.rb', line 122

def records
  Krikri::ProvenanceQueryClient.find_by_activity(generator_uri)
    .execute.lazy.flat_map do |solution|
    OriginalRecord.load(solution.record.to_s)
  end
end

#run(activity_uri = nil) ⇒ Object


108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/krikri/mapper.rb', line 108

def run(activity_uri = nil)
  Krikri::Mapper.map(name, records).each do |rec|
    begin
      rec.mint_id! if rec.node?
      rec << RDF::Statement(rec, RDF::PROV.wasGeneratedBy, activity_uri) if
        activity_uri
      rec.save
    rescue => e
      Rails.logger.error("Error saving record: #{rec.rdf_subject}\n" \
                         "#{e.message}\n#{e.backtrace}")
    end
  end
end