Class: Marc2LinkedData::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/marc2linkeddata/configuration.rb', line 41

def initialize
  @debug = env_boolean('DEBUG')
  @test_records = ENV['TEST_RECORDS'].to_i

  @threads = env_boolean('THREADS')
  @thread_limit = ENV['THREAD_LIMIT'].to_i || 25

  # logging
  log_file = ENV['LOG_FILE'] || 'marc2ld.log'
  log_file = File.absolute_path log_file
  @log_file = log_file
  log_path = File.dirname log_file
  unless File.directory? log_path
    # try to create the log directory
    Dir.mkdir log_path rescue nil
  end
  begin
    log_file = File.new(@log_file, 'w+')
  rescue
    log_file = $stderr
    @log_file = 'STDERR'
  end
  @logger = Logger.new(log_file, shift_age = 'monthly')
  @logger.level = @debug ? Logger::DEBUG : Logger::INFO

  # RDF prefixes
  @prefixes = {}
  # Library specific prefixes (use .env file or set shell ENV)
  @prefixes['lib'] = ENV['LIB_PREFIX'] || 'http://linked-data.stanford.edu/library/'
  @prefixes['lib_auth'] = "#{prefixes['lib']}authority/"
  @prefixes['lib_cat']  = "#{prefixes['lib']}catalog/"
  # Static Prefixes
  @prefixes['bf'] = 'http://bibframe.org/vocab/'
  @prefixes['foaf'] = 'http://xmlns.com/foaf/0.1/'
  @prefixes['isni'] = 'http://www.isni.org/isni/'
  @prefixes['loc_names'] = 'http://id.loc.gov/authorities/names/'
  @prefixes['loc_subjects'] = 'http://id.loc.gov/authorities/subjects/'
  @prefixes['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
  @prefixes['rdfs'] = 'http://www.w3.org/2000/01/rdf-schema#'
  @prefixes['schema'] = 'http://schema.org/'
  @prefixes['owl'] = 'http://www.w3.org/2002/07/owl#'
  @prefixes['viaf'] = 'http://viaf.org/viaf/'

  # Authority parse options
  @field_auth_id = ENV['FIELD_AUTH_ID'] || '001'
  @field_auth_loc = ENV['FIELD_AUTH_LOC']
  @field_auth_isni = ENV['FIELD_AUTH_ISNI']
  @field_auth_oclc = ENV['FIELD_AUTH_OCLC']
  @field_auth_viaf = ENV['FIELD_AUTH_VIAF']

  @get_isni = env_boolean('GET_ISNI')
  @get_loc = env_boolean('GET_LOC')
  @get_viaf = env_boolean('GET_VIAF')
  @get_oclc = env_boolean('GET_OCLC')
  @oclc_auth2works = env_boolean('OCLC_AUTH2WORKS')

  # Vocabulary options
  # foaf:Person or schema:Person or both?
  @use_foaf = env_boolean('USE_FOAF')
  @use_schema = env_boolean('USE_SCHEMA') # schema.org

  # Local triple store for LOC authority data,
  # accessed via an HTTP API with basic authentication.
  # See downloads at http://id.loc.gov/download/
  @local_loc_user = ENV['LOCAL_LOC_USER']
  @local_loc_pass = ENV['LOCAL_LOC_PASS']
  loc_host = ENV['LOCAL_LOC_HOST']
  loc_port = ENV['LOCAL_LOC_PORT']
  loc_path = ENV['LOCAL_LOC_PATH']
  @local_loc_url = "http://#{loc_host}:#{loc_port}#{loc_path}"

  # Persistence options
  @redis = nil
  @redis4marc = env_boolean('REDIS4MARC')
  if @redis4marc
    @redis_url = env_boolean('REDIS_URL')
    @redis_read  = env_boolean('REDIS_READ')
    @redis_write = env_boolean('REDIS_WRITE')
    redis_config
  else
    @redis_url = nil
    @redis_read  = false
    @redis_write = false
  end
  # TODO: provide options for triple stores
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



6
7
8
# File 'lib/marc2linkeddata/configuration.rb', line 6

def debug
  @debug
end

#field_auth_idObject

Returns the value of attribute field_auth_id.



12
13
14
# File 'lib/marc2linkeddata/configuration.rb', line 12

def field_auth_id
  @field_auth_id
end

#field_auth_isniObject

Returns the value of attribute field_auth_isni.



14
15
16
# File 'lib/marc2linkeddata/configuration.rb', line 14

def field_auth_isni
  @field_auth_isni
end

#field_auth_locObject

Returns the value of attribute field_auth_loc.



13
14
15
# File 'lib/marc2linkeddata/configuration.rb', line 13

def field_auth_loc
  @field_auth_loc
end

#field_auth_oclcObject

Returns the value of attribute field_auth_oclc.



15
16
17
# File 'lib/marc2linkeddata/configuration.rb', line 15

def field_auth_oclc
  @field_auth_oclc
end

#field_auth_viafObject

Returns the value of attribute field_auth_viaf.



16
17
18
# File 'lib/marc2linkeddata/configuration.rb', line 16

def field_auth_viaf
  @field_auth_viaf
end

#get_isniObject

Returns the value of attribute get_isni.



18
19
20
# File 'lib/marc2linkeddata/configuration.rb', line 18

def get_isni
  @get_isni
end

#get_locObject

Returns the value of attribute get_loc.



19
20
21
# File 'lib/marc2linkeddata/configuration.rb', line 19

def get_loc
  @get_loc
end

#get_oclcObject

Returns the value of attribute get_oclc.



20
21
22
# File 'lib/marc2linkeddata/configuration.rb', line 20

def get_oclc
  @get_oclc
end

#get_viafObject

Returns the value of attribute get_viaf.



21
22
23
# File 'lib/marc2linkeddata/configuration.rb', line 21

def get_viaf
  @get_viaf
end

#local_loc_passObject

Returns the value of attribute local_loc_pass.



25
26
27
# File 'lib/marc2linkeddata/configuration.rb', line 25

def local_loc_pass
  @local_loc_pass
end

#local_loc_urlObject

Returns the value of attribute local_loc_url.



26
27
28
# File 'lib/marc2linkeddata/configuration.rb', line 26

def local_loc_url
  @local_loc_url
end

#local_loc_userObject

Returns the value of attribute local_loc_user.



24
25
26
# File 'lib/marc2linkeddata/configuration.rb', line 24

def local_loc_user
  @local_loc_user
end

#log_fileObject

Returns the value of attribute log_file.



38
39
40
# File 'lib/marc2linkeddata/configuration.rb', line 38

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#oclc_auth2worksObject

Returns the value of attribute oclc_auth2works.



22
23
24
# File 'lib/marc2linkeddata/configuration.rb', line 22

def oclc_auth2works
  @oclc_auth2works
end

#prefixesObject

Returns the value of attribute prefixes.



28
29
30
# File 'lib/marc2linkeddata/configuration.rb', line 28

def prefixes
  @prefixes
end

#redisObject

Returns the value of attribute redis.



36
37
38
# File 'lib/marc2linkeddata/configuration.rb', line 36

def redis
  @redis
end

#redis4marcObject

Returns the value of attribute redis4marc.



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

def redis4marc
  @redis4marc
end

#redis_readObject

Returns the value of attribute redis_read.



34
35
36
# File 'lib/marc2linkeddata/configuration.rb', line 34

def redis_read
  @redis_read
end

#redis_writeObject

Returns the value of attribute redis_write.



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

def redis_write
  @redis_write
end

#test_recordsObject

Returns the value of attribute test_records.



7
8
9
# File 'lib/marc2linkeddata/configuration.rb', line 7

def test_records
  @test_records
end

#thread_limitObject

Returns the value of attribute thread_limit.



10
11
12
# File 'lib/marc2linkeddata/configuration.rb', line 10

def thread_limit
  @thread_limit
end

#threadsObject

Returns the value of attribute threads.



9
10
11
# File 'lib/marc2linkeddata/configuration.rb', line 9

def threads
  @threads
end

#use_foafObject

Returns the value of attribute use_foaf.



30
31
32
# File 'lib/marc2linkeddata/configuration.rb', line 30

def use_foaf
  @use_foaf
end

#use_schemaObject

Returns the value of attribute use_schema.



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

def use_schema
  @use_schema
end

Instance Method Details

#env_boolean(var) ⇒ Object



128
129
130
131
# File 'lib/marc2linkeddata/configuration.rb', line 128

def env_boolean(var)
  # check if an ENV variable is true, use false as default
  ENV[var].to_s.upcase == 'TRUE' rescue false
end

#redis_configObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/marc2linkeddata/configuration.rb', line 133

def redis_config
  if @redis4marc
    # https://github.com/redis/redis-rb
    # storing objects in redis:
    #redis.set "foo", [1, 2, 3].to_json
    #JSON.parse(redis.get("foo"))
    require 'hiredis'
    require 'redis'
    if @redis_url
      # redis url should be of the form "redis://{user}:{password}@{host}:{port}/{db}"
      @redis = Redis.new(:url => @redis_url)
      @redis.ping
    else
      # default is 'redis://127.0.0.1:6379/0'
      @redis = Redis.new
      @redis.ping
    end
  end
end