Class: LD4L::WorksRDF::PopulateBibframeModelsFromRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/works_rdf/services/model_services/populate_bibframe_models_from_repository.rb

Class Method Summary collapse

Class Method Details

.call(bibframe_work_uri, repository) ⇒ Object

Create a Bibframe model and populate it with metadata from the repository.

Parameters:

  • repository (RDF::Repository)

    holding triples

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ld4l/works_rdf/services/model_services/populate_bibframe_models_from_repository.rb', line 11

def self.call( bibframe_work_uri, repository )
  raise ArgumentError, 'bibframe_work_uri argument must be a uri string or an instance of RDF::URI'  unless
      bibframe_work_uri.kind_of?(String) && bibframe_work_uri.size > 0 || bibframe_work_uri.kind_of?(RDF::URI)

  raise ArgumentError, 'repository argument must be an instance of RDF::Repository'  unless
      repository.kind_of?(RDF::Repository)

  bibframe_work_uri = RDF::URI(bibframe_work_uri) unless bibframe_work_uri.kind_of?(RDF::URI)

  # TODO: Move to common place because this code is repeated in each model_from_repository file
  # # Get work as a generic work
  # work = LD4L::WorksRDF::GenericWork.new(uri, :data => repository)
  # types = []
  # work.type.each do |t|
  #   types << t.to_s
  # end

  query = RDF::Query.new({
                             :instance => {
                                 RDF.type =>  RDFVocabularies::BF.Instance,
                                 RDFVocabularies::BF.instanceOf => bibframe_work_uri,
                             }
                         })
  instances = []
  results = query.execute(repository)
  results.each { |r| instances << r.to_hash[:instance] }
  instances

  work     = LD4L::WorksRDF::BibframeWork.new(bibframe_work_uri, :data => repository)
  instance = LD4L::WorksRDF::BibframeInstance.new(instances.first, :data=>repository)

  { :work => work, :instance => instance }
end