module BibCard

Constants

BIBO_DOCUMENT_PART
BIBO_SHORT_TITLE
DBO_ABSTRACT
DBO_INFLUENCED
DBO_INFLUENCED_BY
DBO_STARRING
DBO_THUMBNAIL
DBP_FOUNDED
DBP_LOCATION
DCT_IS_PART_OF
DCT_SOURCE
DC_IS_PART_OF
DC_SOURCE
FOAF_DEPICTION
FOAF_GIVEN_NAME

SHOULD BE LOADED VIA RDF::Vocab, but not working

FOAF_SURNAME
JSON_LD_CONTEXT
JSON_LD_FRAME
PROV_DERIVED_FROM
RDFS_COMMENT
RDFS_LABEL
SCHEMA_BIRTHDATE
SCHEMA_DEATHDATE
SCHEMA_DESCRIPTION
SCHEMA_NAME
SCHEMA_ORGANIZATION
SCHEMA_PERSON
SCHEMA_SAME_AS
SCOPE_NOTE
SKOS_NOTE
SKOS_SCOPENOTE
SKOS_SCOPE_NOTE
VERSION
VOCAB_PREFIXES
WDPS_STMT_EDU_AT
WDP_EDUCATED_AT
WDR_STATED_IN
WDT_EDUCATED_AT
WDT_ISBN
WDT_NOTABLE_WORKS
WDT_OCLC_NUMBER
WDT_WORK_LOCATION

Attributes

logger[W]

Public Class Methods

lcnaf_uri?(uri) click to toggle source
# File lib/bib_card.rb, line 53
def lcnaf_uri?(uri)
  url = uri.to_s
  url.match(/^http:\/\/id\.loc\.gov\/authorities\/names\/n[bors]{0,1}\d+$/).nil? ? false : true
end
logger() click to toggle source
# File lib/bib_card.rb, line 28
def logger
  @logger ||= Logger.new($stdout).tap do |logger|
    logger.progname = self.name
    logger.formatter = proc do |severity, time, progname, msg|
      "#{severity} [#{time.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{progname}: #{msg}\n"
    end
  end
end
person(uri) click to toggle source
# File lib/bib_card.rb, line 42
def person(uri)
  graph, viaf_uri = creator_graph_and_viaf_uri(uri)
  Spira.repository = graph
  viaf_uri.as(Person)
end
person_data(uri) click to toggle source
# File lib/bib_card.rb, line 37
def person_data(uri)
  graph, viaf_uri = creator_graph_and_viaf_uri(uri)
  graph.dump(:ntriples)
end
viaf_uri?(uri) click to toggle source
# File lib/bib_card.rb, line 48
def viaf_uri?(uri)
  url = uri.to_s
  url.match(/^http:\/\/viaf\.org\/viaf\/\d+$/).nil? ? false : true
end

Private Class Methods

convert_uri(uri) click to toggle source

Convert

# File lib/bib_card.rb, line 105
def convert_uri(uri)
  uri.is_a?(RDF::URI) ? uri : RDF::URI.new(uri)
end
creator_graph_and_viaf_uri(uri) click to toggle source
# File lib/bib_card.rb, line 60
def creator_graph_and_viaf_uri(uri)
  # Convert the URI to an RDF::URI object if it is not already
  uri = convert_uri(uri)

  # 1. Get the VIAF data and determine the VIAF URI
  begin
    if lcnaf_uri?(uri)
      # Load the VIAF data graph and determine the VIAF URI based on the LCNAF URI.
      identifier = lcnaf_uri_to_identifier(uri)
      viaf_url   = "http://viaf.org/viaf/sourceID/" + URI.encode_www_form_component("LC|#{identifier}")
      viaf_graph = RDF::Graph.load(viaf_url, format: :rdfxml)
      viaf_uri   = viaf_graph.query({predicate: SCHEMA_SAME_AS, object: uri}).first.subject
    elsif viaf_uri?(uri)
      # Load the VIAF data graph using the URI
      viaf_uri   = uri
      viaf_graph = RDF::Graph.load(uri, format: :rdfxml)
    else
      raise BibCard::InvalidURIException
    end
  rescue IOError
    raise BibCard::EntityNotFoundException
  rescue Errno::ECONNRESET
    raise BibCard::CrawlException.new("Unable to access VIAF, connection reset by peer.")
  rescue NoMethodError => e
    undifferentiated_uri_msg = "This VIAF URI has been corrupted by an 'undifferentiate name' and should be treated as unusable."
    results = viaf_graph.query({predicate: RDFS_COMMENT, object: undifferentiated_uri_msg})
    if results.size > 0
      raise BibCard::EntityNotFoundException.new(undifferentiated_uri_msg)
    else
      raise e
    end
  end

  # 2. Crawl and use it as a basis for crawling the other data sources
  crawler = Crawler.new(viaf_uri, viaf_graph)
  graph = crawler.creator_graph
  [graph, viaf_uri]
end
lcnaf_uri_to_identifier(uri) click to toggle source
# File lib/bib_card.rb, line 99
def lcnaf_uri_to_identifier(uri)
  url = uri.to_s
  url.gsub("http://id.loc.gov/authorities/names/", "")
end