Class: LD4L::WorksRDF::GetModelFromURI

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

Class Method Summary collapse

Class Method Details

.call(uri) ⇒ Object

Attempt to get metadata from the source of the URI via content negotiation.

Parameters:

  • uri (String, RDF::URI)

    for the work



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
44
# File 'lib/ld4l/works_rdf/services/get_model_from_uri.rb', line 11

def self.call( uri )
  uri = uri.to_s if uri.kind_of?(RDF::URI)

  # curl -L -D - -H "Accept: text/turtle" http://vivo.cornell.edu/individual/n56611
  http = Curl.get(uri) do |curl|
    curl.headers['Accept'] = 'text/turtle'
    curl.headers['Content-Type'] = 'text/turtle'
    curl.headers['Api-Version'] = '2.2'
    curl.follow_location = true
    curl.max_redirects = 3
    curl.connect_timeout = 30
    curl.useragent = "curb"
  end
  result = http.body_str
  header = http.header_str

  work_graph = RDF::Graph.new.from_ttl result
  repo_name = SecureRandom.uuid.to_sym
  # r = RDF::Repository.new
  r = ActiveTriples::Repositories.add_repository repo_name, RDF::Repository.new
  r << work_graph

  # Get work as a generic work
  the_work = self.get_generic_work( r, uri )
  types = []
  the_work.type.each do |t|
    types << t.to_s
  end

  # Try to get more specific work
  the_work = self.get_vivo_book( r, uri )    if types.include? RDFVocabularies::BIBO.Book.to_s
  the_work = self.get_schema_book( r, uri )  if types.include? RDF::SCHEMA.Book.to_s
  the_work
end

.get_generic_work(repo, uri) ⇒ Object



46
47
48
# File 'lib/ld4l/works_rdf/services/get_model_from_uri.rb', line 46

def self.get_generic_work( repo, uri )
  LD4L::WorksRDF::GenericWork.new(uri, :data => repo)
end

.get_schema_book(repo, uri) ⇒ Object



54
55
56
# File 'lib/ld4l/works_rdf/services/get_model_from_uri.rb', line 54

def self.get_schema_book( repo, uri )
  LD4L::WorksRDF::SchemaBook.new(uri, :data => repo)
end

.get_vivo_book(repo, uri) ⇒ Object



50
51
52
# File 'lib/ld4l/works_rdf/services/get_model_from_uri.rb', line 50

def self.get_vivo_book( repo, uri )
  LD4L::WorksRDF::VivoBook.new(uri, :data => repo)
end