Class: Marc2LinkedData::OclcCreativeWork
- Inherits:
-
OclcResource
- Object
- Resource
- OclcResource
- Marc2LinkedData::OclcCreativeWork
- Defined in:
- lib/marc2linkeddata/oclc_creative_work.rb
Constant Summary collapse
- PREFIX =
'http://www.worldcat.org/oclc/'
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
Methods inherited from OclcResource
#about, #book?, #contributor?, #contributors, #creator?, #creators, #editor?, #editors, #initialize, #isbns, #media_object?, #publishers, #rdf
Methods inherited from Resource
#get_rdf, #id, #initialize, #iri_types, #rdf, #rdf_find_object, #rdf_find_subject, #rdf_uri, #rdf_valid?, #resolve_external_auth, #same_as, #same_as_array
Constructor Details
This class inherits a constructor from Marc2LinkedData::OclcResource
Instance Method Details
#get_works ⇒ Object
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 |
#query_work(uri) ⇒ Object
35 36 37 |
# File 'lib/marc2linkeddata/oclc_creative_work.rb', line 35 def query_work(uri) SPARQL.parse("SELECT * WHERE { <#{uri}> <http://schema.org/exampleOfWork> ?o }") end |