Class: Marc2LinkedData::Loc

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

Constant Summary collapse

PREFIX =
'http://id.loc.gov/authorities/'
PREFIX_NAMES =
"#{PREFIX}names/"
PREFIX_SUBJECTS =
"#{PREFIX}subjects/"

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

#authority?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/marc2linkeddata/loc.rb', line 33

def authority?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#Authority' }.length > 0
end

#conference?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/marc2linkeddata/loc.rb', line 41

def conference?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#ConferenceName' }.length > 0
end

#corporation?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/marc2linkeddata/loc.rb', line 45

def corporation?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#CorporateName' }.length > 0
end

#deprecated?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/marc2linkeddata/loc.rb', line 37

def deprecated?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#DeprecatedAuthority' }.length > 0
end

#geographic?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/marc2linkeddata/loc.rb', line 60

def geographic?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#Geographic' }.length > 0
end

#get_oclc_identityObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/marc2linkeddata/loc.rb', line 68

def get_oclc_identity
  # Try to get OCLC URI from LOC ID
  # http://oclc.org/developer/develop/web-services/worldcat-identities.en.html
  # e.g. http://www.worldcat.org/identities/lccn-n79044803/
  # e.g. http://www.worldcat.org/identities/lccn-n79044798/
  return @oclc_iri unless @oclc_iri.nil?
  oclc_url = URI.encode('http://www.worldcat.org/identities/lccn-' + id + '/')
  @oclc_iri = resolve_external_auth(oclc_url)
  # TODO: OCLC might redirect and then provide a 'fast' URI for obsolete identity records.
end

#get_viafObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/marc2linkeddata/loc.rb', line 79

def get_viaf
  return @viaf_iri unless @viaf_iri.nil?
  # Try to get VIAF from LOC sourceID
  # LOC statement with VIAF URI, e.g.:
  # s: <http://id.loc.gov/authorities/names/n79046291>
  # p: <http://www.loc.gov/mads/rdf/v1#hasExactExternalAuthority>
  # o: <http://viaf.org/viaf/sourceID/LC%7Cn+79046291#skos:Concept> .
  #return nil unless rdf_valid?
  #@viaf_iri ||= rdf_find_object 'viaf'
  viaf_url = URI.encode('http://viaf.org/viaf/sourceID/LC|' + id + '#skos:Concept')
  @viaf_iri = resolve_external_auth(viaf_url)
end

#labelObject



27
28
29
30
31
# File 'lib/marc2linkeddata/loc.rb', line 27

def label
  label_predicate = '<http://www.loc.gov/mads/rdf/v1#authoritativeLabel>'
  query = SPARQL.parse("SELECT * WHERE { <#{@iri}> #{label_predicate} ?o }")
  rdf.query(query).first[:o].to_s rescue nil
end

#name_title?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/marc2linkeddata/loc.rb', line 49

def name_title?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#NameTitle' }.length > 0
end

#person?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/marc2linkeddata/loc.rb', line 53

def person?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#PersonalName' }.length > 0
  # iri_types.filter {|s| s[:o] =~ /PersonalName/ }.length > 0
  # obj = rdf_find_object 'PersonalName'
  # obj.nil? ? false : true
end

#rdfObject

def id

return nil if @iri.nil?
@id ||= @iri.basename
# Could get id from rdf, but that incurs costs for RDF retrieval and parsing etc.
#oclc_id = '<identifiers:oclcnum>oca04921729</identifiers:oclcnum>'
#<identifiers:lccn>no 99010609</identifiers:lccn>
#<identifiers:oclcnum>oca04921729</identifiers:oclcnum>

end



20
21
22
23
24
25
# File 'lib/marc2linkeddata/loc.rb', line 20

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

#uniform_title?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/marc2linkeddata/loc.rb', line 64

def uniform_title?
  iri_types.filter {|s| s[:o] == 'http://www.loc.gov/mads/rdf/v1#Title' }.length > 0
end