Method: Marc2LinkedData::OclcCreativeWork#get_works

Defined in:
lib/marc2linkeddata/oclc_creative_work.rb

#get_worksObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/marc2linkeddata/oclc_creative_work.rb', line 9

def get_works
  # assume an exampleOfWork can only ever link to one work?
  q = query_work(@iri)
  works = rdf.query(q).collect {|s| s[:o] }
  if works.empty?
    # OCLC data is inconsistent in use of 'www.' in IRI, so try again.
    # The OclcResource coerces @iri so it includes 'www.', so try without it.
    uri = @iri.to_s.gsub('www.','')
    q = query_work(uri)
    works = rdf.query(q).collect {|s| s[:o] }
  end
  if works.empty?
    # Keep the 'www.', cast the ID to an integer.
    uri = @iri.to_s.gsub(id, id.to_i.to_s)
    q = query_work(uri)
    works = rdf.query(q).collect {|s| s[:o] }
  end
  if works.empty?
    # Remove the 'www.' AND cast the ID to an integer.
    uri = @iri.to_s.gsub('www.','').gsub(id, id.to_i.to_s)
    q = query_work(uri)
    works = rdf.query(q).collect {|s| s[:o] }
  end
  works
end