Class: Marc2LinkedData::Viaf

Inherits:
Resource show all
Defined in:
lib/marc2linkeddata/viaf.rb

Constant Summary collapse

PREFIX =
'http://viaf.org/viaf/'

Instance Attribute Summary

Attributes inherited from Resource

#iri

Instance Method Summary collapse

Methods inherited from Resource

#get_rdf, #id, #initialize, #iri_types, #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::Resource

Instance Method Details

#family_namesObject



39
40
41
42
43
# File 'lib/marc2linkeddata/viaf.rb', line 39

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

#get_isniObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/marc2linkeddata/viaf.rb', line 21

def get_isni
  return nil if @iri.nil?
  return nil unless rdf_valid?
  return @isni_iri unless @isni_iri.nil?
  # Try to get ISNI source for VIAF
  # e.g. http://viaf.org/viaf/sourceID/ISNI%7C0000000109311081#skos:Concept
  isni_iri = rdf_find_subject 'isni'
  isni_src = URI.parse(isni_iri.to_s)
  isni_iri = isni_src.path.sub('/viaf/sourceID/ISNI%7C','http://www.isni.org/isni/')
  @isni_iri = resolve_external_auth(isni_iri)
end

#given_namesObject



33
34
35
36
37
# File 'lib/marc2linkeddata/viaf.rb', line 33

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

#rdfObject

def id

return nil if @iri.nil?
iri.path.gsub('viaf/','').gsub('/','')

end



14
15
16
17
18
19
# File 'lib/marc2linkeddata/viaf.rb', line 14

def rdf
  return nil if @iri.nil?
  return @rdf unless @rdf.nil?
  uri4rdf = @iri.to_s + '/rdf.xml'
  @rdf = get_rdf(uri4rdf)
end