Class: Marc2LinkedData::OclcResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/marc2linkeddata/oclc_resource.rb

Direct Known Subclasses

OclcCreativeWork, OclcWork

Constant Summary collapse

PREFIX =
'http://www.worldcat.org/oclc/'

Instance Attribute Summary

Attributes inherited from Resource

#iri

Instance Method Summary collapse

Methods inherited from Resource

#get_rdf, #id, #iri_types, #rdf_find_object, #rdf_find_subject, #rdf_uri, #rdf_valid?, #resolve_external_auth, #same_as, #same_as_array

Constructor Details

#initialize(uri = nil) ⇒ OclcResource

Returns a new instance of OclcResource.



9
10
11
12
13
14
15
# File 'lib/marc2linkeddata/oclc_resource.rb', line 9

def initialize(uri=nil)
  # Ensure the OCLC IRI contains 'www' in the host name.
  unless uri =~ /www\./
    uri = uri.to_s.gsub('worldcat.org','www.worldcat.org')
  end
  super(uri)
end

Instance Method Details

#aboutObject



47
48
49
50
# File 'lib/marc2linkeddata/oclc_resource.rb', line 47

def about
  q = SPARQL.parse('SELECT * WHERE { ?s <http://schema.org/about> ?o }')
  rdf.query(q)
end

#book?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/marc2linkeddata/oclc_resource.rb', line 27

def book?
  iri_types.filter {|s| s[:o] == 'http://schema.org/Book' }.length > 0
end

#contributor?(uri) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/marc2linkeddata/oclc_resource.rb', line 35

def contributor?(uri)
  contributors.include? RDF::URI.new(uri)
end

#contributorsObject



57
58
59
60
# File 'lib/marc2linkeddata/oclc_resource.rb', line 57

def contributors
  q = SPARQL.parse("SELECT * WHERE { <#{@iri}> <http://schema.org/contributor> ?o }")
  rdf.query(q).collect {|s| s[:o] }
end

#creator?(uri) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/marc2linkeddata/oclc_resource.rb', line 31

def creator?(uri)
  creators.include? RDF::URI.new(uri)
end

#creatorsObject



52
53
54
55
# File 'lib/marc2linkeddata/oclc_resource.rb', line 52

def creators
  q = SPARQL.parse("SELECT * WHERE { <#{@iri}> <http://schema.org/creator> ?o }")
  rdf.query(q).collect {|s| s[:o] }
end

#editor?(uri) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/marc2linkeddata/oclc_resource.rb', line 39

def editor?(uri)
  editors.include? RDF::URI.new(uri)
end

#editorsObject



62
63
64
65
# File 'lib/marc2linkeddata/oclc_resource.rb', line 62

def editors
  q = SPARQL.parse("SELECT * WHERE { <#{@iri}> <http://schema.org/editor> ?o }")
  rdf.query(q).collect {|s| s[:o] }
end

#isbnsObject



72
73
74
75
# File 'lib/marc2linkeddata/oclc_resource.rb', line 72

def isbns
  q = SPARQL.parse("SELECT * WHERE { <#{@iri}> <http://schema.org/isbn> ?o }")
  rdf.query(q).collect {|s| s[:o] }
end

#media_object?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/marc2linkeddata/oclc_resource.rb', line 43

def media_object?
  iri_types.filter {|s| s[:o] == 'http://schema.org/MediaObject' }.length > 0
end

#publishersObject



67
68
69
70
# File 'lib/marc2linkeddata/oclc_resource.rb', line 67

def publishers
  q = SPARQL.parse("SELECT * WHERE { <#{@iri}> <http://schema.org/publisher> ?o }")
  rdf.query(q).collect {|s| s[:o] }
end

#rdfObject



17
18
19
20
21
22
23
24
25
# File 'lib/marc2linkeddata/oclc_resource.rb', line 17

def rdf
  # e.g. 'http://worldcat.org/oclc/004957186'
  # also 'http://www.worldcat.org/oclc/004957186'
  return nil if @iri.nil?
  return @rdf unless @rdf.nil?
  uri4rdf = @iri.to_s
  uri4rdf += '.rdf' unless uri4rdf.end_with? '.rdf'
  @rdf = get_rdf(uri4rdf)
end